Menu Close

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

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

Function prototype:

func Float64frombits(no uint64) float64

Return value:

Float64frombits() 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

Float64frombits(Float64bits(x)) == number

Example with code:

package main

import (
  "fmt"
  "math"
)

func main() {

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

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

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

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

Output:

1e-323
5e-324
1.5e-323
2.5e-323

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. Required fields are marked *