...
Source file
src/math/atan2.go
Documentation: math
1
2
3
4
5 package math
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 func Atan2(y, x float64) float64 {
30 if haveArchAtan2 {
31 return archAtan2(y, x)
32 }
33 return atan2(y, x)
34 }
35
36 func atan2(y, x float64) float64 {
37
38 switch {
39 case IsNaN(y) || IsNaN(x):
40 return NaN()
41 case y == 0:
42 if x >= 0 && !Signbit(x) {
43 return Copysign(0, y)
44 }
45 return Copysign(Pi, y)
46 case x == 0:
47 return Copysign(Pi/2, y)
48 case IsInf(x, 0):
49 if IsInf(x, 1) {
50 switch {
51 case IsInf(y, 0):
52 return Copysign(Pi/4, y)
53 default:
54 return Copysign(0, y)
55 }
56 }
57 switch {
58 case IsInf(y, 0):
59 return Copysign(3*Pi/4, y)
60 default:
61 return Copysign(Pi, y)
62 }
63 case IsInf(y, 0):
64 return Copysign(Pi/2, y)
65 }
66
67
68 q := Atan(y / x)
69 if x < 0 {
70 if q <= 0 {
71 return q + Pi
72 }
73 return q - Pi
74 }
75 return q
76 }
77
View as plain text