Exp2()

manikanta528's avatar
Published Aug 6, 2023
Contribute to Docs

The Exp2() function returns the value of a base-2 exponential of a given number of type float64.

Syntax

import math

result := math.Exp2(x)

Where result will contain the value of a base-2 exponential of x, returned as a float64. Special cases:

  • The result of Exp2(+Inf) is +Inf
  • The result of Exp2(NaN) is NaN

Example

The example below demonstrates the basic use of Exp2():

package main
import (
"fmt"
"math"
)
func main() {
x := 4.0
result1 := math.Exp2(x)
fmt.Printf("%.1f\n", result1)
y := -4.0
result2 := math.Exp2(y)
fmt.Printf("%.1f\n", result2)
}

The output will be:

16.0
0.1

Codebyte Example

The following example is runnable and shows how the Exp2() function handles special cases:

Code
Output
Loading...

All contributors

Contribute to Docs

Learn Go on Codecademy