#include <float.h>
#include "math.h"
#include "math_private.h"
#include "fpmath.h"
#define BIAS (LDBL_MAX_EXP - 1)
static const double
zero = 0.00000000000000000000e+00,
two24 = 1.67772160000000000000e+07,
pio2_1 = 1.57079632679597125389e+00,
pio2_2 = -1.07463465549783099519e-12,
pio2_3 = 6.36831716351370313614e-25;
#if defined(__amd64__) || defined(__i386__)
static const volatile double
invpio2hi = 6.3661977236758138e-01,
invpio2lo = -3.9356538861223811e-17,
pio2_1thi = -1.0746346554971943e-12,
pio2_1tlo = 8.8451028997905949e-29,
pio2_2thi = 6.3683171635109499e-25,
pio2_2tlo = 2.3183081793789774e-41,
pio2_3thi = -2.7529965190440717e-37,
pio2_3tlo = -4.2006647512740502e-54;
#define invpio2 ((long double)invpio2hi + invpio2lo)
#define pio2_1t ((long double)pio2_1thi + pio2_1tlo)
#define pio2_2t ((long double)pio2_2thi + pio2_2tlo)
#define pio2_3t ((long double)pio2_3thi + pio2_3tlo)
#else
static const long double
invpio2 = 6.36619772367581343076e-01L,
pio2_1t = -1.07463465549719416346e-12L,
pio2_2t = 6.36831716351095013979e-25L,
pio2_3t = -2.75299651904407171810e-37L;
#endif
static __always_inline int
__ieee754_rem_pio2l(long double x, long double *y)
{
union IEEEl2bits u,u1;
long double z,w,t,r,fn;
double tx[3],ty[2];
int e0,ex,i,j,nx,n;
int16_t expsign;
u.e = x;
expsign = u.xbits.expsign;
ex = expsign & 0x7fff;
if (ex < BIAS + 25 || (ex == BIAS + 25 && u.bits.manh < 0xc90fdaa2)) {
fn = rnintl(x*invpio2);
n = irint(fn);
r = x-fn*pio2_1;
w = fn*pio2_1t;
{
union IEEEl2bits u2;
int ex1;
j = ex;
y[0] = r-w;
u2.e = y[0];
ex1 = u2.xbits.expsign & 0x7fff;
i = j-ex1;
if(i>22) {
t = r;
w = fn*pio2_2;
r = t-w;
w = fn*pio2_2t-((t-r)-w);
y[0] = r-w;
u2.e = y[0];
ex1 = u2.xbits.expsign & 0x7fff;
i = j-ex1;
if(i>61) {
t = r;
w = fn*pio2_3;
r = t-w;
w = fn*pio2_3t-((t-r)-w);
y[0] = r-w;
}
}
}
y[1] = (r-y[0])-w;
return n;
}
if(ex==0x7fff) {
y[0]=y[1]=x-x; return 0;
}
u1.e = x;
e0 = ex - BIAS - 23;
u1.xbits.expsign = ex - e0;
z = u1.e;
for(i=0;i<2;i++) {
tx[i] = (double)((int32_t)(z));
z = (z-tx[i])*two24;
}
tx[2] = z;
nx = 3;
while(tx[nx-1]==zero) nx--;
n = __kernel_rem_pio2(tx,ty,e0,nx,2);
r = (long double)ty[0] + ty[1];
w = ty[1] - (r - ty[0]);
if(expsign<0) {y[0] = -r; y[1] = -w; return -n;}
y[0] = r; y[1] = w; return n;
}