00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 static char *rcs_id = "$Source: /proj/osprey/CVS/open64/osprey1.0/libm/mips/atan.c,v $ $Revision: 1.1.1.1 $";
00061
00062 #ifdef _CALL_MATHERR
00063 #include <stdio.h>
00064 #include <math.h>
00065 #include <errno.h>
00066 #endif
00067
00068 #include "libm.h"
00069
00070 #if defined(mips) && !defined(__GNUC__)
00071 extern double atan(double);
00072
00073 #pragma weak atan = __atan
00074 #endif
00075
00076 #if defined(BUILD_OS_DARWIN)
00077 extern double __atan(double);
00078 #pragma weak atan
00079 double atan( double x ) {
00080 return __atan( x );
00081 }
00082 #elif defined(__GNUC__)
00083 extern double __atan(double);
00084
00085 double atan() __attribute__ ((weak, alias ("__atan")));
00086
00087 #endif
00088
00089 static const du Qnan =
00090 {D(QNANHI, QNANLO)};
00091
00092 static const du x0 = {D(0x4005a045, 0x6bb5777e)};
00093 static const du atanx0 = {D(0x3ff376b7, 0x14052e5f)};
00094
00095 static const du x1 = {D(0x401569f1, 0xdc77c11f)};
00096 static const du atanx1 = {D(0x3ff62d96, 0x1fdc0458)};
00097
00098 static const du x2 = {D(0x40255a9e, 0xc859d828)};
00099 static const du atanx2 = {D(0x3ff7a378, 0x109217cc)};
00100
00101
00102
00103 static const du P1[] =
00104 {
00105 {D(0xbfd55555, 0x5555554a)},
00106 {D(0xbfe19716, 0xdbd2dae9)},
00107 {D(0xbfd11086, 0xb3197c81)},
00108 {D(0xbfa269e6, 0x2efde2b2)},
00109 {D(0xbf24f1d1, 0x3d7b6dc8)},
00110 };
00111
00112 static const du Q1[] =
00113 {
00114 {D(0x3ff00000, 0x00000000)},
00115 {D(0x4001fe1d, 0xf1aaee0b)},
00116 {D(0x3ffb884e, 0x717967d7)},
00117 {D(0x3fe0504a, 0x395eff9f)},
00118 {D(0x3fa779a6, 0x7019ef92)},
00119 };
00120
00121
00122
00123 static const du P2[] =
00124 {
00125 {D(0x00000000, 0x00000000)},
00126 {D(0xc003463c, 0xd05a4ebc)},
00127 {D(0xc006a82b, 0xc06143d7)},
00128 {D(0xbfe73f9d, 0x6d046093)},
00129 {D(0xbf7d6f3f, 0x1d90fdcf)},
00130 };
00131
00132 static const du Q2[] =
00133 {
00134 {D(0x401ce95b, 0x38877730)},
00135 {D(0x4029aa88, 0xfad77a71)},
00136 {D(0x401b207c, 0xe379aaab)},
00137 {D(0x3ff00000, 0x00000000)},
00138 };
00139
00140
00141
00142 static const du P3[] =
00143 {
00144 {D(0x3ff00000, 0x00000000)},
00145 {D(0xbfd55555, 0x55555538)},
00146 {D(0x3fc99999, 0x999827a8)},
00147 {D(0xbfc24924, 0x8f3fab6c)},
00148 {D(0x3fbc71c1, 0x3cf9a795)},
00149 {D(0xbfb742f1, 0x6d401761)},
00150 {D(0x3fb2ff51, 0xeeb75b4f)},
00151 };
00152
00153
00154
00155 static const du P4[] =
00156 {
00157 {D(0x3ff00000, 0x00000000)},
00158 {D(0xbfd55555, 0x55555537)},
00159 {D(0x3fc99999, 0x9996312c)},
00160 {D(0xbfc24924, 0x8296d3ad)},
00161 {D(0x3fbc7187, 0xfb7f8b73)},
00162 {D(0xbfb70c21, 0xce9d3f8f)},
00163 };
00164
00165 static const du piby4 =
00166 {D(0x3fe921fb, 0x54442d18)};
00167
00168 static const du piby2 =
00169 {D(0x3ff921fb, 0x54442d18)};
00170
00171 static const du m_piby2 =
00172 {D(0xbff921fb, 0x54442d18)};
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186 double
00187 __atan( double x )
00188 {
00189 #ifdef _32BIT_MACHINE
00190
00191 int ix, xpt;
00192
00193 #else
00194
00195 long long ix, xpt;
00196
00197 #endif
00198
00199 double xsq, num, denom, result;
00200 double z, zsq;
00201 #ifdef _CALL_MATHERR
00202 struct exception exstruct;
00203 #endif
00204
00205
00206
00207 #ifdef _32BIT_MACHINE
00208
00209 DBLHI2INT(x, ix);
00210 #else
00211 DBL2LL(x, ix);
00212 #endif
00213 xpt = (ix >> DMANTWIDTH);
00214 xpt &= 0x7ff;
00215
00216 if ( xpt < 0x400 )
00217 {
00218 if ( xpt < 0x3fe )
00219 {
00220
00221
00222 if ( xpt >= 0x3e3 )
00223 {
00224
00225
00226 xsq = x*x;
00227
00228 num = (((P1[4].d*xsq + P1[3].d)*xsq +
00229 P1[2].d)*xsq + P1[1].d)*xsq + P1[0].d;
00230
00231 denom = (((Q1[4].d*xsq + Q1[3].d)*xsq +
00232 Q1[2].d)*xsq + Q1[1].d)*xsq + Q1[0].d;
00233
00234 result = x + x*xsq*num/denom;
00235
00236 return ( result );
00237 }
00238
00239 return (x);
00240 }
00241 else
00242 {
00243
00244
00245 z = (fabs(x) - 1.0)/(1.0 + fabs(x));
00246
00247 zsq = z*z;
00248
00249 num = (((P2[4].d*zsq + P2[3].d)*zsq + P2[2].d)*zsq + P2[1].d);
00250
00251 denom = ((Q2[3].d*zsq + Q2[2].d)*zsq + Q2[1].d)*zsq + Q2[0].d;
00252
00253 result = z + ((z*zsq)*num)/denom;
00254
00255 result = piby4.d + result;
00256
00257 if ( x < 0.0 )
00258 result = -result;
00259
00260 return ( result );
00261 }
00262 }
00263 else if ( xpt < 0x403 )
00264 {
00265 if ( xpt < 0x401 )
00266 {
00267
00268
00269 z = (fabs(x) - x0.d)/(1.0 + fabs(x)*x0.d);
00270 zsq = z*z;
00271
00272 result = (((((P3[6].d*zsq + P3[5].d)*zsq + P3[4].d)*zsq +
00273 P3[3].d)*zsq + P3[2].d)*zsq + P3[1].d)*zsq;
00274
00275 result = z*result + z + atanx0.d;
00276
00277 if ( x < 0.0 )
00278 result = -result;
00279
00280 return ( result );
00281 }
00282 else if ( xpt < 0x402 )
00283 {
00284
00285
00286 z = (fabs(x) - x1.d)/(1.0 + fabs(x)*x1.d);
00287 zsq = z*z;
00288
00289 result = ((((P4[5].d*zsq + P4[4].d)*zsq +
00290 P4[3].d)*zsq + P4[2].d)*zsq + P4[1].d)*zsq;
00291
00292 result = z*result + z + atanx1.d;
00293
00294 if ( x < 0.0 )
00295 result = -result;
00296
00297 return ( result );
00298 }
00299 else
00300 {
00301
00302
00303 z = (fabs(x) - x2.d)/(1.0 + fabs(x)*x2.d);
00304 zsq = z*z;
00305
00306 result = ((((P4[5].d*zsq + P4[4].d)*zsq +
00307 P4[3].d)*zsq + P4[2].d)*zsq + P4[1].d)*zsq;
00308
00309 result = z*result + z + atanx2.d;
00310
00311 if ( x < 0.0 )
00312 result = -result;
00313
00314 return ( result );
00315 }
00316 }
00317 else if ( xpt < 0x435 )
00318 {
00319
00320
00321
00322
00323 z = -1.0/fabs(x);
00324 zsq = z*z;
00325
00326 result = ((((P4[5].d*zsq + P4[4].d)*zsq + P4[3].d)*zsq +
00327 P4[2].d)*zsq + P4[1].d)*zsq;
00328
00329 result = result*z + z + piby4.d + piby4.d;
00330
00331 if ( x < 0.0 )
00332 result = -result;
00333
00334 return ( result );
00335 }
00336
00337 if ( x != x )
00338 {
00339
00340
00341 #ifdef _CALL_MATHERR
00342
00343 exstruct.type = DOMAIN;
00344 exstruct.name = "atan";
00345 exstruct.arg1 = x;
00346 exstruct.retval = Qnan.d;
00347
00348 if ( matherr( &exstruct ) == 0 )
00349 {
00350 fprintf(stderr, "domain error in atan\n");
00351 SETERRNO(EDOM);
00352 }
00353
00354 return ( exstruct.retval );
00355 #else
00356 NAN_SETERRNO(EDOM);
00357
00358 return ( Qnan.d );
00359 #endif
00360 }
00361
00362 if ( ix > 0 )
00363 return ( piby2.d );
00364
00365 return ( m_piby2.d );
00366 }
00367
00368 #ifdef NO_LONG_DOUBLE
00369
00370 #if defined(BUILD_OS_DARWIN)
00371 #pragma weak atanl
00372 long double atanl( long double x ) {
00373 return ( (long double)__atan((double)x) );
00374 }
00375 #elif defined(__GNUC__)
00376 extern long double __atanl(long double);
00377
00378 long double atanl() __attribute__ ((weak, alias ("__atanl")));
00379
00380 #endif
00381
00382 long double
00383 __atanl( long double x )
00384 {
00385 return ( (long double)__atan((double)x) );
00386 }
00387
00388 #endif
00389