3 * Inverse circular tangent, long double precision
10 * long double x, y, atanl();
18 * Returns radian angle between -pi/2 and +pi/2 whose tangent
21 * Range reduction is from four intervals into the interval
22 * from zero to tan( pi/8 ). The approximant uses a rational
23 * function of degree 3/4 of the form x + x**3 P(x)/Q(x).
30 * arithmetic domain # trials peak rms
31 * IEEE -10, 10 150000 1.3e-19 3.0e-20
36 * Quadrant correct inverse circular tangent,
37 * long double precision
43 * long double x, y, z, atan2l();
51 * Returns radian angle whose tangent is y/x.
52 * Define compile time symbol ANSIC = 1 for ANSI standard,
53 * range -PI < z <= +PI, args (y,x); else ANSIC = 0 for range
54 * 0 to 2PI, args (x,y).
61 * arithmetic domain # trials peak rms
62 * IEEE -10, 10 60000 1.7e-19 3.2e-20
71 Cephes Math Library Release 2.7: May, 1998
72 Copyright 1984, 1990, 1998 by Stephen L. Moshier
79 static long double P[] = {
80 -8.6863818178092187535440E-1L,
81 -1.4683508633175792446076E1L,
82 -6.3976888655834347413154E1L,
83 -9.9988763777265819915721E1L,
84 -5.0894116899623603312185E1L,
86 static long double Q[] = {
87 /* 1.00000000000000000000E0L,*/
88 2.2981886733594175366172E1L,
89 1.4399096122250781605352E2L,
90 3.6144079386152023162701E2L,
91 3.9157570175111990631099E2L,
92 1.5268235069887081006606E2L,
96 static long double T3P8 = 2.41421356237309504880169L;
99 static long double TP8 = 4.1421356237309504880169e-1L;
104 static unsigned short P[] = {
105 0x8ece,0xce53,0x1266,0xde5f,0xbffe, XPD
106 0x07e6,0xa061,0xa6bf,0xeaef,0xc002, XPD
107 0x53ee,0xf291,0x557f,0xffe8,0xc004, XPD
108 0xf9d6,0xeda6,0x3f3e,0xc7fa,0xc005, XPD
109 0xb6c3,0x6abc,0x9361,0xcb93,0xc004, XPD
111 static unsigned short Q[] = {
112 /*0x0000,0x0000,0x0000,0x8000,0x3fff,*/
113 0x54d4,0x894e,0xe76e,0xb7da,0x4003, XPD
114 0x76b9,0x7a46,0xafa2,0x8ffd,0x4006, XPD
115 0xe3a9,0xe9c0,0x6bee,0xb4b8,0x4007, XPD
116 0xabc1,0x50a7,0xb098,0xc3c9,0x4007, XPD
117 0x891c,0x100d,0xae89,0x98ae,0x4006, XPD
120 /* tan( 3*pi/8 ) = 2.41421356237309504880 */
121 static unsigned short T3P8A[] = {0x3242,0xfcef,0x7999,0x9a82,0x4000, XPD};
122 #define T3P8 *(long double *)T3P8A
124 /* tan( pi/8 ) = 0.41421356237309504880 */
125 static unsigned short TP8A[] = {0x9211,0xe779,0xcccf,0xd413,0x3ffd, XPD};
126 #define TP8 *(long double *)TP8A
130 static unsigned long P[] = {
131 0xbffe0000,0xde5f1266,0xce538ece,
132 0xc0020000,0xeaefa6bf,0xa06107e6,
133 0xc0040000,0xffe8557f,0xf29153ee,
134 0xc0050000,0xc7fa3f3e,0xeda6f9d6,
135 0xc0040000,0xcb939361,0x6abcb6c3,
137 static unsigned long Q[] = {
138 /*0x3fff0000,0x80000000,0x00000000,*/
139 0x40030000,0xb7dae76e,0x894e54d4,
140 0x40060000,0x8ffdafa2,0x7a4676b9,
141 0x40070000,0xb4b86bee,0xe9c0e3a9,
142 0x40070000,0xc3c9b098,0x50a7abc1,
143 0x40060000,0x98aeae89,0x100d891c,
146 /* tan( 3*pi/8 ) = 2.41421356237309504880 */
147 static long T3P8A[] = {0x40000000,0x9a827999,0xfcef3242};
148 #define T3P8 *(long double *)T3P8A
150 /* tan( pi/8 ) = 0.41421356237309504880 */
151 static long TP8A[] = {0x3ffd0000,0xd413cccf,0xe7799211};
152 #define TP8 *(long double *)TP8A
156 extern long double polevll ( long double, void *, int );
157 extern long double p1evll ( long double, void *, int );
158 extern long double fabsl ( long double );
159 extern int signbitl ( long double );
160 extern int isnanl ( long double );
161 long double atanl ( long double );
163 long double polevll(), p1evll(), fabsl(), signbitl(), isnanl();
167 extern long double INFINITYL;
170 extern long double NANL;
173 extern long double NEGZEROL;
179 extern long double PIO2L, PIO4L;
190 if( x == -INFINITYL )
193 /* make argument positive and save the sign */
201 /* range reduction */
211 x = (x-1.0L)/(x+1.0L);
216 /* rational form in x**2 */
218 y = y + ( polevll( z, P, 4 ) / p1evll( z, Q, 5 ) ) * z * x + x;
229 extern long double PIL, PIO2L, MAXNUML;
232 long double atan2l( y, x )
234 long double atan2l( x, y )
295 #endif /* MINUSZERO */
301 else if( y == -INFINITYL )
309 if( x == -INFINITYL )
313 else if( y == -INFINITYL )
323 if( y == -INFINITYL )
325 #endif /* INFINITIES */
330 if( fabsl(x) <= (fabsl(y) / MAXNUML) )
338 return( 3.0L*PIO2L );
359 case 1: w = 0.0L; break;
360 case 2: w = PIL; break;
361 case 3: w = -PIL; break;
363 case 0: w = 0.0L; break;
364 case 1: w = 2.0L * PIL; break;
366 case 3: w = PIL; break;
370 z = w + atanl( y/x );
372 if( z == 0.0L && y < 0.0L )