Go 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
  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn how to use Go (Golang), an open-source programming language supported by Google!
    • Beginner Friendly.
      6 hours

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

All contributors

Contribute to Docs

Learn Go on Codecademy

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn how to use Go (Golang), an open-source programming language supported by Google!
    • Beginner Friendly.
      6 hours