Go 语言为基本常量和数学函数提供内置支持,以在 math 包的帮助下对数字执行运算。您可以借助 math 包提供的 Expm1() 函数找到指定数字减去 1 的 base-e index ,即 e**a -1。因此,您需要借助 import 关键字在程序中添加一个数学包来访问 Expm1() 函数。
用法:
func Expm1(a float64) float64
- 如果在此函数中传递 +Inf,则此函数将返回 +Inf。
- 如果在此函数中传递 -Inf,则此函数将返回 -1。
- 在这个函数中,非常大的值溢出到 -1 或 +Inf。
- 如果在此函数中传递 NaN,则此函数将返回 NaN。
范例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)
}
输出:
Result 1:53.6 Result 2:-0.6 Result 3:+Inf Result 4:NaN
范例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)
}
输出:
1479.3 + -1.0 = 1478.3
相关用法
- Golang math.Lgamma()用法及代码示例
- Golang math.Float64bits()用法及代码示例
- Golang atomic.AddInt64()用法及代码示例
- Golang atomic.StoreInt64()用法及代码示例
- Golang reflect.FieldByIndex()用法及代码示例
- Golang string.Contains用法及代码示例
- Golang bits.Sub()用法及代码示例
- Golang io.PipeWriter.CloseWithError()用法及代码示例
- Golang time.Round()用法及代码示例
- Golang reflect.AppendSlice()用法及代码示例
- Golang reflect.ChanOf()用法及代码示例
- Golang flag.Bool()用法及代码示例
- Golang time.Sleep()用法及代码示例
- Golang time.Time.Year()用法及代码示例
- Golang reflect.Indirect()用法及代码示例
- Golang reflect.CanAddr()用法及代码示例
- Golang reflect.CanInterface()用法及代码示例
- Golang reflect.CanSet()用法及代码示例
- Golang reflect.Cap()用法及代码示例
- Golang strings.ContainsRune()用法及代码示例
- Golang atomic.LoadInt64()用法及代码示例
- Golang reflect.Index()用法及代码示例
- Golang filepath.Abs()用法及代码示例
- Golang filepath.Base()用法及代码示例
注:本文由纯净天空筛选整理自Kirti_Mangal大神的英文原创作品 math.Expm1 Function() in Golang With Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。