123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- package math
- func libc_atan2(float64, float64) float64
- func Atan2(y, x float64) float64 {
- return libc_atan2(y, x)
- }
- func atan2(y, x float64) float64 {
-
- switch {
- case IsNaN(y) || IsNaN(x):
- return NaN()
- case y == 0:
- if x >= 0 && !Signbit(x) {
- return Copysign(0, y)
- }
- return Copysign(Pi, y)
- case x == 0:
- return Copysign(Pi/2, y)
- case IsInf(x, 0):
- if IsInf(x, 1) {
- switch {
- case IsInf(y, 0):
- return Copysign(Pi/4, y)
- default:
- return Copysign(0, y)
- }
- }
- switch {
- case IsInf(y, 0):
- return Copysign(3*Pi/4, y)
- default:
- return Copysign(Pi, y)
- }
- case IsInf(y, 0):
- return Copysign(Pi/2, y)
- }
-
- q := Atan(y / x)
- if x < 0 {
- if q <= 0 {
- return q + Pi
- }
- return q - Pi
- }
- return q
- }
|