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 static char *rcs_id = "$Source: /proj/osprey/CVS/open64/osprey1.0/libm/mips/acosf.c,v $ $Revision: 1.1.1.1 $";
00060
00061 #ifdef _CALL_MATHERR
00062 #include <stdio.h>
00063 #include <math.h>
00064 #include <errno.h>
00065 #endif
00066
00067 #include "libm.h"
00068
00069 #if defined(mips) && !defined(__GNUC__)
00070 extern float facos(float);
00071 extern float acosf(float);
00072
00073 #pragma weak facos = __acosf
00074 #pragma weak acosf = __acosf
00075 #endif
00076
00077 #if defined(BUILD_OS_DARWIN)
00078 extern float __acosf(float);
00079 #pragma weak acosf
00080 float acosf( float x ) {
00081 return __acosf(x);
00082 }
00083 #elif defined(__GNUC__)
00084 extern float __acosf(float);
00085 float acosf(float) __attribute__ ((weak, alias ("__acosf")));
00086 #endif
00087
00088
00089
00090 static const du P[] =
00091 {
00092 {D(0x3ff00000, 0x00000000)},
00093 {D(0x3fc5555c, 0x88342cb0)},
00094 {D(0x3fb3301e, 0x4681bb77)},
00095 {D(0x3fa747e4, 0xa38c190b)},
00096 {D(0x3f98c283, 0xc04a0db6)},
00097 {D(0x3fa596d2, 0x8a9d07d2)},
00098 };
00099
00100
00101
00102 static const du P2[] =
00103 {
00104 {D(0x3ff00000, 0x00000000)},
00105 {D(0x3fc55564, 0xfd6bdcbc)},
00106 {D(0x3fb32843, 0xb5c74590)},
00107 {D(0x3fa90146, 0xd5d24e0c)},
00108 };
00109
00110 static const du half =
00111 {D(0x3fe00000, 0x00000000)};
00112
00113 static const du one =
00114 {D(0x3ff00000, 0x00000000)};
00115
00116 static const du piby4 =
00117 {D(0x3fe921fb, 0x54442d18)};
00118
00119 static const du piby2 =
00120 {D(0x3ff921fb, 0x54442d18)};
00121
00122 static const du threepiby4 =
00123 {D(0x4002d97c, 0x7f3321d2)};
00124
00125 static const du pi =
00126 {D(0x400921fb, 0x54442d18)};
00127
00128 static const fu Qnan = {QNANF};
00129
00130 static const fu f_half = {0x3f000000};
00131
00132 static const fu f_one = {0x3f800000};
00133
00134 static const fu f_m_one = {0xbf800000};
00135
00136 static const fu f_piby2 = {0x3fc90fdb};
00137
00138 static const fu f_pi = {0x40490fdb};
00139
00140 static const int root3by2 = 0x3f5db3d7;
00141
00142 #ifndef _HDW_SQRT
00143
00144 #define MAGIC 0x5fe6eb3b
00145
00146 #endif
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158 float
00159 __acosf( float x )
00160 {
00161 int n;
00162 int ix, xpt;
00163 unsigned int iabsx;
00164 float absx;
00165 double dx, xsq, poly;
00166 double result;
00167 double y, ysq;
00168 double w;
00169 double q, Q;
00170 double ysqby2;
00171 #ifdef _CALL_MATHERR
00172 struct exception exstruct;
00173 #endif
00174
00175 FLT2INT(x, ix);
00176 iabsx = (ix << 1);
00177 iabsx >>= 1;
00178 xpt = (iabsx >> MANTWIDTH);
00179
00180 if ( xpt < 0x7e )
00181 {
00182
00183
00184 if ( xpt >= 0x65 )
00185 {
00186
00187
00188 dx = x;
00189
00190 xsq = dx*dx;
00191
00192 poly = ((((P[5].d*xsq + P[4].d)*xsq + P[3].d)*xsq +
00193 P[2].d)*xsq + P[1].d)*(xsq*dx) + dx;
00194
00195 result = piby2.d - poly;
00196
00197 return ( (float)result );
00198 }
00199
00200 return ( f_piby2.f );
00201 }
00202
00203 if ( xpt < 0x7f )
00204 {
00205
00206
00207 if ( iabsx < root3by2 )
00208 {
00209
00210
00211 dx = x;
00212
00213 xsq = dx*dx;
00214 y = xsq + xsq - one.d;
00215 ysq = y*y;
00216
00217 poly = ((((P[5].d*ysq + P[4].d)*ysq + P[3].d)*ysq +
00218 P[2].d)*ysq + P[1].d);
00219
00220 poly = y + (y*ysq)*poly;
00221
00222 if ( ix > 0 )
00223 return ( (float)(piby4.d - half.d*poly) );
00224 else
00225 return ( (float)(threepiby4.d + half.d*poly) );
00226 }
00227
00228 absx = fabsf(x);
00229
00230 ysq = f_half.f*(f_one.f - absx);
00231
00232 #ifdef _HDW_SQRT
00233
00234 y = sqrt(ysq);
00235 #else
00236
00237
00238
00239
00240
00241
00242
00243
00244 y = 0.0;
00245 DBLHI2INT(ysq, n);
00246 n >>= 1;
00247 n = MAGIC - n;
00248 INT2DBLHI(n, y);
00249 ysqby2 = half.d*ysq;
00250
00251
00252
00253 y = y*(1.5 - ysqby2*y*y);
00254 y = y*(1.5 - ysqby2*y*y);
00255
00256
00257
00258 q = ysqby2*y;
00259 Q = q + q;
00260 y = Q*(1.5 - q*y);
00261 #endif
00262
00263
00264
00265 poly = ((P2[3].d*ysq + P2[2].d)*ysq + P2[1].d);
00266
00267 w = y + (y*ysq)*poly;
00268
00269 if ( ix > 0 )
00270 return ( (float)(w + w) );
00271 else
00272 return ( (float)(pi.d - (w + w)) );
00273 }
00274
00275 if ( x != x )
00276 {
00277
00278
00279 #ifdef _CALL_MATHERR
00280
00281 exstruct.type = DOMAIN;
00282 exstruct.name = "acosf";
00283 exstruct.arg1 = x;
00284 exstruct.retval = Qnan.f;
00285
00286 if ( matherr( &exstruct ) == 0 )
00287 {
00288 fprintf(stderr, "domain error in acosf\n");
00289 SETERRNO(EDOM);
00290 }
00291
00292 return ( exstruct.retval );
00293 #else
00294 NAN_SETERRNO(EDOM);
00295
00296 return ( Qnan.f );
00297 #endif
00298 }
00299
00300 if ( x == f_one.f )
00301 return ( 0.0f );
00302
00303 if ( x == f_m_one.f )
00304 return ( f_pi.f );
00305
00306
00307
00308 #ifdef _CALL_MATHERR
00309
00310 exstruct.type = DOMAIN;
00311 exstruct.name = "acosf";
00312 exstruct.arg1 = x;
00313 exstruct.retval = Qnan.f;
00314
00315 if ( matherr( &exstruct ) == 0 )
00316 {
00317 fprintf(stderr, "domain error in acosf\n");
00318 SETERRNO(EDOM);
00319 }
00320
00321 return ( exstruct.retval );
00322 #else
00323 SETERRNO(EDOM);
00324
00325 return ( Qnan.f );
00326 #endif
00327 }
00328