Menu Close

Go – How to get base-2 exponential of number in go

Here, We will learn how to get base-2 exponential of number in go. We can get it by using Exp2() function in math package in go golang.

Function prototype:

func Exp2(no float64) float64

Return value:

Exp2() function in math package returns the
2**x, the base-2 exponential of number.

Example with code:

package main

import (
  "fmt"
  "math"
)

func main() {
  no := math.Exp2(3)
  fmt.Printf("%.2f\n", no)

  no = math.Exp2(-3)
  fmt.Printf("%.2f\n", no)

  no = math.Exp2(5)
  fmt.Printf("%.2f\n", no)

  no = math.Exp2(0)
  fmt.Printf("%.2f\n", no)  

}

Output:

8.00
0.12
32.00
1.00

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

https://www.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 *