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 (
  "fmt"
  "math"
)

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)
  
}

Output:

0.5 1
0.5 2
0.75 0
-0.5 2

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

https://techieindoor.com/go-lang-tutorial/

References:

https://golang.org/doc/
https://golang.org/pkg/
Posted in golang, math

Leave a Reply

Your email address will not be published. Required fields are marked *