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$ $Revision$";
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 fsin(float);
00067 extern float sinf(float);
00068
00069 #pragma weak fsin = __sinf
00070 #pragma weak sinf = __sinf
00071 #endif
00072
00073 #if defined(BUILD_OS_DARWIN)
00074 extern float __sinf(float);
00075 #pragma weak sinf
00076 float sinf( float x ) {
00077 return __sinf( x );
00078 }
00079 #elif defined(__GNUC__)
00080 extern float __sinf(float);
00081 float sinf(float) __attribute__ ((weak, alias ("__sinf")));
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 __sinf( 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 if ( xpt >= 0xe6 )
00157 {
00158
00159
00160 dx = x;
00161
00162 xsq = dx*dx;
00163
00164 poly = ((S[3].d*xsq + S[2].d)*xsq + S[1].d)*(xsq*dx) + dx;
00165
00166 result = poly;
00167
00168 return ( result );
00169 }
00170 else
00171 {
00172 return ( x );
00173 }
00174
00175 }
00176
00177 if (xpt < 0x12a)
00178 {
00179
00180
00181 dx = x;
00182 dn = dx*rpiby2.d;
00183
00184 n = ROUND(dn);
00185 dn = n;
00186
00187 dx = dx - dn*piby2hi.d;
00188 dx = dx - dn*piby2lo.d;
00189
00190 xsq = dx*dx;
00191
00192 if ( n&1 )
00193 {
00194 poly = ((C[3].d*xsq + C[2].d)*xsq + C[1].d)*xsq + C[0].d;
00195
00196 if ( n&2 )
00197 {
00198
00199
00200
00201
00202
00203 result = -poly;
00204 }
00205 else
00206 {
00207
00208
00209
00210
00211
00212 result = poly;
00213 }
00214
00215 return ( result );
00216 }
00217
00218 poly = ((S[3].d*xsq + S[2].d)*xsq + S[1].d)*(xsq*dx) + dx;
00219
00220 if ( n&2 )
00221 {
00222
00223
00224
00225
00226
00227 result = -poly;
00228 }
00229 else
00230 {
00231
00232
00233
00234
00235
00236 result = poly;
00237 }
00238
00239 return( result );
00240 }
00241
00242 if ( (x != x) || (fabsf(x) == Inf.f) )
00243 {
00244
00245
00246 #ifdef _CALL_MATHERR
00247
00248 exstruct.type = DOMAIN;
00249 exstruct.name = "sinf";
00250 exstruct.arg1 = x;
00251 exstruct.retval = Qnan.f;
00252
00253 if ( matherr( &exstruct ) == 0 )
00254 {
00255 fprintf(stderr, "domain error in sinf\n");
00256 SETERRNO(EDOM);
00257 }
00258
00259 return ( exstruct.retval );
00260 #else
00261 NAN_SETERRNO(EDOM);
00262
00263 return ( Qnan.f );
00264 #endif
00265 }
00266
00267
00268
00269 #ifdef _CALL_MATHERR
00270
00271 exstruct.type = TLOSS;
00272 exstruct.name = "sinf";
00273 exstruct.arg1 = x;
00274 exstruct.retval = 0.0f;
00275
00276 if ( matherr( &exstruct ) == 0 )
00277 {
00278 fprintf(stderr, "range error in sinf (total loss \
00279 of significance)\n");
00280 SETERRNO(ERANGE);
00281 }
00282
00283 return ( exstruct.retval );
00284 #else
00285 SETERRNO(ERANGE);
00286
00287 return ( 0.0f );
00288 #endif
00289 }
00290