35 #ifdef POK_NEEDS_LIBMATH
37 #include "math_private.h"
39 static const double one = 1.0, Zero[] = {0.0, -0.0,};
42 __ieee754_fmod(
double x,
double y)
44 int32_t n,hx,hy,hz,ix,iy,sx,i;
47 EXTRACT_WORDS(hx,lx,x);
48 EXTRACT_WORDS(hy,ly,y);
54 if((hy|ly)==0||(hx>=0x7ff00000)||
55 ((hy|((ly|-ly)>>31))>0x7ff00000))
58 if((hx<hy)||(lx<ly))
return x;
60 return Zero[(uint32_t)sx>>31];
66 for (ix = -1043, i=lx; i>0; i<<=1) ix -=1;
68 for (ix = -1022,i=(hx<<11); i>0; i<<=1) ix -=1;
70 }
else ix = (hx>>20)-1023;
75 for (iy = -1043, i=ly; i>0; i<<=1) iy -=1;
77 for (iy = -1022,i=(hy<<11); i>0; i<<=1) iy -=1;
79 }
else iy = (hy>>20)-1023;
83 hx = 0x00100000|(0x000fffff&hx);
87 hx = (hx<<n)|(lx>>(32-n));
95 hy = 0x00100000|(0x000fffff&hy);
99 hy = (hy<<n)|(ly>>(32-n));
110 hz=hx-hy;lz=lx-ly;
if(lx<ly) hz -= 1;
111 if(hz<0){hx = hx+hx+(lx>>31); lx = lx+lx;}
114 return Zero[(uint32_t)sx>>31];
115 hx = hz+hz+(lz>>31); lx = lz+lz;
118 hz=hx-hy;lz=lx-ly;
if(lx<ly) hz -= 1;
119 if(hz>=0) {hx=hz;lx=lz;}
123 return Zero[(uint32_t)sx>>31];
124 while(hx<0x00100000) {
125 hx = hx+hx+(lx>>31); lx = lx+lx;
129 hx = ((hx-0x00100000)|((iy+1023)<<20));
130 INSERT_WORDS(x,hx|sx,lx);
134 lx = (lx>>n)|((uint32_t)hx<<(32-n));
137 lx = (hx<<(32-n))|(lx>>n); hx = sx;
139 lx = hx>>(n-32); hx = sx;
141 INSERT_WORDS(x,hx|sx,lx);