ADVERTISEMENT
ADVERTISEMENT

Golang math.Float32bits() Function with Examples

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

math.Float32bits()

The Float32bits() 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 Float32bits(f float32) uint32

Parameter(s):

  • f : The value of float32 type whose IEEE 754 binary representation is to be found.

Return Value:

The return type of Float32bits() function is a uint32, it returns the IEEE 754 binary representation of the given parameter.

Example 1:

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

package main

import (
	"fmt"
	"math"
)

func main() {
	fmt.Println(math.Float32bits(0))
	fmt.Println(math.Float32bits(5))
	fmt.Println(math.Float32bits(-5))
	fmt.Println(math.Float32bits(10.5))
	fmt.Println(math.Float32bits(-10.5))
	fmt.Println(math.Float32bits(0.01))
}

Output:

0
1084227584
3231711232
1093140480
3240624128
1008981770

Example 2:

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

package main

import (
	"fmt"
	"math"
)

func main() {
	var x float32
	var Float32bitsX uint32

	x = 0
	Float32bitsX = math.Float32bits(x)
	fmt.Println("Float32bits(", x, ") = ", Float32bitsX)

	x = 0.5
	Float32bitsX = math.Float32bits(x)
	fmt.Println("Float32bits(", x, ") = ", Float32bitsX)

	x = 6
	Float32bitsX = math.Float32bits(x)
	fmt.Println("Float32bits(", x, ") = ", Float32bitsX)

	x = -6
	Float32bitsX = math.Float32bits(x)
	fmt.Println("Float32bits(", x, ") = ", Float32bitsX)

	x = -0.15
	Float32bitsX = math.Float32bits(x)
	fmt.Println("Float32bits(", x, ") = ", Float32bitsX)
}

Output:

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

Golang math Package Constants and Functions »


ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.