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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
|
/* atanl.c
*
* Inverse circular tangent, long double precision
* (arctangent)
*
*
*
* SYNOPSIS:
*
* long double x, y, atanl();
*
* y = atanl( x );
*
*
*
* DESCRIPTION:
*
* Returns radian angle between -pi/2 and +pi/2 whose tangent
* is x.
*
* Range reduction is from four intervals into the interval
* from zero to tan( pi/8 ). The approximant uses a rational
* function of degree 3/4 of the form x + x**3 P(x)/Q(x).
*
*
*
* ACCURACY:
*
* Relative error:
* arithmetic domain # trials peak rms
* IEEE -10, 10 150000 1.3e-19 3.0e-20
*
*/
/* atan2l()
*
* Quadrant correct inverse circular tangent,
* long double precision
*
*
*
* SYNOPSIS:
*
* long double x, y, z, atan2l();
*
* z = atan2l( y, x );
*
*
*
* DESCRIPTION:
*
* Returns radian angle whose tangent is y/x.
* Define compile time symbol ANSIC = 1 for ANSI standard,
* range -PI < z <= +PI, args (y,x); else ANSIC = 0 for range
* 0 to 2PI, args (x,y).
*
*
*
* ACCURACY:
*
* Relative error:
* arithmetic domain # trials peak rms
* IEEE -10, 10 60000 1.7e-19 3.2e-20
* See atan.c.
*
*/
/* atan.c */
/*
Cephes Math Library Release 2.7: May, 1998
Copyright 1984, 1990, 1998 by Stephen L. Moshier
*/
#include <math.h>
#ifdef UNK
static long double P[] = {
-8.6863818178092187535440E-1L,
-1.4683508633175792446076E1L,
-6.3976888655834347413154E1L,
-9.9988763777265819915721E1L,
-5.0894116899623603312185E1L,
};
static long double Q[] = {
/* 1.00000000000000000000E0L,*/
2.2981886733594175366172E1L,
1.4399096122250781605352E2L,
3.6144079386152023162701E2L,
3.9157570175111990631099E2L,
1.5268235069887081006606E2L,
};
/* tan( 3*pi/8 ) */
static long double T3P8 = 2.41421356237309504880169L;
/* tan( pi/8 ) */
static long double TP8 = 4.1421356237309504880169e-1L;
#endif
#ifdef IBMPC
static unsigned short P[] = {
0x8ece,0xce53,0x1266,0xde5f,0xbffe, XPD
0x07e6,0xa061,0xa6bf,0xeaef,0xc002, XPD
0x53ee,0xf291,0x557f,0xffe8,0xc004, XPD
0xf9d6,0xeda6,0x3f3e,0xc7fa,0xc005, XPD
0xb6c3,0x6abc,0x9361,0xcb93,0xc004, XPD
};
static unsigned short Q[] = {
/*0x0000,0x0000,0x0000,0x8000,0x3fff,*/
0x54d4,0x894e,0xe76e,0xb7da,0x4003, XPD
0x76b9,0x7a46,0xafa2,0x8ffd,0x4006, XPD
0xe3a9,0xe9c0,0x6bee,0xb4b8,0x4007, XPD
0xabc1,0x50a7,0xb098,0xc3c9,0x4007, XPD
0x891c,0x100d,0xae89,0x98ae,0x4006, XPD
};
/* tan( 3*pi/8 ) = 2.41421356237309504880 */
static unsigned short T3P8A[] = {0x3242,0xfcef,0x7999,0x9a82,0x4000, XPD};
#define T3P8 *(long double *)T3P8A
/* tan( pi/8 ) = 0.41421356237309504880 */
static unsigned short TP8A[] = {0x9211,0xe779,0xcccf,0xd413,0x3ffd, XPD};
#define TP8 *(long double *)TP8A
#endif
#ifdef MIEEE
static unsigned long P[] = {
0xbffe0000,0xde5f1266,0xce538ece,
0xc0020000,0xeaefa6bf,0xa06107e6,
0xc0040000,0xffe8557f,0xf29153ee,
0xc0050000,0xc7fa3f3e,0xeda6f9d6,
0xc0040000,0xcb939361,0x6abcb6c3,
};
static unsigned long Q[] = {
/*0x3fff0000,0x80000000,0x00000000,*/
0x40030000,0xb7dae76e,0x894e54d4,
0x40060000,0x8ffdafa2,0x7a4676b9,
0x40070000,0xb4b86bee,0xe9c0e3a9,
0x40070000,0xc3c9b098,0x50a7abc1,
0x40060000,0x98aeae89,0x100d891c,
};
/* tan( 3*pi/8 ) = 2.41421356237309504880 */
static long T3P8A[] = {0x40000000,0x9a827999,0xfcef3242};
#define T3P8 *(long double *)T3P8A
/* tan( pi/8 ) = 0.41421356237309504880 */
static long TP8A[] = {0x3ffd0000,0xd413cccf,0xe7799211};
#define TP8 *(long double *)TP8A
#endif
#ifdef ANSIPROT
extern long double polevll ( long double, void *, int );
extern long double p1evll ( long double, void *, int );
extern long double fabsl ( long double );
extern int signbitl ( long double );
extern int isnanl ( long double );
long double atanl ( long double );
#else
long double polevll(), p1evll(), fabsl(), signbitl(), isnanl();
long double atanl();
#endif
#ifdef INFINITIES
extern long double INFINITYL;
#endif
#ifdef NANS
extern long double NANL;
#endif
#ifdef MINUSZERO
extern long double NEGZEROL;
#endif
long double atanl(x)
long double x;
{
extern long double PIO2L, PIO4L;
long double y, z;
short sign;
#ifdef MINUSZERO
if( x == 0.0L )
return(x);
#endif
#ifdef INFINITIES
if( x == INFINITYL )
return( PIO2L );
if( x == -INFINITYL )
return( -PIO2L );
#endif
/* make argument positive and save the sign */
sign = 1;
if( x < 0.0L )
{
sign = -1;
x = -x;
}
/* range reduction */
if( x > T3P8 )
{
y = PIO2L;
x = -( 1.0L/x );
}
else if( x > TP8 )
{
y = PIO4L;
x = (x-1.0L)/(x+1.0L);
}
else
y = 0.0L;
/* rational form in x**2 */
z = x * x;
y = y + ( polevll( z, P, 4 ) / p1evll( z, Q, 5 ) ) * z * x + x;
if( sign < 0 )
y = -y;
return(y);
}
/* atan2 */
extern long double PIL, PIO2L, MAXNUML;
#if ANSIC
long double atan2l( y, x )
#else
long double atan2l( x, y )
#endif
long double x, y;
{
long double z, w;
short code;
code = 0;
if( x < 0.0L )
code = 2;
if( y < 0.0L )
code |= 1;
#ifdef NANS
if( isnanl(x) )
return(x);
if( isnanl(y) )
return(y);
#endif
#ifdef MINUSZERO
if( y == 0.0L )
{
if( signbitl(y) )
{
if( x > 0.0L )
z = y;
else if( x < 0.0L )
z = -PIL;
else
{
if( signbitl(x) )
z = -PIL;
else
z = y;
}
}
else /* y is +0 */
{
if( x == 0.0L )
{
if( signbitl(x) )
z = PIL;
else
z = 0.0L;
}
else if( x > 0.0L )
z = 0.0L;
else
z = PIL;
}
return z;
}
if( x == 0.0L )
{
if( y > 0.0L )
z = PIO2L;
else
z = -PIO2L;
return z;
}
#endif /* MINUSZERO */
#ifdef INFINITIES
if( x == INFINITYL )
{
if( y == INFINITYL )
z = 0.25L * PIL;
else if( y == -INFINITYL )
z = -0.25L * PIL;
else if( y < 0.0L )
z = NEGZEROL;
else
z = 0.0L;
return z;
}
if( x == -INFINITYL )
{
if( y == INFINITYL )
z = 0.75L * PIL;
else if( y == -INFINITYL )
z = -0.75L * PIL;
else if( y >= 0.0L )
z = PIL;
else
z = -PIL;
return z;
}
if( y == INFINITYL )
return( PIO2L );
if( y == -INFINITYL )
return( -PIO2L );
#endif /* INFINITIES */
#ifdef INFINITIES
if( x == 0.0L )
#else
if( fabsl(x) <= (fabsl(y) / MAXNUML) )
#endif
{
if( code & 1 )
{
#if ANSIC
return( -PIO2L );
#else
return( 3.0L*PIO2L );
#endif
}
if( y == 0.0L )
return( 0.0L );
return( PIO2L );
}
if( y == 0.0L )
{
if( code & 2 )
return( PIL );
return( 0.0L );
}
switch( code )
{
default:
#if ANSIC
case 0:
case 1: w = 0.0L; break;
case 2: w = PIL; break;
case 3: w = -PIL; break;
#else
case 0: w = 0.0L; break;
case 1: w = 2.0L * PIL; break;
case 2:
case 3: w = PIL; break;
#endif
}
z = w + atanl( y/x );
#ifdef MINUSZERO
if( z == 0.0L && y < 0.0L )
z = NEGZEROL;
#endif
return( z );
}
|