32 #ifdef POK_NEEDS_LIBMATH
35 #include "namespace.h"
36 #include "math_private.h"
38 static float ponef(
float), qonef(
float);
43 invsqrtpi= 5.6418961287e-01,
44 tpi = 6.3661974669e-01,
46 r00 = -6.2500000000e-02,
47 r01 = 1.4070566976e-03,
48 r02 = -1.5995563444e-05,
49 r03 = 4.9672799207e-08,
50 s01 = 1.9153760746e-02,
51 s02 = 1.8594678841e-04,
52 s03 = 1.1771846857e-06,
53 s04 = 5.0463624390e-09,
54 s05 = 1.2354227016e-11;
56 static const float zero = 0.0;
59 __ieee754_j1f(
float x)
61 float z, s,c,ss,cc,r,u,v,y;
66 if(ix>=0x7f800000)
return one/x;
68 if(ix >= 0x40000000) {
75 if ((s*c)>zero) cc = z/ss;
83 if(ix>0x80000000) z = (invsqrtpi*cc)/sqrtf(y);
87 u = ponef(y); v = qonef(y);
88 z = invsqrtpi*(u*cc-v*ss)/sqrtf(y);
94 if(huge+x>one)
return (
float)0.5*x;
97 r = z*(r00+z*(r01+z*(r02+z*r03)));
98 s = one+z*(s01+z*(s02+z*(s03+z*(s04+z*s05))));
100 return(x*(
float)0.5+r/s);
103 static const float U0[5] = {
110 static const float V0[5] = {
119 __ieee754_y1f(
float x)
121 float z, s,c,ss,cc,u,v;
124 GET_FLOAT_WORD(hx,x);
127 if(ix>=0x7f800000)
return one/(x+x*x);
128 if(ix==0)
return -one/zero;
129 if(hx<0)
return zero/zero;
130 if(ix >= 0x40000000) {
137 if ((s*c)>zero) cc = z/ss;
151 if(ix>0x48000000) z = (invsqrtpi*ss)/sqrtf(x);
153 u = ponef(x); v = qonef(x);
154 z = invsqrtpi*(u*ss+v*cc)/sqrtf(x);
162 u = U0[0]+z*(U0[1]+z*(U0[2]+z*(U0[3]+z*U0[4])));
163 v = one+z*(V0[0]+z*(V0[1]+z*(V0[2]+z*(V0[3]+z*V0[4]))));
164 return(x*(u/v) + tpi*(__ieee754_j1f(x)*__ieee754_logf(x)-one/x));
177 static const float pr8[6] = {
185 static const float ps8[5] = {
193 static const float pr5[6] = {
201 static const float ps5[5] = {
209 static const float pr3[6] = {
217 static const float ps3[5] = {
225 static const float pr2[6] = {
233 static const float ps2[5] = {
249 GET_FLOAT_WORD(ix,x);
251 if(ix>=0x41000000) {p = pr8; q= ps8;}
252 else if(ix>=0x40f71c58){p = pr5; q= ps5;}
253 else if(ix>=0x4036db68){p = pr3; q= ps3;}
254 else if(ix>=0x40000000){p = pr2; q= ps2;}
256 r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
257 s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*q[4]))));
272 static const float qr8[6] = {
280 static const float qs8[6] = {
289 static const float qr5[6] = {
297 static const float qs5[6] = {
306 static const float qr3[6] = {
314 static const float qs3[6] = {
323 static const float qr2[6] = {
331 static const float qs2[6] = {
348 GET_FLOAT_WORD(ix,x);
351 if(ix>=0x41000000) {p = qr8; q= qs8;}
353 else if(ix>=0x409173eb){p = qr5; q= qs5;}
355 else if(ix>=0x4036d917){p = qr3; q= qs3;}
357 else if(ix>=0x40000000){p = qr2; q= qs2;}
359 r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
360 s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*(q[4]+z*q[5])))));
361 return ((
float).375 + r/s)/x;