...
Source file src/pkg/math/atan2.go
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
31 func atan2(y, x float64) float64 {
32
33 switch {
34 case IsNaN(y) || IsNaN(x):
35 return NaN()
36 case y == 0:
37 if x >= 0 && !Signbit(x) {
38 return Copysign(0, y)
39 }
40 return Copysign(Pi, y)
41 case x == 0:
42 return Copysign(Pi/2, y)
43 case IsInf(x, 0):
44 if IsInf(x, 1) {
45 switch {
46 case IsInf(y, 0):
47 return Copysign(Pi/4, y)
48 default:
49 return Copysign(0, y)
50 }
51 }
52 switch {
53 case IsInf(y, 0):
54 return Copysign(3*Pi/4, y)
55 default:
56 return Copysign(Pi, y)
57 }
58 case IsInf(y, 0):
59 return Copysign(Pi/2, y)
60 }
61
62
63 q := Atan(y / x)
64 if x < 0 {
65 if q <= 0 {
66 return q + Pi
67 }
68 return q - Pi
69 }
70 return q
71 }
72
View as plain text