math.Expm1 Function() in Golang With Examples
Last Updated :
01 Apr, 2020
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:
package main
import (
"fmt"
"math"
)
func main() {
res_1 := math.Expm1(4)
res_2 := math.Expm1(-1)
res_3 := math.Expm1(math.Inf(1))
res_4 := math.Expm1(math.NaN())
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:
package main
import (
"fmt"
"math"
)
func main() {
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
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...