×

Golang Tutorial

Golang Reference

Golang Programs

Golang Practice

Golang Miscellaneous

Golang math.Float64frombits() Function with Examples

Golang | math.Float64frombits() Function: Here, we are going to learn about the Float64frombits() function of the math package with its usages, syntax, and examples.
Submitted by IncludeHelp, on August 31, 2021

math.Float64frombits()

The Float64frombits() function is an inbuilt function of the math package which is used to get the floating-point number corresponding to the IEEE 754 binary representation b, with the sign bit of b and the result in the same bit position. Where b is the given parameter.

It accepts a parameter (b) and returns the floating-point number corresponding to the IEEE 754 binary representation b.

Syntax

func Float64frombits(b uint64) float64

Parameters

  • b : The value of uint64 type whose floating-point number corresponding to the IEEE 754 binary representation is to be found.

Return Value

The return type of Float64frombits() function is a float64, it returns the floating-point number corresponding to the IEEE 754 binary representation of the given parameter.

Example 1

// Golang program to demonstrate the
// example of math.Float64frombits() Function

package main

import (
	"fmt"
	"math"
)

func main() {
	fmt.Println(math.Float64frombits(0))
	fmt.Println(math.Float64frombits(4617315517961601024))
	fmt.Println(math.Float64frombits(13840687554816376832))
	fmt.Println(math.Float64frombits(4622100592565682176))
	fmt.Println(math.Float64frombits(13845472629420457984))
	fmt.Println(math.Float64frombits(4576918229304087675))
}

Output:

0
5
-5
10.5
-10.5
0.01

Example 2

// Golang program to demonstrate the
// example of math.Float64frombits() Function

package main

import (
	"fmt"
	"math"
)

func main() {
	var x uint64
	var Float64frombitsX float64

	x = 0
	Float64frombitsX = math.Float64frombits(x)
	fmt.Println("Float64frombits(", x, ") = ", Float64frombitsX)

	x = 4602678819172646912
	Float64frombitsX = math.Float64frombits(x)
	fmt.Println("Float64frombits(", x, ") = ", Float64frombitsX)

	x = 4618441417868443648
	Float64frombitsX = math.Float64frombits(x)
	fmt.Println("Float64frombits(", x, ") = ", Float64frombitsX)

	x = 13841813454723219456
	Float64frombitsX = math.Float64frombits(x)
	fmt.Println("Float64frombits(", x, ") = ", Float64frombitsX)

	x = 13817944376698155827
	Float64frombitsX = math.Float64frombits(x)
	fmt.Println("Float64frombits(", x, ") = ", Float64frombitsX)
}

Output:

Float64frombits( 0 ) =  0
Float64frombits( 4602678819172646912 ) =  0.5
Float64frombits( 4618441417868443648 ) =  6
Float64frombits( 13841813454723219456 ) =  -6
Float64frombits( 13817944376698155827 ) =  -0.15

Golang math Package Constants and Functions »




Comments and Discussions!

Load comments ↻





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