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: /home/bos/bk/kpro64-pending/libm/mips/SCCS/s.tanf.c $ $Revision: 1.5 $";
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 ftan(float);
00071 extern float tanf(float);
00072
00073 #pragma weak ftan = __tanf
00074 #pragma weak tanf = __tanf
00075 #endif
00076
00077 #if defined(BUILD_OS_DARWIN)
00078 extern float __tanf(float);
00079 #pragma weak tanf
00080 float tanf( float x ) {
00081 return __tanf( x );
00082 }
00083 #elif defined(__GNUC__)
00084 extern float __tanf(float);
00085 float tanf(float) __attribute__ ((weak, alias ("__tanf")));
00086 #endif
00087
00088
00089
00090 static const du P[] =
00091 {
00092 {D(0x3ff00000, 0x00000000)},
00093 {D(0x3fd5554d, 0xee0d8ef8)},
00094 {D(0x3fc112db, 0xaacfc056)},
00095 {D(0x3fab58b6, 0xc20538bd)},
00096 {D(0x3f990447, 0xf756b2dd)},
00097 {D(0x3f698e16, 0x80b8e679)},
00098 {D(0x3f8338c7, 0xa092a7f3)},
00099 };
00100
00101
00102
00103 static const du P2[] =
00104 {
00105 {D(0xbfd55555, 0x55555555)},
00106 {D(0xbf96c1b2, 0x603d1494)},
00107 {D(0xbf614116, 0xf382ec7a)},
00108 {D(0xbf2f5d6f, 0x1e20e337)},
00109 };
00110
00111 static const du rpiby2 =
00112 {D(0x3fe45f30, 0x6dc9c883)};
00113
00114 static const du m_one =
00115 {D(0xbff00000, 0x00000000)};
00116
00117 static const du piby2hi =
00118 {D(0x3ff921fb, 0x50000000)};
00119
00120 static const du piby2lo =
00121 {D(0x3e5110b4, 0x611a6263)};
00122
00123 static const fu Qnan = {QNANF};
00124
00125 static const fu Inf = {0x7f800000};
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137 float
00138 __tanf( float x )
00139 {
00140 int ix, xpt;
00141 int n;
00142 double dx, xsq, poly;
00143 double dn;
00144 double result;
00145 #ifdef _CALL_MATHERR
00146 struct exception exstruct;
00147 #endif
00148
00149 FLT2INT(x, ix);
00150 xpt = (ix >> (MANTWIDTH-1));
00151 xpt &= 0x1ff;
00152
00153
00154
00155 if ( xpt < 0xfd )
00156 {
00157
00158
00159
00160
00161 dx = x;
00162
00163 if ( xpt >= 0xe6 )
00164 {
00165
00166
00167 xsq = dx*dx;
00168
00169 poly = ((((P[6].d*xsq + P[5].d)*xsq + P[4].d)*xsq +
00170 + P[3].d)*xsq + P[2].d)*xsq + P[1].d;
00171
00172 result = dx + (dx*xsq)*poly;
00173
00174 return ( (float)result );
00175 }
00176
00177 return ( x );
00178 }
00179
00180 if ( xpt < 0x136 )
00181 {
00182
00183
00184
00185
00186 dx = x;
00187
00188 dn = dx*rpiby2.d;
00189
00190 n = ROUND(dn);
00191 dn = n;
00192
00193 dx = dx - dn*piby2hi.d;
00194 dx = dx - dn*piby2lo.d;
00195
00196 if ( (n & 1) == 0 )
00197 {
00198
00199
00200 xsq = dx*dx;
00201
00202 poly = ((((P[6].d*xsq + P[5].d)*xsq + P[4].d)*xsq +
00203 + P[3].d)*xsq + P[2].d)*xsq + P[1].d;
00204
00205 result = dx + (dx*xsq)*poly;
00206
00207 return ( (float)result );
00208 }
00209
00210
00211
00212
00213 xsq = dx*dx;
00214
00215 result = m_one.d/dx;
00216
00217 poly = (((P2[3].d*xsq + P2[2].d)*xsq + P2[1].d)*xsq +
00218 P2[0].d)*dx;
00219
00220 result -= poly;
00221
00222 return ( (float)result );
00223 }
00224
00225 if ( (x != x) || (fabsf(x) == Inf.f) )
00226 {
00227
00228
00229 #ifdef _CALL_MATHERR
00230
00231 exstruct.type = DOMAIN;
00232 exstruct.name = "tanf";
00233 exstruct.arg1 = x;
00234 exstruct.retval = Qnan.f;
00235
00236 if ( matherr( &exstruct ) == 0 )
00237 {
00238 fprintf(stderr, "domain error in tanf\n");
00239 SETERRNO(EDOM);
00240 }
00241
00242 return ( exstruct.retval );
00243 #else
00244 NAN_SETERRNO(EDOM);
00245
00246 return ( Qnan.f );
00247 #endif
00248 }
00249
00250
00251
00252 #ifdef _CALL_MATHERR
00253
00254 exstruct.type = TLOSS;
00255 exstruct.name = "tanf";
00256 exstruct.arg1 = x;
00257 exstruct.retval = 0.0;
00258
00259 if ( matherr( &exstruct ) == 0 )
00260 {
00261 fprintf(stderr, "range error in tanf (total loss \
00262 of significance)\n");
00263 SETERRNO(ERANGE);
00264 }
00265
00266 return ( exstruct.retval );
00267 #else
00268 SETERRNO(ERANGE);
00269
00270 return ( 0.0f );
00271 #endif
00272 }
00273