Open In App

math.Float32frombits() Function in Golang With Examples

Last Updated : 19 Apr, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

Go language provides inbuilt support for basic constants and mathematical functions to perform operations on the numbers with the help of the math package. This package provides Float32frombits() function which returns the floating-point number corresponding to the IEEE 754 binary representation a, with the sign bit of a and the result in the same bit position. So, you need to add a math package in your program with the help of the import keyword to access the Float32frombits() function.

Syntax:

func Float32frombits(a uint32) float32

Example 1:




// Golang program to illustrate how to find
// the floating-point number corresponding
// to the IEEE 754 binary representation
package main
  
import (
    "fmt"
    "math"
)
  
// Main function
func main() {
  
    // Finding floating-point number corresponding
    // to the IEEE 754 binary representation 
    // of the given numbers
    // Using Float32frombits() function
    res_1 := math.Float32frombits(2)
    res_2 := math.Float32frombits(1)
    res_3 := math.Float32frombits(0)
    res_4 := math.Float32frombits(223)
  
    // Displaying the result
    fmt.Println("Result 1: ", res_1)
    fmt.Println("Result 2: ", res_2)
    fmt.Println("Result 3: ", res_3)
    fmt.Println("Result 4: ", res_4)
  
}


Output:

Result 1:  3e-45
Result 2:  1e-45
Result 3:  0
Result 4:  3.12e-43

Example 2:




// Golang program to illustrate how to find
// the floating-point number corresponding
// to the IEEE 754 binary representation
package main
  
import (
    "fmt"
    "math"
)
  
// Main function
func main() {
  
    // Finding floating-point number corresponding
    // to the IEEE 754 binary representation
    // of the given numbers
    // Using Float32frombits() function
    nvalue_1 := math.Float32frombits(3)
    nvalue_2 := math.Float32frombits(50)
  
    // Sum of the given values
    res := nvalue_1 + nvalue_2
    fmt.Println("Result 1: ", nvalue_1)
    fmt.Println("Result 2: ", nvalue_2)
    fmt.Println("Sum of Result 1 and Result 2: ", res)
  
}


Output:

Result 1:  4e-45
Result 2:  7e-44
Sum of Result 1 and Result 2:  7.4e-44


Similar Reads

math.Lgamma() Function in Golang with Examples
Go language provides inbuilt support for basic constants and mathematical functions to perform operations on the numbers with the help of the math package. This package provides Lgamma() function which is used to find the natural logarithm and sign (either -1 or +1) of Gamma(a). So, you need to add a math package in your program with the help of th
2 min read
math.Float64bits() Function in Golang With Examples
Go language provides inbuilt support for basic constants and mathematical functions to perform operations on the numbers with the help of the math package. This package provides Float64bits() function which returns the IEEE 754 binary representation of a with the sign bit of a and the result in the same bit position. So, you need to add a math pack
2 min read
math.Dim() Function in Golang With Examples
Go language provides inbuilt support for basic constants and mathematical functions to perform operations on the numbers with the help of the math package. Dim() function provided by the math package return the maximum of a-b or 0. So, to access this function you need to add a math package in your program with the help of the import keyword. Syntax
2 min read
math.Expm1 Function() in Golang With Examples
Go language provides inbuilt support for basic constants and mathematical functions to perform operations on the numbers with the help of the math package. You are allowed to find base-e exponential of the specified number minus 1, i.e., e**a -1 with the help of Expm1() function provided by the math package. So, you need to add a math package in yo
2 min read
math.Hypot Function in Golang With Examples
Go language provides inbuilt support for basic constants and mathematical functions to perform operations on the numbers with the help of the math package. You can find the hypotenuse, i.e., Sqrt(a*a + b*b) with the help of Hypot() function provided by the math package. So, you need to add a math package in your program with the help of the import
2 min read
math.Round() Function in Golang With Examples
Go language provides inbuilt support for basic constants and mathematical functions to perform operations on the numbers with the help of the math package. You can round off the given number to the nearest integer(rounding half away from zero) with the help of Round() function provided by the math package. So, you need to add a math package in your
2 min read
math.Remainder() Function in Golang With Examples
Go language provides inbuilt support for basic constants and mathematical functions to perform operations on the numbers with the help of the math package. You can find the remainder or the IEEE 754 floating-point remainder of a/b with the help of Remainder() function provided by the math package. So, you need to add a math package in your program
2 min read
math.RoundToEven() Function in Golang With Examples
Go language provides inbuilt support for basic constants and mathematical functions to perform operations on the numbers with the help of the math package. You can round off the given number to the nearest even integer with the help of RoundToEven() function provided by the math package. So, you need to add a math package in your program with the h
2 min read
math.Signbit() Function in Golang With Examples
Go language provides inbuilt support for basic constants and mathematical functions to perform operations on the numbers with the help of the math package. You check whether the sign of the specified number is negative or negative zero with the help of Signbit() function provided by the math package. If the sign of the given number is negative, the
2 min read
math.NaN() Function in Golang With Examples
Go language provides inbuilt support for basic constants and mathematical functions to perform operations on the numbers with the help of the math package. You get an IEEE 754 "not-a-number" value with the help of NaN() function provided by the math package. So, you need to add a math package in your program with the help of the import keyword to a
1 min read
Article Tags :