go Atan2()

Atan2()方法语法

func Atan2(y, x float64) float64

go源码对Atan2()方法的介绍:

Atan2 returns the arc tangent of y/x, using the signs of the two to determine the quadrant of the return value.

Special cases are (in order):

Atan2(y, NaN) = NaN
Atan2(NaN, x) = NaN
Atan2(+0, x>=0) = +0
Atan2(-0, x>=0) = -0
Atan2(+0, x<=-0) = +Pi
Atan2(-0, x<=-0) = -Pi
Atan2(y>0, 0) = +Pi/2
Atan2(y<0, 0) = -Pi/2
Atan2(+Inf, +Inf) = +Pi/4
Atan2(-Inf, +Inf) = -Pi/4
Atan2(+Inf, -Inf) = 3Pi/4
Atan2(-Inf, -Inf) = -3Pi/4
Atan2(y, +Inf) = 0
Atan2(y>0, -Inf) = +Pi
Atan2(y<0, -Inf) = -Pi
Atan2(+Inf, x) = +Pi/2
Atan2(-Inf, x) = -Pi/2

golang标准库math.Atan2()方法,接收两个float64类型参数x和y,计算方法类似Atan(y/x),但会根据x,y的正负号确定象限。除此之外,Special cases可参考上方的源码。


math.Atan2()方法实例代码

func main() {
	var atan2_value float64 = math.Atan2(2, 2)
	atan2_value = atan2_value * 180 / math.Pi
	fmt.Println(atan2_value)
}

运行go文件,得到输出:

45

全栈后端 / go语法 :













Copyright © 2022-2024 笨鸟工具 x1y1z1.com All Rights Reserved.