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 static char *rcs_id = "$Source: /proj/osprey/CVS/open64/osprey1.0/libm/mips/cosf.c,v $ $Revision: 1.1.1.1 $";
00056
00057 #ifdef _CALL_MATHERR
00058 #include <stdio.h>
00059 #include <math.h>
00060 #include <errno.h>
00061 #endif
00062
00063 #include "libm.h"
00064
00065 #ifdef mips
00066 extern float fcos(float);
00067 extern float cosf(float);
00068
00069 #pragma weak fcos = __cosf
00070 #pragma weak cosf = __cosf
00071 #endif
00072
00073 #if defined(BUILD_OS_DARWIN)
00074 extern float __cosf(float);
00075 #pragma weak cosf
00076 float cosf( float x ) {
00077 return __cosf( x );
00078 }
00079 #elif defined(__GNUC__)
00080 extern float __cosf(float);
00081 float cosf(float) __attribute__ ((weak, alias ("__cosf")));
00082 #endif
00083
00084
00085
00086 static const du S[] =
00087 {
00088 {D(0x3ff00000, 0x00000000)},
00089 {D(0xbfc55554, 0x5268a030)},
00090 {D(0x3f811073, 0xafd14db9)},
00091 {D(0xbf29943e, 0x0fc79aa9)},
00092 };
00093
00094
00095
00096 static const du C[] =
00097 {
00098 {D(0x3ff00000, 0x00000000)},
00099 {D(0xbfdffffb, 0x2a77e083)},
00100 {D(0x3fa553e7, 0xf02ac8aa)},
00101 {D(0xbf5644d6, 0x2993c4ad)},
00102 };
00103
00104 static const du rpiby2 =
00105 {D(0x3fe45f30, 0x6dc9c883)};
00106
00107 static const du piby2hi =
00108 {D(0x3ff921fb, 0x50000000)};
00109
00110 static const du piby2lo =
00111 {D(0x3e5110b4, 0x611a6263)};
00112
00113 static const fu Qnan = {QNANF};
00114
00115 static const fu Inf = {0x7f800000};
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132 float
00133 __cosf( float x )
00134 {
00135 int n;
00136 int ix, xpt;
00137 double dx, xsq;
00138 double dn;
00139 double poly;
00140 float result;
00141 #ifdef _CALL_MATHERR
00142 struct exception exstruct;
00143 #endif
00144
00145 FLT2INT(x, ix);
00146
00147 xpt = (ix >> (MANTWIDTH-1));
00148 xpt &= 0x1ff;
00149
00150
00151
00152 if ( xpt < 0xfd )
00153 {
00154
00155
00156 dx = x;
00157
00158 if ( xpt >= 0xe6 )
00159 {
00160
00161
00162 xsq = dx*dx;
00163
00164 result = ((C[3].d*xsq + C[2].d)*xsq + C[1].d)*xsq + 1.0;
00165 }
00166 else
00167 {
00168 result = 1.0f;
00169 }
00170
00171 return ( result );
00172 }
00173
00174 if (xpt < 0x12a)
00175 {
00176
00177
00178 dx = x;
00179 dn = dx*rpiby2.d;
00180
00181 n = ROUND(dn);
00182 dn = n;
00183
00184 dx = dx - dn*piby2hi.d;
00185 dx = dx - dn*piby2lo.d;
00186
00187 xsq = dx*dx;
00188
00189 if ( n&1 )
00190 {
00191 poly = ((S[3].d*xsq + S[2].d)*xsq + S[1].d)*(xsq*dx) + dx;
00192
00193 if ( n&2 )
00194 {
00195
00196
00197
00198
00199
00200 result = poly;
00201 }
00202 else
00203 {
00204
00205
00206
00207
00208
00209 result = -poly;
00210 }
00211
00212 return ( result );
00213 }
00214
00215 poly = ((C[3].d*xsq + C[2].d)*xsq + C[1].d)*xsq + C[0].d;
00216
00217 if ( n&2 )
00218 {
00219
00220
00221
00222
00223
00224 result = -poly;
00225 }
00226 else
00227 {
00228
00229
00230
00231
00232
00233 result = poly;
00234 }
00235
00236 return ( result );
00237 }
00238
00239 if ( (x != x) || (fabsf(x) == Inf.f) )
00240 {
00241
00242
00243 #ifdef _CALL_MATHERR
00244
00245 exstruct.type = DOMAIN;
00246 exstruct.name = "cosf";
00247 exstruct.arg1 = x;
00248 exstruct.retval = Qnan.f;
00249
00250 if ( matherr( &exstruct ) == 0 )
00251 {
00252 fprintf(stderr, "domain error in cosf\n");
00253 SETERRNO(EDOM);
00254 }
00255
00256 return ( exstruct.retval );
00257 #else
00258 NAN_SETERRNO(EDOM);
00259
00260 return ( Qnan.f );
00261 #endif
00262 }
00263
00264
00265
00266 #ifdef _CALL_MATHERR
00267
00268 exstruct.type = TLOSS;
00269 exstruct.name = "cosf";
00270 exstruct.arg1 = x;
00271 exstruct.retval = 0.0f;
00272
00273 if ( matherr( &exstruct ) == 0 )
00274 {
00275 fprintf(stderr, "range error in cosf (total loss \
00276 of significance)\n");
00277 SETERRNO(ERANGE);
00278 }
00279
00280 return ( exstruct.retval );
00281 #else
00282 SETERRNO(ERANGE);
00283
00284 return ( 0.0f );
00285 #endif
00286 }
00287