Go language provides inbuilt support for basic constants and mathematical functions to perform operations on the numbers with the help of the math package. You are allowed to find base-e exponential of the specified number minus 1, i.e., e**a -1 with the help of Expm1() function provided by the math package. So, you need to add a math package in your program with the help of the import keyword to access Expm1() function.
Syntax:
func Expm1(a float64) float64
- If you pass +Inf in this function, then this function will return +Inf.
- If you pass -Inf in this function, then this function will return -1.
- In this function, very large values overflow to -1 or +Inf.
- If you pass NaN in this function, then this function will return NaN.
Example 1:
// Golang program to illustrate the Exmp1 function package main import ( "fmt"
"math"
) // Main function func main() { // Using Expm1() function
res_1 := math.Expm1(4)
res_2 := math.Expm1(-1)
res_3 := math.Expm1(math.Inf(1))
res_4 := math.Expm1(math.NaN())
// Displaying the result
fmt.Printf( "Result 1: %.1f" , res_1)
fmt.Printf( "\nResult 2: %.1f" , res_2)
fmt.Printf( "\nResult 3: %.1f" , res_3)
fmt.Printf( "\nResult 4: %.1f" , res_4)
} |
Output:
Result 1: 53.6 Result 2: -0.6 Result 3: +Inf Result 4: NaN
Example 2:
// Golang program to illustrate the Exmp1 function package main import ( "fmt"
"math"
) // Main function func main() { // Using Expm1() function
nvalue_1 := math.Expm1(7.3)
nvalue_2 := math.Expm1(-3)
res := nvalue_1 + nvalue_2
fmt.Printf( "%.1f + %.1f = %.1f" ,
nvalue_1, nvalue_2, res)
} |
Output:
1479.3 + -1.0 = 1478.3
Article Tags :