double nextafter(double x, double y) { int hx,hy,ix,iy; unsigned lx,ly; hx = __HI(x); /* high word of x */ lx = __LO(x); /* low word of x */ hy = __HI(y); /* high word of y */ ly = __LO(y); /* low word of y */ ix = hx&0x7fffffff; /* |x| */ iy = hy&0x7fffffff; /* |y| */ if(((ix>=0x7ff00000)&&((ix-0x7ff00000)|lx)!=0) || /* x is nan */ ((iy>=0x7ff00000)&&((iy-0x7ff00000)|ly)!=0)) /* y is nan */ return x+y; if(x==y) return x; /* x=y, return x */ if((ix|lx)==0) { /* x == 0 */ __HI(x) = hy&0x80000000; /* return +-minsubnormal */ __LO(x) = 1; y = x*x; if(y==x) return y; else return x; /* raise underflow flag */ } if(hx>=0) { /* x > 0 */ if(hx>hy||((hx==hy)&&(lx>ly))) { /* x > y, x -= ulp */ if(lx==0) hx -= 1; lx -= 1; } else { /* x < y, x += ulp */ lx += 1; if(lx==0) hx += 1; } } else { /* x < 0 */ if(hy>=0||hx>hy||((hx==hy)&&(lx>ly))) { /* x < y, x -= ulp */ if(lx==0) hx -= 1; lx -= 1; } else { /* x > y, x += ulp */ lx += 1; if(lx==0) hx += 1; } } hy = hx&0x7ff00000; if(hy>=0x7ff00000) return x+x; /* overflow */ if(hy<0x00100000) { /* underflow */ y = x*x; if(y!=x) { /* raise underflow flag */ __HI(y) = hx; __LO(y) = lx; return y; } } __HI(x) = hx; __LO(x) = lx; return x; }
double pow (double x, double y) { double z, ax, z_h, z_l, p_h, p_l; double y1, t1, t2, r, s, t, u, v, w; int i, j, k, yisint, n; int hx, hy, ix, iy; unsigned lx, ly; hx = __HI (x); lx = __LO (x); hy = __HI (y); ly = __LO (y); ix = hx & 0x7fffffff; iy = hy & 0x7fffffff; /* y == zero: x**0 = 1 */ if ((iy | ly) == 0) { return one; } /* +-NaN return x + y */ if (ix > 0x7ff00000 || ((ix == 0x7ff00000) && (lx != 0)) || iy > 0x7ff00000 || ((iy == 0x7ff00000) && (ly != 0))) { return x + y; } /* determine if y is an odd int when x < 0 * yisint = 0 ... y is not an integer * yisint = 1 ... y is an odd int * yisint = 2 ... y is an even int */ yisint = 0; if (hx < 0) { if (iy >= 0x43400000) /* even integer y */ { yisint = 2; } else if (iy >= 0x3ff00000) { k = (iy >> 20) - 0x3ff; /* exponent */ if (k > 20) { j = ly >> (52 - k); if ((j << (52 - k)) == ly) { yisint = 2 - (j & 1); } } else if (ly == 0)
double __ieee754_log(double x) { double hfsq,f,s,z,R,w,t1,t2,dk; int k,hx,i,j; unsigned lx; hx = __HI(x); /* high word of x */ lx = __LO(x); /* low word of x */ k=0; if (hx < 0x00100000) { /* x < 2**-1022 */ if (((hx&0x7fffffff)|lx)==0) return -two54/zero; /* log(+-0)=-inf */ if (hx<0) return (x-x)/zero; /* log(-#) = NaN */ k -= 54; x *= two54; /* subnormal number, scale up x */ hx = __HI(x); /* high word of x */ } if (hx >= 0x7ff00000) return x+x; k += (hx>>20)-1023; hx &= 0x000fffff; i = (hx+0x95f64)&0x100000; __HI(x) = hx|(i^0x3ff00000); /* normalize x or x/2 */ k += (i>>20); f = x-1.0; if((0x000fffff&(2+hx))<3) { /* |f| < 2**-20 */ if(f==zero) if(k==0) return zero; else {dk=(double)k; return dk*ln2_hi+dk*ln2_lo;} R = f*f*(0.5-0.33333333333333333*f); if(k==0) return f-R; else {dk=(double)k; return dk*ln2_hi-((R-dk*ln2_lo)-f);} } s = f/(2.0+f); dk = (double)k; z = s*s; i = hx-0x6147a; w = z*z; j = 0x6b851-hx; t1= w*(Lg2+w*(Lg4+w*Lg6)); t2= z*(Lg1+w*(Lg3+w*(Lg5+w*Lg7))); i |= j; R = t2+t1; if(i>0) { hfsq=0.5*f*f; if(k==0) return f-(hfsq-s*(hfsq+R)); else return dk*ln2_hi-((hfsq-(s*(hfsq+R)+dk*ln2_lo))-f); } else { if(k==0) return f-s*(f-R); else return dk*ln2_hi-((s*(f-R)-dk*ln2_lo)-f); } }
double JFP_lib_sin(double x) { double y[2]; int n, ix; /* High word of x. */ ix = __HI(x); /* |x| ~< pi/4 */ ix &= 0x7fffffff; if(ix <= 0x3fe921fb) return __kernel_sin(x,0,0); /* sin(Inf or NaN) is NaN */ else if (ix>=0x7ff00000) return x-x; /* argument reduction needed */ else { n = __ieee754_rem_pio2(x,y); switch(n&3) { case 0: return __kernel_sin(y[0],y[1],1); case 1: return __kernel_cos(y[0],y[1]); case 2: return -__kernel_sin(y[0],y[1],1); default: return -__kernel_cos(y[0],y[1]); } } }
double acos (double x) { double z, p, q, r, w, s, c, df; int hx, ix; hx = __HI (x); ix = hx & 0x7fffffff; if (ix >= 0x3ff00000) /* |x| >= 1 */ { if (((ix - 0x3ff00000) | __LO (x)) == 0) /* |x| == 1 */ { if (hx > 0) /* acos(1) = 0 */ { return 0.0; } else /* acos(-1) = pi */ { return pi + 2.0 * pio2_lo; } } return (x - x) / (x - x); /* acos(|x|>1) is NaN */ } if (ix < 0x3fe00000) /* |x| < 0.5 */ { if (ix <= 0x3c600000) /* if |x| < 2**-57 */ { return pio2_hi + pio2_lo; } z = x * x; p = z * (pS0 + z * (pS1 + z * (pS2 + z * (pS3 + z * (pS4 + z * pS5))))); q = one + z * (qS1 + z * (qS2 + z * (qS3 + z * qS4))); r = p / q; return pio2_hi - (x - (pio2_lo - x * r)); } else if (hx < 0) /* x < -0.5 */ { z = (one + x) * 0.5; p = z * (pS0 + z * (pS1 + z * (pS2 + z * (pS3 + z * (pS4 + z * pS5))))); q = one + z * (qS1 + z * (qS2 + z * (qS3 + z * qS4))); s = sqrt (z); r = p / q; w = r * s - pio2_lo; return pi - 2.0 * (s + w); } else /* x > 0.5 */ { z = (one - x) * 0.5; s = sqrt (z); df = s; __LO (df) = 0; c = (z - df * df) / (s + df); p = z * (pS0 + z * (pS1 + z * (pS2 + z * (pS3 + z * (pS4 + z * pS5))))); q = one + z * (qS1 + z * (qS2 + z * (qS3 + z * qS4))); r = p / q; w = r * s + c; return 2.0 * (df + w); } } /* acos */
int finite (double x) { int hx; hx = __HI (x); return (unsigned) ((hx & 0x7fffffff) - 0x7ff00000) >> 31; } /* finite */
int isnan(double x) { int hx,lx; hx = (__HI(x)&0x7fffffff); lx = __LO(x); hx |= (unsigned)(lx|(-lx))>>31; hx = 0x7ff00000 - hx; return ((unsigned)(hx))>>31; }
double __ieee754_y0(double x) { double z, s,c,ss,cc,u,v; int hx,ix,lx; hx = __HI(x); ix = 0x7fffffff&hx; lx = __LO(x); /* Y0(NaN) is NaN, y0(-inf) is Nan, y0(inf) is 0 */ if(ix>=0x7ff00000) return one/(x+x*x); if((ix|lx)==0) return -one/zero; if(hx<0) return zero/zero; if(ix >= 0x40000000) { /* |x| >= 2.0 */ /* y0(x) = sqrt(2/(pi*x))*(p0(x)*sin(x0)+q0(x)*cos(x0)) * where x0 = x-pi/4 * Better formula: * cos(x0) = cos(x)cos(pi/4)+sin(x)sin(pi/4) * = 1/sqrt(2) * (sin(x) + cos(x)) * sin(x0) = sin(x)cos(3pi/4)-cos(x)sin(3pi/4) * = 1/sqrt(2) * (sin(x) - cos(x)) * To avoid cancellation, use * sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x)) * to compute the worse one. */ s = sin(x); c = cos(x); ss = s-c; cc = s+c; /* * j0(x) = 1/sqrt(pi) * (P(0,x)*cc - Q(0,x)*ss) / sqrt(x) * y0(x) = 1/sqrt(pi) * (P(0,x)*ss + Q(0,x)*cc) / sqrt(x) */ if(ix<0x7fe00000) { /* make sure x+x not overflow */ z = -cos(x+x); if ((s*c)<zero) cc = z/ss; else ss = z/cc; } if(ix>0x48000000) z = (invsqrtpi*ss)/sqrt(x); else { u = pzero(x); v = qzero(x); z = invsqrtpi*(u*ss+v*cc)/sqrt(x); } return z; } if(ix<=0x3e400000) { /* x < 2**-27 */ return(u00 + tpi*__ieee754_log(x)); } z = x*x; u = u00+z*(u01+z*(u02+z*(u03+z*(u04+z*(u05+z*u06))))); v = one+z*(v01+z*(v02+z*(v03+z*v04))); return(u/v + tpi*(__ieee754_j0(x)*__ieee754_log(x))); }
double __kernel_cos(double x, double y) { double a,hz,z,r,qx; int ix; ix = __HI(x)&0x7fffffff; /* ix = |x|'s high word*/ if(ix<0x3e400000) { /* if x < 2**27 */ if(((int)x)==0) return one; /* generate inexact */ } z = x*x; r = z*(C1+z*(C2+z*(C3+z*(C4+z*(C5+z*C6))))); if(ix < 0x3FD33333) /* if |x| < 0.3 */ return one - (0.5*z - (z*r - x*y)); else { if(ix > 0x3fe90000) { /* x > 0.78125 */ qx = 0.28125; } else { __HI(qx) = ix-0x00200000; /* x/4 */ __LO(qx) = 0; } hz = 0.5*z-qx; a = one-qx; return a - (hz - (z*r-x*y)); } }
static double qzero(double x) { const double *p,*q; double s,r,z; int ix; ix = 0x7fffffff&__HI(x); if(ix>=0x40200000) {p = qR8; q= qS8;} else if(ix>=0x40122E8B){p = qR5; q= qS5;} else if(ix>=0x4006DB6D){p = qR3; q= qS3;} else if(ix>=0x40000000){p = qR2; q= qS2;} z = one/(x*x); r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5])))); s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*(q[4]+z*q[5]))))); return (-.125 + r/s)/x; }
static double pzero(double x) { const double *p,*q; double z,r,s; int ix; ix = 0x7fffffff&__HI(x); if(ix>=0x40200000) {p = pR8; q= pS8;} else if(ix>=0x40122E8B){p = pR5; q= pS5;} else if(ix>=0x4006DB6D){p = pR3; q= pS3;} else if(ix>=0x40000000){p = pR2; q= pS2;} z = one/(x*x); r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5])))); s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*q[4])))); return one+ r/s; }
static double qone(double x) { const double *p,*q; double s,r,z; int ix; ix = 0x7fffffff&__HI(x); if(ix>=0x40200000) {p = qr8; q= qs8;} else if(ix>=0x40122E8B){p = qr5; q= qs5;} else if(ix>=0x4006DB6D){p = qr3; q= qs3;} else if(ix>=0x40000000){p = qr2; q= qs2;} z = one/(x*x); r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5])))); s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*(q[4]+z*q[5]))))); return (.375 + r/s)/x; }
static double pone(double x) { const double *p,*q; double z,r,s; int ix; ix = 0x7fffffff&__HI(x); if(ix>=0x40200000) {p = pr8; q= ps8;} else if(ix>=0x40122E8B){p = pr5; q= ps5;} else if(ix>=0x4006DB6D){p = pr3; q= ps3;} else if(ix>=0x40000000){p = pr2; q= ps2;} z = one/(x*x); r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5])))); s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*q[4])))); return one+ r/s; }
double __ieee754_y1(double x) { double z, s,c,ss,cc,u,v; int hx,ix,lx; hx = __HI(x); ix = 0x7fffffff&hx; lx = __LO(x); /* if Y1(NaN) is NaN, Y1(-inf) is NaN, Y1(inf) is 0 */ if(ix>=0x7ff00000) return one/(x+x*x); if((ix|lx)==0) return -one/zero; if(hx<0) return zero/zero; if(ix >= 0x40000000) { /* |x| >= 2.0 */ s = sin(x); c = cos(x); ss = -s-c; cc = s-c; if(ix<0x7fe00000) { /* make sure x+x not overflow */ z = cos(x+x); if ((s*c)>zero) cc = z/ss; else ss = z/cc; } /* y1(x) = sqrt(2/(pi*x))*(p1(x)*sin(x0)+q1(x)*cos(x0)) * where x0 = x-3pi/4 * Better formula: * cos(x0) = cos(x)cos(3pi/4)+sin(x)sin(3pi/4) * = 1/sqrt(2) * (sin(x) - cos(x)) * sin(x0) = sin(x)cos(3pi/4)-cos(x)sin(3pi/4) * = -1/sqrt(2) * (cos(x) + sin(x)) * To avoid cancellation, use * sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x)) * to compute the worse one. */ if(ix>0x48000000) z = (invsqrtpi*ss)/sqrt(x); else { u = pone(x); v = qone(x); z = invsqrtpi*(u*ss+v*cc)/sqrt(x); } return z; } if(ix<=0x3c900000) { /* x < 2**-54 */ return(-tpi/x); } z = x*x; u = U0[0]+z*(U0[1]+z*(U0[2]+z*(U0[3]+z*U0[4]))); v = one+z*(V0[0]+z*(V0[1]+z*(V0[2]+z*(V0[3]+z*V0[4])))); return(x*(u/v) + tpi*(__ieee754_j1(x)*__ieee754_log(x)-one/x)); }
double __kernel_sin(double x, double y, int iy) { double z,r,v; int ix; ix = __HI(x)&0x7fffffff; /* high word of x */ if(ix<0x3e400000) /* |x| < 2**-27 */ {if((int)x==0) return x;} /* generate inexact */ z = x*x; v = z*x; #ifdef higher_degree r = S2+z*(S3+z*(S4+z*(S5+z*(S6+z*(S7+z*(S8+z*(S9+z*(S10+z*(S11+z*S12))))))))); #else r = S2+z*(S3+z*(S4+z*(S5+z*S6))); #endif if(iy==0) return x+v*(S1+z*r); else return x-((z*(half*y-v*r)-y)-v*S1); }
double __ieee754_j0(double x) { double z, s,c,ss,cc,r,u,v; int hx,ix; hx = __HI(x); ix = hx&0x7fffffff; if(ix>=0x7ff00000) return one/(x*x); x = fabs(x); if(ix >= 0x40000000) { /* |x| >= 2.0 */ s = sin(x); c = cos(x); ss = s-c; cc = s+c; if(ix<0x7fe00000) { /* make sure x+x not overflow */ z = -cos(x+x); if ((s*c)<zero) cc = z/ss; else ss = z/cc; } /* * j0(x) = 1/sqrt(pi) * (P(0,x)*cc - Q(0,x)*ss) / sqrt(x) * y0(x) = 1/sqrt(pi) * (P(0,x)*ss + Q(0,x)*cc) / sqrt(x) */ if(ix>0x48000000) z = (invsqrtpi*cc)/sqrt(x); else { u = pzero(x); v = qzero(x); z = invsqrtpi*(u*cc-v*ss)/sqrt(x); } return z; } if(ix<0x3f200000) { /* |x| < 2**-13 */ if(Huge+x>one) { /* raise inexact if x != 0 */ if(ix<0x3e400000) return one; /* |x|<2**-27 */ else return one - 0.25*x*x; } } z = x*x; r = z*(R02+z*(R03+z*(R04+z*R05))); s = one+z*(S01+z*(S02+z*(S03+z*S04))); if(ix < 0x3FF00000) { /* |x| < 1.00 */ return one + z*(-0.25+(r/s)); } else { u = 0.5*x; return((one+u)*(one-u)+z*(r/s)); } }
int ilogb(double x) { int hx,lx,ix; hx = (__HI(x))&0x7fffffff; /* high word of x */ if(hx<0x00100000) { lx = __LO(x); if((hx|lx)==0) return 0x80000001; /* ilogb(0) = 0x80000001 */ else /* subnormal x */ if(hx==0) { for (ix = -1043; lx>0; lx<<=1) ix -=1; } else { for (ix = -1022,hx<<=11; hx>0; hx<<=1) ix -=1; } return ix; } else if (hx<0x7ff00000) return (hx>>20)-1023; else return 0x7fffffff;
double asin(double x) { double t=0.0,w=0.0,p=0.0,q=0.0,c=0.0,r=0.0,s=0.0; int hx=0,ix=0; hx = __HI(x); ix = hx&0x7fffffff; if(ix>= 0x3ff00000) { /* |x|>= 1 */ if(((ix-0x3ff00000)|__LO(x))==0) /* asin(1)=+-pi/2 with inexact */ return x*pio2_hi+x*pio2_lo; return (x-x)/(x-x); /* asin(|x|>1) is NaN */ } else if (ix<0x3fe00000) { /* |x|<0.5 */ if(ix<0x3e400000) { /* if |x| < 2**-27 */ if(huge+x>one) return x;/* return x with inexact if x!=0*/ } else t = x*x; p = t*(pS0+t*(pS1+t*(pS2+t*(pS3+t*(pS4+t*pS5))))); q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4))); w = p/q; return x+x*w; } /* 1> |x|>= 0.5 */ w = one-fabs(x); t = w*0.5; p = t*(pS0+t*(pS1+t*(pS2+t*(pS3+t*(pS4+t*pS5))))); q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4))); s = sqrt(t); if(ix>=0x3FEF3333) { /* if |x| > 0.975 */ w = p/q; t = pio2_hi-(2.0*(s+s*w)-pio2_lo); } else { w = s; __LO(w) = 0; c = (t-w*w)/(s+w); r = p/q; p = 2.0*s*r-(pio2_lo-2.0*c); q = pio4_hi-2.0*w; t = pio4_hi-(p-q); } if(hx>0) return t; else return -t; }
double asinh(double x) { double t,w; int hx,ix; hx = __HI(x); ix = hx&0x7fffffff; if(ix>=0x7ff00000) return x+x; /* x is inf or NaN */ if(ix< 0x3e300000) { /* |x|<2**-28 */ if(Huge+x>one) return x; /* return x inexact except 0 */ } if(ix>0x41b00000) { /* |x| > 2**28 */ w = __ieee754_log(fabs(x))+ln2; } else if (ix>0x40000000) { /* 2**28 > |x| > 2.0 */ t = fabs(x); w = __ieee754_log(2.0*t+one/(sqrt(x*x+one)+t)); } else { /* 2.0 > |x| > 2**-28 */ t = x*x; w =log1p(fabs(x)+t/(one+sqrt(one+t))); } if(hx>0) return w; else return -w; }
double JFP_lib_tan(double x) { double y[2],z=0.0; int n, ix; /* High word of x. */ ix = __HI(x); /* |x| ~< pi/4 */ ix &= 0x7fffffff; if(ix <= 0x3fe921fb) return __kernel_tan(x,z,1); /* tan(Inf or NaN) is NaN */ else if (ix>=0x7ff00000) return x-x; /* NaN */ /* argument reduction needed */ else { n = __ieee754_rem_pio2(x,y); return __kernel_tan(y[0],y[1],1-((n&1)<<1)); /* 1 -- n even -1 -- n odd */ } }
double __ieee754_j1(double x) { double z, s,c,ss,cc,r,u,v,y; int hx,ix; hx = __HI(x); ix = hx&0x7fffffff; if(ix>=0x7ff00000) return one/x; y = fabs(x); if(ix >= 0x40000000) { /* |x| >= 2.0 */ s = sin(y); c = cos(y); ss = -s-c; cc = s-c; if(ix<0x7fe00000) { /* make sure y+y not overflow */ z = cos(y+y); if ((s*c)>zero) cc = z/ss; else ss = z/cc; } /* * j1(x) = 1/sqrt(pi) * (P(1,x)*cc - Q(1,x)*ss) / sqrt(x) * y1(x) = 1/sqrt(pi) * (P(1,x)*ss + Q(1,x)*cc) / sqrt(x) */ if(ix>0x48000000) z = (invsqrtpi*cc)/sqrt(y); else { u = pone(y); v = qone(y); z = invsqrtpi*(u*cc-v*ss)/sqrt(y); } if(hx<0) return -z; else return z; } if(ix<0x3e400000) { /* |x|<2**-27 */ if(huge+x>one) return 0.5*x;/* inexact if x!=0 necessary */ } z = x*x; r = z*(r00+z*(r01+z*(r02+z*r03))); s = one+z*(s01+z*(s02+z*(s03+z*(s04+z*s05)))); r *= x; return(x*0.5+r/s); }
double __ieee754_acosh(double x) { double t; int hx; hx = __HI(x); if(hx<0x3ff00000) { /* x < 1 */ return (x-x)/(x-x); } else if(hx >=0x41b00000) { /* x > 2**28 */ if(hx >=0x7ff00000) { /* x is inf of NaN */ return x+x; } else return __ieee754_log(x)+ln2; /* acosh(Huge)=log(2x) */ } else if(((hx-0x3ff00000)|__LO(x))==0) { return 0.0; /* acosh(1) = 0 */ } else if (hx > 0x40000000) { /* 2**28 > x > 2 */ t=x*x; return __ieee754_log(2.0*x-one/(x+sqrt(t-one))); } else { /* 1<x<2 */ t = x-one; return log1p(t+sqrt(2.0*t+t*t)); } }
double __ieee754_hypot(double x, double y) { double a=x,b=y,t1,t2,y1,y2,w; int j,k,ha,hb; ha = __HI(x)&0x7fffffff; /* high word of x */ hb = __HI(y)&0x7fffffff; /* high word of y */ if(hb > ha) {a=y;b=x;j=ha; ha=hb;hb=j;} else {a=x;b=y;} __HI(a) = ha; /* a <- |a| */ __HI(b) = hb; /* b <- |b| */ if((ha-hb)>0x3c00000) {return a+b;} /* x/y > 2**60 */ k=0; if(ha > 0x5f300000) { /* a>2**500 */ if(ha >= 0x7ff00000) { /* Inf or NaN */ w = a+b; /* for sNaN */ if(((ha&0xfffff)|__LO(a))==0) w = a; if(((hb^0x7ff00000)|__LO(b))==0) w = b; return w; } /* scale a and b by 2**-600 */ ha -= 0x25800000; hb -= 0x25800000; k += 600; __HI(a) = ha; __HI(b) = hb; } if(hb < 0x20b00000) { /* b < 2**-500 */ if(hb <= 0x000fffff) { /* subnormal b or 0 */ if((hb|(__LO(b)))==0) return a; t1=0; __HI(t1) = 0x7fd00000; /* t1=2^1022 */ b *= t1; a *= t1; k -= 1022; } else { /* scale a and b by 2^600 */ ha += 0x25800000; /* a *= 2^600 */ hb += 0x25800000; /* b *= 2^600 */ k -= 600; __HI(a) = ha; __HI(b) = hb; } } /* medium size a and b */ w = a-b; if (w>b) { t1 = 0; __HI(t1) = ha; t2 = a-t1; w = sqrt(t1*t1-(b*(-b)-t2*(a+t1))); } else { a = a+a; y1 = 0; __HI(y1) = hb; y2 = b - y1; t1 = 0; __HI(t1) = ha+0x00100000; t2 = a - t1; w = sqrt(t1*y1-(w*(-w)-(t1*y2+t2*b))); } if(k!=0) { t1 = 1.0; __HI(t1) += (k<<20); return t1*w; } else return w; }
double copysign(double x, double y) { __HI(x) = (__HI(x)&0x7fffffff)|(__HI(y)&0x80000000); return x; }
double JFP_lib_fabs(double x) { __HI(x) &= 0x7fffffff; return x; }
double _SVID_libm_err(double x, double y, int type) { struct exception exc; double t, w, ieee_retval; enum version lib_version = _lib_version; int iy; /* force libm_ieee behavior in SUSv3 mode */ if ((__xpg6 & _C99SUSv3_math_errexcept) != 0) lib_version = libm_ieee; if (lib_version == c_issue_4) { (void) fflush(stdout); } exc.arg1 = x; exc.arg2 = y; switch (type) { case 1: /* acos(|x|>1) */ exc.type = DOMAIN; exc.name = "acos"; ieee_retval = setexception(3, 1.0); exc.retval = 0.0; if (lib_version == strict_ansi) { errno = EDOM; } else if (!matherr(&exc)) { if (lib_version == c_issue_4) { (void) write(2, "acos: DOMAIN error\n", 19); } errno = EDOM; } break; case 2: /* asin(|x|>1) */ exc.type = DOMAIN; exc.name = "asin"; exc.retval = 0.0; ieee_retval = setexception(3, 1.0); if (lib_version == strict_ansi) { errno = EDOM; } else if (!matherr(&exc)) { if (lib_version == c_issue_4) { (void) write(2, "asin: DOMAIN error\n", 19); } errno = EDOM; } break; case 3: /* atan2(+-0,+-0) */ exc.arg1 = y; exc.arg2 = x; exc.type = DOMAIN; exc.name = "atan2"; ieee_retval = copysign(1.0, x) == 1.0 ? y : copysign(PI_RZ + DBL_MIN, y); exc.retval = 0.0; if (lib_version == strict_ansi) { errno = EDOM; } else if (!matherr(&exc)) { if (lib_version == c_issue_4) { (void) write(2, "atan2: DOMAIN error\n", 20); } errno = EDOM; } break; case 4: /* hypot(finite,finite) overflow */ exc.type = OVERFLOW; exc.name = "hypot"; ieee_retval = Inf; if (lib_version == c_issue_4) exc.retval = HUGE; else exc.retval = HUGE_VAL; if (lib_version == strict_ansi) errno = ERANGE; else if (!matherr(&exc)) errno = ERANGE; break; case 5: /* cosh(finite) overflow */ exc.type = OVERFLOW; exc.name = "cosh"; ieee_retval = setexception(2, 1.0); if (lib_version == c_issue_4) exc.retval = HUGE; else exc.retval = HUGE_VAL; if (lib_version == strict_ansi) errno = ERANGE; else if (!matherr(&exc)) errno = ERANGE; break; case 6: /* exp(finite) overflow */ exc.type = OVERFLOW; exc.name = "exp"; ieee_retval = setexception(2, 1.0); if (lib_version == c_issue_4) exc.retval = HUGE; else exc.retval = HUGE_VAL; if (lib_version == strict_ansi) errno = ERANGE; else if (!matherr(&exc)) errno = ERANGE; break; case 7: /* exp(finite) underflow */ exc.type = UNDERFLOW; exc.name = "exp"; ieee_retval = setexception(1, 1.0); exc.retval = 0.0; if (lib_version == strict_ansi) errno = ERANGE; else if (!matherr(&exc)) errno = ERANGE; break; case 8: /* y0(0) = -inf */ exc.type = DOMAIN; /* should be SING for IEEE */ exc.name = "y0"; ieee_retval = setexception(0, -1.0); if (lib_version == c_issue_4) exc.retval = -HUGE; else exc.retval = -HUGE_VAL; if (lib_version == strict_ansi) { errno = EDOM; } else if (!matherr(&exc)) { if (lib_version == c_issue_4) { (void) write(2, "y0: DOMAIN error\n", 17); } errno = EDOM; } break; case 9: /* y0(x<0) = NaN */ exc.type = DOMAIN; exc.name = "y0"; ieee_retval = setexception(3, 1.0); if (lib_version == c_issue_4) exc.retval = -HUGE; else exc.retval = -HUGE_VAL; if (lib_version == strict_ansi) { errno = EDOM; } else if (!matherr(&exc)) { if (lib_version == c_issue_4) { (void) write(2, "y0: DOMAIN error\n", 17); } errno = EDOM; } break; case 10: /* y1(0) = -inf */ exc.type = DOMAIN; /* should be SING for IEEE */ exc.name = "y1"; ieee_retval = setexception(0, -1.0); if (lib_version == c_issue_4) exc.retval = -HUGE; else exc.retval = -HUGE_VAL; if (lib_version == strict_ansi) { errno = EDOM; } else if (!matherr(&exc)) { if (lib_version == c_issue_4) { (void) write(2, "y1: DOMAIN error\n", 17); } errno = EDOM; } break; case 11: /* y1(x<0) = NaN */ exc.type = DOMAIN; exc.name = "y1"; ieee_retval = setexception(3, 1.0); if (lib_version == c_issue_4) exc.retval = -HUGE; else exc.retval = -HUGE_VAL; if (lib_version == strict_ansi) { errno = EDOM; } else if (!matherr(&exc)) { if (lib_version == c_issue_4) { (void) write(2, "y1: DOMAIN error\n", 17); } errno = EDOM; } break; case 12: /* yn(n,0) = -inf */ exc.type = DOMAIN; /* should be SING for IEEE */ exc.name = "yn"; ieee_retval = setexception(0, -1.0); if (lib_version == c_issue_4) exc.retval = -HUGE; else exc.retval = -HUGE_VAL; if (lib_version == strict_ansi) { errno = EDOM; } else if (!matherr(&exc)) { if (lib_version == c_issue_4) { (void) write(2, "yn: DOMAIN error\n", 17); } errno = EDOM; } break; case 13: /* yn(x<0) = NaN */ exc.type = DOMAIN; exc.name = "yn"; ieee_retval = setexception(3, 1.0); if (lib_version == c_issue_4) exc.retval = -HUGE; else exc.retval = -HUGE_VAL; if (lib_version == strict_ansi) { errno = EDOM; } else if (!matherr(&exc)) { if (lib_version == c_issue_4) { (void) write(2, "yn: DOMAIN error\n", 17); } errno = EDOM; } break; case 14: /* lgamma(finite) overflow */ exc.type = OVERFLOW; exc.name = "lgamma"; ieee_retval = setexception(2, 1.0); if (lib_version == c_issue_4) exc.retval = HUGE; else exc.retval = HUGE_VAL; if (lib_version == strict_ansi) errno = ERANGE; else if (!matherr(&exc)) errno = ERANGE; break; case 15: /* lgamma(-integer) or lgamma(0) */ exc.type = SING; exc.name = "lgamma"; ieee_retval = setexception(0, 1.0); if (lib_version == c_issue_4) exc.retval = HUGE; else exc.retval = HUGE_VAL; if (lib_version == strict_ansi) { errno = EDOM; } else if (!matherr(&exc)) { if (lib_version == c_issue_4) { (void) write(2, "lgamma: SING error\n", 19); } errno = EDOM; } break; case 16: /* log(0) */ exc.type = SING; exc.name = "log"; ieee_retval = setexception(0, -1.0); if (lib_version == c_issue_4) exc.retval = -HUGE; else exc.retval = -HUGE_VAL; if (lib_version == strict_ansi) { errno = ERANGE; } else if (!matherr(&exc)) { if (lib_version == c_issue_4) { (void) write(2, "log: SING error\n", 16); errno = EDOM; } else { errno = ERANGE; } } break; case 17: /* log(x<0) */ exc.type = DOMAIN; exc.name = "log"; ieee_retval = setexception(3, 1.0); if (lib_version == c_issue_4) exc.retval = -HUGE; else exc.retval = -HUGE_VAL; if (lib_version == strict_ansi) { errno = EDOM; } else if (!matherr(&exc)) { if (lib_version == c_issue_4) { (void) write(2, "log: DOMAIN error\n", 18); } errno = EDOM; } break; case 18: /* log10(0) */ exc.type = SING; exc.name = "log10"; ieee_retval = setexception(0, -1.0); if (lib_version == c_issue_4) exc.retval = -HUGE; else exc.retval = -HUGE_VAL; if (lib_version == strict_ansi) { errno = ERANGE; } else if (!matherr(&exc)) { if (lib_version == c_issue_4) { (void) write(2, "log10: SING error\n", 18); errno = EDOM; } else { errno = ERANGE; } } break; case 19: /* log10(x<0) */ exc.type = DOMAIN; exc.name = "log10"; ieee_retval = setexception(3, 1.0); if (lib_version == c_issue_4) exc.retval = -HUGE; else exc.retval = -HUGE_VAL; if (lib_version == strict_ansi) { errno = EDOM; } else if (!matherr(&exc)) { if (lib_version == c_issue_4) { (void) write(2, "log10: DOMAIN error\n", 20); } errno = EDOM; } break; case 20: /* pow(0.0,0.0) */ /* error only if lib_version == c_issue_4 */ exc.type = DOMAIN; exc.name = "pow"; exc.retval = 0.0; ieee_retval = 1.0; if (lib_version != c_issue_4) { exc.retval = 1.0; } else if (!matherr(&exc)) { (void) write(2, "pow(0,0): DOMAIN error\n", 23); errno = EDOM; } break; case 21: /* pow(x,y) overflow */ exc.type = OVERFLOW; exc.name = "pow"; exc.retval = (lib_version == c_issue_4)? HUGE : HUGE_VAL; if (signbit(x)) { t = rint(y); if (t == y) { w = rint(0.5 * y); if (t != w + w) { /* y is odd */ exc.retval = -exc.retval; } } } ieee_retval = setexception(2, exc.retval); if (lib_version == strict_ansi) errno = ERANGE; else if (!matherr(&exc)) errno = ERANGE; break; case 22: /* pow(x,y) underflow */ exc.type = UNDERFLOW; exc.name = "pow"; exc.retval = 0.0; if (signbit(x)) { t = rint(y); if (t == y) { w = rint(0.5 * y); if (t != w + w) /* y is odd */ exc.retval = -exc.retval; } } ieee_retval = setexception(1, exc.retval); if (lib_version == strict_ansi) errno = ERANGE; else if (!matherr(&exc)) errno = ERANGE; break; case 23: /* (+-0)**neg */ exc.type = DOMAIN; exc.name = "pow"; ieee_retval = setexception(0, 1.0); { int ahy, k, j, yisint, ly, hx; /* INDENT OFF */ /* * determine if y is an odd int when x = -0 * yisint = 0 ... y is not an integer * yisint = 1 ... y is an odd int * yisint = 2 ... y is an even int */ /* INDENT ON */ hx = __HI(x); ahy = __HI(y)&0x7fffffff; ly = __LO(y); yisint = 0; if (ahy >= 0x43400000) { yisint = 2; /* even integer y */ } else if (ahy >= 0x3ff00000) { k = (ahy >> 20) - 0x3ff; /* exponent */ if (k > 20) { j = ly >> (52 - k); if ((j << (52 - k)) == ly) yisint = 2 - (j & 1); } else if (ly == 0) { j = ahy >> (20 - k); if ((j << (20 - k)) == ahy) yisint = 2 - (j & 1); }
double atan (double x) { double w, s1, s2, z; int ix, hx, id; hx = __HI (x); ix = hx & 0x7fffffff; if (ix >= 0x44100000) /* if |x| >= 2^66 */ { if (ix > 0x7ff00000 || (ix == 0x7ff00000 && (__LO (x) != 0))) { return x + x; /* NaN */ } if (hx > 0) { return atanhi[3] + atanlo[3]; } else { return -atanhi[3] - atanlo[3]; } } if (ix < 0x3fdc0000) /* |x| < 0.4375 */ { if (ix < 0x3e200000) /* |x| < 2^-29 */ { if (huge + x > one) /* raise inexact */ { return x; } } id = -1; } else { x = fabs (x); if (ix < 0x3ff30000) /* |x| < 1.1875 */ { if (ix < 0x3fe60000) /* 7/16 <= |x| < 11/16 */ { id = 0; x = (2.0 * x - one) / (2.0 + x); } else /* 11/16 <= |x| < 19/16 */ { id = 1; x = (x - one) / (x + one); } } else { if (ix < 0x40038000) /* |x| < 2.4375 */ { id = 2; x = (x - 1.5) / (one + 1.5 * x); } else /* 2.4375 <= |x| < 2^66 */ { id = 3; x = -1.0 / x; } } } /* end of argument reduction */ z = x * x; w = z * z; /* break sum from i=0 to 10 aT[i] z**(i+1) into odd and even poly */ s1 = z * (aT0 + w * (aT2 + w * (aT4 + w * (aT6 + w * (aT8 + w * aT10))))); s2 = w * (aT1 + w * (aT3 + w * (aT5 + w * (aT7 + w * aT9)))); if (id < 0) { return x - x * (s1 + s2); } else { z = atanhi[id] - ((x * (s1 + s2) - atanlo[id]) - x); return (hx < 0) ? -z : z; } } /* atan */
double fabs(double x) { __HI(x) &= 0x7fffffff; return x; }