Golang 找出指定数字的反双曲正切
Go语言提供了内置的math包,它支持基本常量和数学函数,可以对数字执行操作。使用 Atanh()函数 提供的反双曲正切功能,可以找出指定数字的反双曲正切。因此,您需要使用import关键字将math包添加到程序中,以访问Atanh()函数。
语法:
func Atanh(y float64) float64
- 如果您在此函数中传递1,则此函数将返回+Inf。
- 如果您在此函数中传递-1,则此函数将返回-Inf。
- 如果您在此函数中传递-0或+0,则此函数将返回-0或+0。
- 如果您在此函数中传递NaN,则此函数将返回NaN。
- 如果y < -1或y > 1,则此函数将返回NaN。
示例1:
// Golang程序演示如何找出给定数字的反双曲正切
package main
import (
"fmt"
"math"
)
// 主函数
func main() {
// 查找反双曲正切
// 给定值
// 使用Atanh()函数
res_1 := math.Atanh(math.Pi / 4)
res_2 := math.Atanh(math.Inf(-3))
res_3 := math.Atanh(0)
res_4 := math.Atanh(math.NaN())
res_5 := math.Atanh(-1)
// 显示结果
fmt.Printf("结果1:%.1f", res_1)
fmt.Printf("\n结果2:%.1f", res_2)
fmt.Printf("\n结果3:%.1f", res_3)
fmt.Printf("\n结果4:%.1f", res_4)
fmt.Printf("\n结果5:%.1f", res_5)
}
输出:
结果1:1.1
结果2:NaN
结果3:0.0
结果4:NaN
结果5:-Inf
示例2:
// Golang程序演示如何找出给定数字的反双曲正切
package main
import (
"fmt"
"math"
)
// 主函数
func main() {
// 查找反双曲正切
// 给定数字
nvalue_1 := math.Atanh(math.Pi / 3)
nvalue_2 := math.Atanh(math.Pi / 6)
// 给定值的总和
res := nvalue_1 + nvalue_2
// 显示结果
fmt.Printf("%.1f + %.1f = %.1f",
nvalue_1, nvalue_2, res)
}
输出:
NaN + 0.6 = NaN