blob: 2902bd8c0411a3e254a5ac80b9fa368cb454b8d2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
#include "fdlibm.h"
#ifdef __STDC__
static const double
#else
static double
#endif
tiny = 1.0e-300,
zero = 0.0, pi_o_4 = 7.8539816339744827900E-01,
pi_o_2 = 1.5707963267948965580E+00,
pi = 3.1415926535897931160E+00,
pi_lo = 1.2246467991473531772E-16;
#ifdef __STDC__
double __ieee754_atan2(double y, double x)
#else
double __ieee754_atan2(y, x)
double y, x;
#endif
{
double z;
_INT32 k, m, hx, hy, ix, iy;
_UINT32 lx, ly;
hx = __HI(x);
ix = hx & 0x7fffffff;
lx = __LO(x);
hy = __HI(y);
iy = hy & 0x7fffffff;
ly = __LO(y);
if (((ix | ((lx | -lx) >> 31)) > 0x7ff00000) ||
((iy | ((ly | -ly) >> 31)) > 0x7ff00000))
return x + y;
if ((hx - 0x3ff00000 | lx) == 0)
return atan(y);
m = ((hy >> 31) & 1) | ((hx >> 30) & 2);
if ((iy | ly) == 0) {
switch (m) {
case 0:
case 1:
return y;
case 2:
return pi + tiny;
case 3:
return -pi - tiny;
}
}
if ((ix | lx) == 0)
return (hy < 0) ? -pi_o_2 - tiny : pi_o_2 + tiny;
if (ix == 0x7ff00000) {
if (iy == 0x7ff00000) {
switch (m) {
case 0:
return pi_o_4 + tiny;
case 1:
return -pi_o_4 - tiny;
case 2:
return 3.0 * pi_o_4 + tiny;
case 3:
return -3.0 * pi_o_4 - tiny;
}
} else {
switch (m) {
case 0:
return zero;
case 1:
return -zero;
case 2:
return pi + tiny;
case 3:
return -pi - tiny;
}
}
}
if (iy == 0x7ff00000)
return (hy < 0) ? -pi_o_2 - tiny : pi_o_2 + tiny;
k = (iy - ix) >> 20;
if (k > 60)
z = pi_o_2 + 0.5 * pi_lo;
else if (hx < 0 && k < -60)
z = 0.0;
else
z = atan(fabs(y / x));
switch (m) {
case 0:
return z;
case 1:
__HI(z) ^= 0x80000000;
return z;
case 2:
return pi - (z - pi_lo);
default:
return (z - pi_lo) - pi;
}
}
|