The Wayback Machine - https://web.archive.org/web/20240118181705/https://www.geeksforgeeks.org/math-float64bits-function-in-golang-with-examples/
Open In App
Related Articles

math.Float64bits() Function in Golang With Examples

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
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 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 package in your program with the help of the import keyword to access the Float64bits() function. 

Syntax: 

func Float64bits(a float64) uint64

Example 1: 

Go




// Golang program to illustrate how to
// find the IEEE 754 binary representation
package main
 
import (
    "fmt"
    "math"
)
 
// Main function
func main() {
 
    // Finding IEEE 754 binary
    // representation of the
    // given numbers
    // Using Float64bits() function
    res_1 := math.Float64bits(2)
    res_2 := math.Float64bits(1)
    res_3 := math.Float64bits(0)
    res_4 := math.Float64bits(2.3)
 
    // 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: 4611686018427387904
Result 2: 4607182418800017408
Result 3: 0
Result 4: 4612361558371493478

Example 2: 

Go




// Golang program to illustrate how to
// find the IEEE 754 binary representation
package main
 
import (
    "fmt"
    "math"
)
 
// Main function
func main() {
 
    // Finding IEEE 754 binary
    // representation of the
    // given numbers
    // Using Float64bits() function
    nvalue_1 := math.Float64bits(3)
    nvalue_2 := math.Float64bits(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: 4613937818241073152
Result 2: 4632233691727265792
Sum of Result 1 and Result 2: 9246171509968338944

Learn to code easily with our course Coding for Everyone. This course is accessible and designed for everyone, even if you're new to coding. Start today and join millions on a journey to improve your skills!

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated : 02 Nov, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads