Golang 如何找到给定值的双曲反正切
在本教程中,我们将学习如何在Golang编程语言中找到给定值的双曲反正切。Golang语言具有许多预定义函数的包,开发人员可以在不编写完整逻辑的情况下使用这些函数。
为了执行数学运算和逻辑,我们在Golang中有一个 math 包。我们将只使用这个包来找到给定值的双曲反正切。我们还将看到如何导入这个包,以及如何通过编写Golang代码来调用这个包中的函数。
双曲反正切
定义
双曲反正切函数类似于三角函数。双曲反正切等于三角函数的类似函数。双曲反正切的公式如下所示,双曲反正切的值在不同的角度上。
语法
atanh(x) = 1/2 * ln(1+x/1-x)
图表
不同角度下双曲反正切的值
- atanh(0) = 0
-
atanh(30) = NaN
-
atanh(45) = NaN
-
atanh(60) = NaN
-
atanh(90) = NaN
步骤
步骤1 - 声明一个变量来存储守护者的值和float32类型的答案。
步骤2 - 初始化一个值的变量。
步骤3 - 调用双曲反正切函数并传递值。
步骤4 - 打印结果。
示例
在这个示例中,我们将编写一个Golang程序,导入一个 math 包并调用双曲反正切函数。
package main
import (
// fmt package provides the function to print anything
"fmt"
// math package provides multiple functions for different
// mathematical operations
"math"
)
func main() {
// declaring the variables to store the value of \value and answer
var value, answer float64
fmt.Println("Program to find the Hyperbolic Arc Tangent of a given value in the Golang programming language using a math package.")
// initializing the value of the variable value
value = 0.5
// finding Hyperbolic Arc Tangent for the given value
answer = math.Atanh(value)
// printing the result
fmt.Println("The Hyperbolic Arc Tangent value with the value of", value, "is", answer)
}
输出
Program to find the Hyperbolic Arc Tangent of a given value in the Golang programming language using a math package.
The Hyperbolic Arc Tangent value with the value of 0.5 is 0.5493061443340548
步骤
步骤1 - 声明一个变量来存储 guardian 和 answer 的值,类型为 float32。
步骤2 - 初始化该变量的值。
步骤3 - 调用我们定义的 Hyperbolic Arc Tangent 函数,并将该值作为参数传递给函数。
步骤4 - 打印结果。
示例
在这个示例中,我们将编写一个 Golang 程序,其中我们将导入一个 math 包,并在一个独立的函数中调用 Hyperbolic Arc Tangent 函数,并将该函数称为主函数。
package main
import
(
"fmt"
"math"
)
type of float64
func HyperbolicArcTangent(angle float64) float64 {
// returning the Hyperbolic Arc Tangent of the angle
return math.Atanh(angle)
}
func main() {
// declaring the variables to store the value of value and answer
var value, answer float64
fmt.Println("Program to find the Hyperbolic Arc Tangent of a given value in the Golang programming language using a separate function in the same program.")
// initializing the value of the value
value = 0.5
// finding Hyperbolic Arc Tangent for the given value in a separate function
answer = HyperbolicArcTangent(value)
// printing the result
fmt.Println("The Hyperbolic Arc Tangent value with the value of", value, "is", answer)
}
输出
Program to find the Hyperbolic Arc Tangent of a given value in the Golang programming language using a separate function in the same program.
The Hyperbolic Arc Tangent value with the value of 0.5 is 0.5493061443340548
结论
使用数学包中的函数并将该值作为参数传递有两种方法可以找到双曲线反正切。第二种方法将在程序中提供抽象。要了解更多关于Golang的信息,可以探索这些教程。