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.log1pf.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
00070
00071
00072
00073
00074
00075
00076 #if defined(mips) && !defined(__GNUC__)
00077 extern float flog1p(float);
00078 extern float log1pf(float);
00079
00080 #pragma weak flog1p = __log1pf
00081 #pragma weak log1pf = __log1pf
00082 #endif
00083
00084 #if defined(BUILD_OS_DARWIN)
00085 extern float __log1pf(float);
00086 #pragma weak log1pf
00087 float log1pf( float x ) {
00088 return __log1pf( x );
00089 }
00090 #elif defined(__GNUC__)
00091 extern float __log1pf(float);
00092 float log1pf(float) __attribute__ ((weak, alias ("__log1pf")));
00093 #endif
00094
00095 extern const fu _logftabhi[];
00096 extern const fu _logftablo[];
00097
00098 static const fu Qnan = {QNANF};
00099
00100 static const fu Neginf = {0x7f800000};
00101
00102 static const fu Inf = {0x7f800000};
00103
00104 static const fu P[] =
00105 {
00106 {0x3f800000},
00107 {0x3daaaaa9},
00108 {0x3c4dffbb},
00109 };
00110
00111 static const fu Q[] =
00112 {
00113 {0x3f800000},
00114 {0x3daaaac2},
00115 };
00116
00117 static const fu f_m_one = {0xbf800000};
00118
00119 static const fu f_one = {0x3f800000};
00120
00121
00122
00123 static const fu T1 = {0xbd782a03};
00124
00125
00126
00127 static const fu T2 = {0x3d8415ac};
00128
00129 static const fu T3 = {0x4c800000};
00130
00131 static const fu twop7 = {0x43000000};
00132
00133 static const fu twopm7 = {0x3c000000};
00134
00135 static const fu log2_lead = {0x3f317200};
00136
00137 static const fu log2_trail = {0x35bfbe8e};
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149 float
00150 __log1pf( float x )
00151 {
00152 int xpt;
00153 float u, v;
00154 double u1;
00155 float q;
00156 float result;
00157 int m, n;
00158 float y, f, F;
00159 float l_lead, l_trail;
00160 int j, k;
00161 float twopnegm;
00162 float md;
00163 #ifdef _CALL_MATHERR
00164 struct exception exstruct;
00165 #endif
00166
00167 if ( x != x )
00168 {
00169
00170
00171 #ifdef _CALL_MATHERR
00172
00173 exstruct.type = DOMAIN;
00174 exstruct.name = "log1pf";
00175 exstruct.arg1 = x;
00176 exstruct.retval = Qnan.f;
00177
00178 if ( matherr( &exstruct ) == 0 )
00179 {
00180 fprintf(stderr, "domain error in log1pf\n");
00181 SETERRNO(EDOM);
00182 }
00183
00184 return ( exstruct.retval );
00185 #else
00186 NAN_SETERRNO(EDOM);
00187
00188 return ( Qnan.f );
00189 #endif
00190 }
00191
00192 if ( (T1.f < x) && (x < T2.f) )
00193 {
00194
00195
00196 FLT2INT(x, xpt);
00197 xpt >>= MANTWIDTH;
00198 xpt &= 0xff;
00199
00200 if ( xpt >= 0x67 )
00201 {
00202
00203
00204 u1 = x/(2.0 + x);
00205 u1 = u1 + u1;
00206 u = u1;
00207 v = u1*u1;
00208
00209 q = (P[2].f*v + P[1].f)*(v*u);
00210
00211 result = u1 + q;
00212
00213 return ( result );
00214 }
00215
00216 return ( x );
00217 }
00218
00219 else if ( (x > f_m_one.f) && (x != Inf.f) )
00220 {
00221 if ( x >= T3.f )
00222 y = x;
00223 else
00224 y = f_one.f + x;
00225
00226 FLT2INT(y, k);
00227 m = (k >> MANTWIDTH);
00228 m -= EXPBIAS;
00229 k &= 0x7fffff;
00230 k |= 0x3f800000;
00231 INT2FLT(k, y);
00232
00233 u = twop7.f*y;
00234
00235 j = ROUNDF(u);
00236
00237 F = j;
00238 j -= 128;
00239
00240 F = twopm7.f*F;
00241
00242 if ( m <= -2 )
00243 f = y - F;
00244 else
00245 {
00246 n = EXPBIAS - m;
00247 n <<= MANTWIDTH;
00248
00249 INT2FLT(n, twopnegm);
00250
00251 if ( m <= 23 )
00252 f = (twopnegm - F) + twopnegm*x;
00253 else if ( m <= 50 )
00254 f = (twopnegm*x - F) + twopnegm;
00255 else
00256 f = y - F;
00257 }
00258
00259 md = m;
00260
00261 l_lead = md*log2_lead.f;
00262 l_trail = md*log2_trail.f;
00263
00264 u = (f + f)/(y + F);
00265
00266 l_lead += _logftabhi[j].f;
00267 l_trail += _logftablo[j].f;
00268
00269 v = u*u;
00270
00271 q = Q[1].f*(v*u);
00272
00273 result = l_lead + (u + (q + l_trail));
00274
00275 return ( result );
00276 }
00277
00278 if ( x == Inf.f )
00279 {
00280 return ( Inf.f );
00281 }
00282
00283 if ( x == f_m_one.f )
00284 {
00285 #ifdef _CALL_MATHERR
00286
00287 exstruct.type = OVERFLOW;
00288 exstruct.name = "log1pf";
00289 exstruct.arg1 = x;
00290 exstruct.retval = Neginf.f;
00291
00292 if ( matherr( &exstruct ) == 0 )
00293 {
00294 fprintf(stderr, "overflow range error in log1pf\n");
00295 SETERRNO(ERANGE);
00296 }
00297
00298 return ( exstruct.retval );
00299 #else
00300
00301 SETERRNO(ERANGE);
00302
00303 return ( Neginf.f );
00304 #endif
00305 }
00306
00307
00308
00309 #ifdef _CALL_MATHERR
00310
00311 exstruct.type = DOMAIN;
00312 exstruct.name = "log1pf";
00313 exstruct.arg1 = x;
00314 exstruct.retval = Qnan.f;
00315
00316 if ( matherr( &exstruct ) == 0 )
00317 {
00318 fprintf(stderr, "domain error in log1pf\n");
00319 SETERRNO(EDOM);
00320 }
00321
00322 return ( exstruct.retval );
00323 #else
00324 SETERRNO(EDOM);
00325
00326 return ( Qnan.f );
00327 #endif
00328 }
00329