Menu Close

Go – Frexp() fucntion in math package in go

Here, We will learn about  Frexp() fucntion in math package in go.

Function prototype:

func Frexp(x float64) (fract float64, expo int)

Return value:

Frexp() function in math package breaks
x into a normalised fraction and an integral power of two.
It also returns fract and expo satisfying x == fract × 2**expo with the absolute value of fract in the interval [½, 1).

Example with code:

package main

import (

func main() {

  fract, expo := math.Frexp(1)
  fmt.Println(fract, expo)

  fract, expo = math.Frexp(2)
  fmt.Println(fract, expo)

  fract, expo = math.Frexp(0.75)
  fmt.Println(fract, expo)

  fract, expo = math.Frexp(-2)
  fmt.Println(fract, expo)


0.5 1
0.5 2
0.75 0
-0.5 2

To learn more about golang, Please refer given below link:

Posted in golang, math

Leave a Reply

Your email address will not be published.

Contact Us