Menu Close

Go – How to get floating-point number corresponding to the IEEE 754 binary representation with Float32frombits in go

Here, We will learn how to get floating-point number corresponding to the IEEE 754 binary representation with Float32frombits in go. We can get it by using Float32frombits() function in math package in go golang.

Function prototype:

func Float32frombits(b uint32) float32

Return value:

Float32frombits() function in math package returns
the floating-point number corresponding to the
IEEE 754 binary representation of number.
It gives result in the same bit position

Float32frombits(Float32bits(x)) == number

Example with code:

package main

import (
  "fmt"
  "math"
)

func main() {

  no := math.Float32frombits(2)
  fmt.Println(no)

  no = math.Float32frombits(1)
  fmt.Println(no)

  no = math.Float32frombits(3)
  fmt.Println(no)

  no = math.Float32frombits(5)
  fmt.Println(no)
  
}

Output:

3e-45
1e-45
4e-45
7e-45

To learn more about golang, Please refer given below link:

https://www.techieindoor.com/go-lang-tutorial/

References:

https://golang.org/doc/
https://golang.org/pkg/
Posted in golang, math

Leave a Reply

Your email address will not be published.

Contact Us