×

Golang Tutorial

Golang Reference

Golang Programs

Golang Practice

Golang Miscellaneous

Golang math.Float32frombits() Function with Examples

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

math.Float32frombits()

The Float32frombits() 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 Float32frombits(b uint32) float32

Parameters

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

Return Value

The return type of Float32frombits() function is a float32, 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.Float32frombits() Function

package main

import (
	"fmt"
	"math"
)

func main() {
	fmt.Println(math.Float32frombits(0))
	fmt.Println(math.Float32frombits(1084227584))
	fmt.Println(math.Float32frombits(3231711232))
	fmt.Println(math.Float32frombits(1093140480))
	fmt.Println(math.Float32frombits(3240624128))
	fmt.Println(math.Float32frombits(1008981770))
}

Output:

0
5
-5
10.5
-10.5
0.01

Example 2

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

package main

import (
	"fmt"
	"math"
)

func main() {
	var x uint32
	var Float32frombitsX float32

	x = 0
	Float32frombitsX = math.Float32frombits(x)
	fmt.Println("Float32frombits(", x, ") = ", Float32frombitsX)

	x = 1056964608
	Float32frombitsX = math.Float32frombits(x)
	fmt.Println("Float32frombits(", x, ") = ", Float32frombitsX)

	x = 1086324736
	Float32frombitsX = math.Float32frombits(x)
	fmt.Println("Float32frombits(", x, ") = ", Float32frombitsX)

	x = 3233808384
	Float32frombitsX = math.Float32frombits(x)
	fmt.Println("Float32frombits(", x, ") = ", Float32frombitsX)

	x = 3189348762
	Float32frombitsX = math.Float32frombits(x)
	fmt.Println("Float32frombits(", x, ") = ", Float32frombitsX)
}

Output:

Float32frombits( 0 ) =  0
Float32frombits( 1056964608 ) =  0.5
Float32frombits( 1086324736 ) =  6
Float32frombits( 3233808384 ) =  -6
Float32frombits( 3189348762 ) =  -0.15

Golang math Package Constants and Functions »




Comments and Discussions!

Load comments ↻





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