29 #ifdef POK_NEEDS_LIBMATH
148 #include "math_private.h"
150 static const int init_jk[] = {2,3,4,6};
152 static const double PIo2[] = {
153 1.57079625129699707031e+00,
154 7.54978941586159635335e-08,
155 5.39030252995776476554e-15,
156 3.28200341580791294123e-22,
157 1.27065575308067607349e-29,
158 1.22933308981111328932e-36,
159 2.73370053816464559624e-44,
160 2.16741683877804819444e-51,
166 two24 = 1.67772160000000000000e+07,
167 twon24 = 5.96046447753906250000e-08;
170 __kernel_rem_pio2(
double *x,
double *y,
int e0,
int nx,
int prec,
const int *ipio2)
172 int32_t jz,jx,jv,jp,jk,carry,n,iq[20],i,j,k,m,q0,ih;
173 double z,fw,f[20],fq[20],q[20];
181 jv = (e0-3)/24;
if(jv<0) jv=0;
185 j = jv-jx; m = jx+jk;
186 for(i=0;i<=m;i++,j++) f[i] = (j<0)? zero : (double) ipio2[j];
189 for (i=0;i<=jk;i++) {
190 for(j=0,fw=0.0;j<=jx;j++) fw += x[j]*f[jx+i-j]; q[i] = fw;
196 for(i=0,j=jz,z=q[jz];j>0;i++,j--) {
197 fw = (double)((int32_t)(twon24* z));
198 iq[i] = (int32_t)(z-two24*fw);
204 z -= 8.0*floor(z*0.125);
209 i = (iq[jz-1]>>(24-q0)); n += i;
210 iq[jz-1] -= i<<(24-q0);
211 ih = iq[jz-1]>>(23-q0);
213 else if(q0==0) ih = iq[jz-1]>>23;
214 else if(z>=0.5) ih=2;
222 carry = 1; iq[i] = 0x1000000- j;
224 }
else iq[i] = 0xffffff - j;
229 iq[jz-1] &= 0x7fffff;
break;
231 iq[jz-1] &= 0x3fffff;
break;
236 if(carry!=0) z -= scalbn(one,q0);
243 for (i=jz-1;i>=jk;i--) j |= iq[i];
245 for(k=1;iq[jk-k]==0;k++);
247 for(i=jz+1;i<=jz+k;i++) {
248 f[jx+i] = (double) ipio2[jv+i];
249 for(j=0,fw=0.0;j<=jx;j++) fw += x[j]*f[jx+i-j];
260 while(iq[jz]==0) { jz--; q0-=24;}
264 fw = (double)((int32_t)(twon24*z));
265 iq[jz] = (int32_t)(z-two24*fw);
267 iq[jz] = (int32_t) fw;
268 }
else iq[jz] = (int32_t) z ;
274 q[i] = fw*(double)iq[i]; fw*=twon24;
279 for(fw=0.0,k=0;k<=jp&&k<=jz-i;k++) fw += PIo2[k]*q[i+k];
287 for (i=jz;i>=0;i--) fw += fq[i];
288 y[0] = (ih==0)? fw: -fw;
293 for (i=jz;i>=0;i--) fw += fq[i];
294 y[0] = (ih==0)? fw: -fw;
296 for (i=1;i<=jz;i++) fw += fq[i];
297 y[1] = (ih==0)? fw: -fw;
310 for (fw=0.0,i=jz;i>=2;i--) fw += fq[i];
312 y[0] = fq[0]; y[1] = fq[1]; y[2] = fw;
314 y[0] = -fq[0]; y[1] = -fq[1]; y[2] = -fw;