Golang - Find IEEE 754 representation using math.Float64bits()

Here, we are going to learn how to find the IEEE 754 representation using math.Float64bits() function of given number in Golang (Go Language)? By Nidhi Last updated : March 28, 2023

Finding the IEEE 754 representation using math.Float64bits() function of given number

In this program, we will use math.Float64bits() function. The math.Float64bits() function is used to find the IEEE 754 representation of the given number.

Golang code to find the IEEE 754 representation using math.Float64bits() function of given number

The source code to demonstrate the Float64bits() function is given below. The given program is compiled and executed successfully.

// Golang program to demonstrate
// the Float64bits() function

package main

import (
	"fmt"
	"math"
)

func main() {
	out1 := math.Float64bits(0)
	out2 := math.Float64bits(1)
	out3 := math.Float64bits(2)
	out4 := math.Float64bits(2.5)

	fmt.Println(out1)
	fmt.Println(out2)
	fmt.Println(out3)
	fmt.Println(out4)
}

Output

0
4607182418800017408
4611686018427387904
4612811918334230528

Explanation

In the above program, we declare the package main. The main package is used to tell the Go language compiler that the package must be compiled and produced the executable file. Here, we imported the fmt package that includes the files of package fmt then we can use a function related to the fmt package.

In the main() function, we find the IEEE 754 representation of given numbers and print on the console screen.

Golang Basic Programs »





Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.