Open In App

math.Float64frombits() 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 Float64frombits() 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 Float64frombits() function.

Syntax:

func Float64frombits(a uint64) float64

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 Float64frombits() function
    res_1 := math.Float64frombits(2)
    res_2 := math.Float64frombits(1)
    res_3 := math.Float64frombits(0)
    res_4 := math.Float64frombits(23)
  
    // 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:  1e-323
Result 2:  5e-324
Result 3:  0
Result 4:  1.14e-322

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 Float64frombits() function
    nvalue_1 := math.Float64frombits(3)
    nvalue_2 := math.Float64frombits(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:  1.5e-323
Result 2:  2.47e-322
Sum of Result 1 and Result 2:  2.6e-322


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads