Exp()

Anonymous contributor's avatar
Anonymous contributor
Anonymous contributor's avatar
Anonymous contributor
Published Aug 7, 2023
Contribute to Docs

The Exp() function returns the value of e^x (e to the power of x), where x is the parameter.

Syntax

import "math"

value := math.Exp(number)

Where value is the value of e raised to the power of number, and where number is a variable of type float64.

Special cases:

  • Exp(+Inf) returns +Inf
  • Exp(NaN) returns NaN as well (Not a Number)

Example

The following code calculates the value of e to the power of 3, and prints the resulting value to the console.

package main
import (
"fmt"
"math"
)
func main() {
result := math.Exp(math.Inf(1))
fmt.Printf("%.1f\n", result)
}

The output will be:

+Inf

Codebyte Example

The following code is runnable and demonstrates the use of the Exp() function.

us
Visit us
code
Hide code
Code
Output
Hide output
Hide output
Loading...

All contributors

Looking to contribute?

Learn Go on Codecademy