Expm1()

Anonymous contributor's avatar
Anonymous contributor
Published Oct 19, 2023
Contribute to Docs

The Expm1() function calculates e (the base of the natural logarithm) raised to the given argument minus one. The formula is written as follows:

Expm1(x)=ex1Expm1(x) = e^{x} - 1

Syntax

import math

value := math.Expm1(x)

Where value will contain the result of the calculation using the passed argument, x, returned as a float64. Special cases:

  • Expm1(+Inf) yields +Inf
  • Expm1(-Inf) yields -1
  • Expm1(NaN) yields NaN

Example

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

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

The output will be:

6.4

Codebyte Example

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

Code
Output
Loading...

All contributors

Contribute to Docs

Learn Go on Codecademy