Home »
Golang »
Golang Reference
Golang math.Float64bits() Function with Examples
Golang | math.Float64bits() Function: Here, we are going to learn about the Float64bits() function of the math package with its usages, syntax, and examples.
Submitted by IncludeHelp, on August 31, 2021
math.Float64bits()
The Float64bits() function is an inbuilt function of the math package which is used to get the IEEE 754 binary representation of f, with the sign bit of f and the result in the same bit position. Where f is the given parameter.
It accepts a parameter (f) and returns the IEEE 754 binary representation of f.
Syntax
func Float64bits(f float64) uint64
Parameters
- f : The value of float64 type whose IEEE 754 binary representation is to be found.
Return Value
The return type of Float64bits() function is a uint64, it returns the IEEE 754 binary representation of the given parameter.
Example 1
// Golang program to demonstrate the
// example of math.Float64bits() Function
package main
import (
"fmt"
"math"
)
func main() {
fmt.Println(math.Float64bits(0))
fmt.Println(math.Float64bits(5))
fmt.Println(math.Float64bits(-5))
fmt.Println(math.Float64bits(10.5))
fmt.Println(math.Float64bits(-10.5))
fmt.Println(math.Float64bits(0.01))
}
Output:
0
4617315517961601024
13840687554816376832
4622100592565682176
13845472629420457984
4576918229304087675
Example 2
// Golang program to demonstrate the
// example of math.Float64bits() Function
package main
import (
"fmt"
"math"
)
func main() {
var x float64
var Float64bitsX uint64
x = 0
Float64bitsX = math.Float64bits(x)
fmt.Println("Float64bits(", x, ") = ", Float64bitsX)
x = 0.5
Float64bitsX = math.Float64bits(x)
fmt.Println("Float64bits(", x, ") = ", Float64bitsX)
x = 6
Float64bitsX = math.Float64bits(x)
fmt.Println("Float64bits(", x, ") = ", Float64bitsX)
x = -6
Float64bitsX = math.Float64bits(x)
fmt.Println("Float64bits(", x, ") = ", Float64bitsX)
x = -0.15
Float64bitsX = math.Float64bits(x)
fmt.Println("Float64bits(", x, ") = ", Float64bitsX)
}
Output:
Float64bits( 0 ) = 0
Float64bits( 0.5 ) = 4602678819172646912
Float64bits( 6 ) = 4618441417868443648
Float64bits( -6 ) = 13841813454723219456
Float64bits( -0.15 ) = 13817944376698155827
Golang math Package Constants and Functions »