long double __modfl(long double x, long double *iptr) { int32_t i0,i1,j0; u_int32_t i,se; GET_LDOUBLE_WORDS(se,i0,i1,x); j0 = (se&0x7fff)-0x3fff; /* exponent of x */ if(j0<32) { /* integer part in high x */ if(j0<0) { /* |x|<1 */ SET_LDOUBLE_WORDS(*iptr,se&0x8000,0,0); /* *iptr = +-0 */ return x; } else { i = (0x7fffffff)>>j0; if(((i0&i)|i1)==0) { /* x is integral */ *iptr = x; SET_LDOUBLE_WORDS(x,se&0x8000,0,0); /* return +-0 */ return x; } else { SET_LDOUBLE_WORDS(*iptr,se,i0&(~i),0); return x - *iptr; } } } else if (__builtin_expect(j0>63, 0)) { /* no fraction part */
long double __nextafterl(long double x, long double y) { int32_t ix,iy,esx,esy; uint32_t hx,hy,lx,ly; GET_LDOUBLE_WORDS(esx,hx,lx,x); GET_LDOUBLE_WORDS(esy,hy,ly,y); ix = esx&0x7fff; /* |x| */ iy = esy&0x7fff; /* |y| */ if(((ix==0x7fff)&&((hx&0x7fffffff)|lx)!=0) || /* x is nan */ ((iy==0x7fff)&&((hy&0x7fffffff)|ly)!=0)) /* y is nan */ return x+y; if(x==y) return y; /* x=y, return y */ if((ix|hx|lx)==0) { /* x == 0 */ SET_LDOUBLE_WORDS(x,esy&0x8000,0,1);/* return +-minsubnormal */ y = x*x; math_force_eval (y); /* raise underflow flag */ return x; } if(esx>=0) { /* x > 0 */ if(esx>esy||((esx==esy) && (hx>hy||((hx==hy)&&(lx>ly))))) { /* x > y, x -= ulp */ if(lx==0) { if (ix != 0 && hx == 0x80000000) hx = 0; if (hx==0) esx -= 1; hx -= 1; } lx -= 1; } else { /* x < y, x += ulp */ lx += 1; if(lx==0) { hx += 1; if (hx==0) { hx = 0x80000000; esx += 1; } } } } else { /* x < 0 */ if(esy>=0||esx>esy||((esx==esy) && (hx>hy||((hx==hy)&&(lx>ly))))){ /* x < y, x -= ulp */ if(lx==0) { if (ix != 0 && hx == 0x80000000) hx = 0; if (hx==0) esx -= 1; hx -= 1; } lx -= 1; } else { /* x > y, x += ulp */ lx += 1; if(lx==0) { hx += 1; if (hx==0) { hx = 0x80000000; esx += 1; } } } } esy = esx&0x7fff; if(esy==0x7fff) { long double u = x + x; /* overflow */ math_force_eval (u); __set_errno (ERANGE); } if(esy==0 && (hx & 0x80000000) == 0) { /* underflow */ y = x*x; math_force_eval (y); /* raise underflow flag */ __set_errno (ERANGE); } SET_LDOUBLE_WORDS(x,esx,hx,lx); return x; }
long double nextafterl(long double x, long double y) { int32_t hx,hy,ix,iy; u_int32_t lx,ly,esx,esy; GET_LDOUBLE_WORDS(esx,hx,lx,x); GET_LDOUBLE_WORDS(esy,hy,ly,y); ix = esx&0x7fff; /* |x| */ iy = esy&0x7fff; /* |y| */ if (((ix==0x7fff)&&((hx&0x7fffffff|lx)!=0)) || /* x is nan */ ((iy==0x7fff)&&((hy&0x7fffffff|ly)!=0))) /* y is nan */ return x+y; if(x==y) return y; /* x=y, return y */ if((ix|hx|lx)==0) { /* x == 0 */ volatile long double u; SET_LDOUBLE_WORDS(x,esy&0x8000,0,1);/* return +-minsubnormal */ u = x; u = u * u; /* raise underflow flag */ return x; } if(esx<0x8000) { /* x > 0 */ if(ix>iy||((ix==iy) && (hx>hy||((hx==hy)&&(lx>ly))))) { /* x > y, x -= ulp */ if(lx==0) { if ((hx&0x7fffffff)==0) esx -= 1; hx = (hx - 1) | (hx & 0x80000000); } lx -= 1; } else { /* x < y, x += ulp */ lx += 1; if(lx==0) { hx = (hx + 1) | (hx & 0x80000000); if ((hx&0x7fffffff)==0) esx += 1; } } } else { /* x < 0 */ if(esy>=0||(ix>iy||((ix==iy)&&(hx>hy||((hx==hy)&&(lx>ly)))))){ /* x < y, x -= ulp */ if(lx==0) { if ((hx&0x7fffffff)==0) esx -= 1; hx = (hx - 1) | (hx & 0x80000000); } lx -= 1; } else { /* x > y, x += ulp */ lx += 1; if(lx==0) { hx = (hx + 1) | (hx & 0x80000000); if ((hx&0x7fffffff)==0) esx += 1; } } } esy = esx&0x7fff; if(esy==0x7fff) return x+x; /* overflow */ if(esy==0) { volatile long double u = x*x; /* underflow */ if(u==x) { SET_LDOUBLE_WORDS(x,esx,hx,lx); return x; } } SET_LDOUBLE_WORDS(x,esx,hx,lx); return x; }
long double __ieee754_hypotl(long double x, long double y) { long double a,b,t1,t2,y1,y2,w; u_int32_t j,k,ea,eb; GET_LDOUBLE_EXP(ea,x); ea &= 0x7fff; GET_LDOUBLE_EXP(eb,y); eb &= 0x7fff; if(eb > ea) {a=y;b=x;j=ea; ea=eb;eb=j;} else {a=x;b=y;} SET_LDOUBLE_EXP(a,ea); /* a <- |a| */ SET_LDOUBLE_EXP(b,eb); /* b <- |b| */ if((ea-eb)>0x46) {return a+b;} /* x/y > 2**70 */ k=0; if(__builtin_expect(ea > 0x5f3f,0)) { /* a>2**8000 */ if(ea == 0x7fff) { /* Inf or NaN */ u_int32_t exp __attribute__ ((unused)); u_int32_t high,low; w = a+b; /* for sNaN */ GET_LDOUBLE_WORDS(exp,high,low,a); if(((high&0x7fffffff)|low)==0) w = a; GET_LDOUBLE_WORDS(exp,high,low,b); if(((eb^0x7fff)|(high&0x7fffffff)|low)==0) w = b; return w; } /* scale a and b by 2**-9600 */ ea -= 0x2580; eb -= 0x2580; k += 9600; SET_LDOUBLE_EXP(a,ea); SET_LDOUBLE_EXP(b,eb); } if(__builtin_expect(eb < 0x20bf, 0)) { /* b < 2**-8000 */ if(eb == 0) { /* subnormal b or 0 */ u_int32_t exp __attribute__ ((unused)); u_int32_t high,low; GET_LDOUBLE_WORDS(exp,high,low,b); if((high|low)==0) return a; SET_LDOUBLE_WORDS(t1, 0x7ffd, 0x80000000, 0); /* t1=2^16382 */ b *= t1; a *= t1; k -= 16382; GET_LDOUBLE_EXP (ea, a); GET_LDOUBLE_EXP (eb, b); if (eb > ea) { t1 = a; a = b; b = t1; j = ea; ea = eb; eb = j; } } else { /* scale a and b by 2^9600 */ ea += 0x2580; /* a *= 2^9600 */ eb += 0x2580; /* b *= 2^9600 */ k -= 9600; SET_LDOUBLE_EXP(a,ea); SET_LDOUBLE_EXP(b,eb); } } /* medium size a and b */ w = a-b; if (w>b) { u_int32_t high; GET_LDOUBLE_MSW(high,a); SET_LDOUBLE_WORDS(t1,ea,high,0); t2 = a-t1; w = __ieee754_sqrtl(t1*t1-(b*(-b)-t2*(a+t1))); } else { u_int32_t high; GET_LDOUBLE_MSW(high,b); a = a+a; SET_LDOUBLE_WORDS(y1,eb,high,0); y2 = b - y1; GET_LDOUBLE_MSW(high,a); SET_LDOUBLE_WORDS(t1,ea+1,high,0); t2 = a - t1; w = __ieee754_sqrtl(t1*y1-(w*(-w)-(t1*y2+t2*b))); } if(k!=0) { u_int32_t exp; t1 = 1.0; GET_LDOUBLE_EXP(exp,t1); SET_LDOUBLE_EXP(t1,exp+k); w *= t1; math_check_force_underflow_nonneg (w); return w; } else return w; }
long double hypotl(long double x, long double y) { long double a,b,t1,t2,yy1,y2,w; u_int32_t j,k,ea,eb; GET_LDOUBLE_EXP(ea,x); ea &= 0x7fff; GET_LDOUBLE_EXP(eb,y); eb &= 0x7fff; if(eb > ea) {a=y;b=x;j=ea; ea=eb;eb=j;} else {a=x;b=y;} SET_LDOUBLE_EXP(a,ea); /* a <- |a| */ SET_LDOUBLE_EXP(b,eb); /* b <- |b| */ if((ea-eb)>0x46) {return a+b;} /* x/y > 2**70 */ k=0; if(ea > 0x5f3f) { /* a>2**8000 */ if(ea == 0x7fff) { /* Inf or NaN */ u_int32_t es,high,low; w = a+b; /* for sNaN */ GET_LDOUBLE_WORDS(es,high,low,a); if(((high&0x7fffffff)|low)==0) w = a; GET_LDOUBLE_WORDS(es,high,low,b); if(((eb^0x7fff)|(high&0x7fffffff)|low)==0) w = b; return w; } /* scale a and b by 2**-9600 */ ea -= 0x2580; eb -= 0x2580; k += 9600; SET_LDOUBLE_EXP(a,ea); SET_LDOUBLE_EXP(b,eb); } if(eb < 0x20bf) { /* b < 2**-8000 */ if(eb == 0) { /* subnormal b or 0 */ u_int32_t es,high,low; GET_LDOUBLE_WORDS(es,high,low,b); if((high|low)==0) return a; SET_LDOUBLE_WORDS(t1, 0x7ffd, 0, 0); /* t1=2^16382 */ b *= t1; a *= t1; k -= 16382; } else { /* scale a and b by 2^9600 */ ea += 0x2580; /* a *= 2^9600 */ eb += 0x2580; /* b *= 2^9600 */ k -= 9600; SET_LDOUBLE_EXP(a,ea); SET_LDOUBLE_EXP(b,eb); } } /* medium size a and b */ w = a-b; if (w>b) { u_int32_t high; GET_LDOUBLE_MSW(high,a); SET_LDOUBLE_WORDS(t1,ea,high,0); t2 = a-t1; w = sqrtl(t1*t1-(b*(-b)-t2*(a+t1))); } else { u_int32_t high; GET_LDOUBLE_MSW(high,b); a = a+a; SET_LDOUBLE_WORDS(yy1,eb,high,0); y2 = b - yy1; GET_LDOUBLE_MSW(high,a); SET_LDOUBLE_WORDS(t1,ea+1,high,0); t2 = a - t1; w = sqrtl(t1*yy1-(w*(-w)-(t1*y2+t2*b))); } if(k!=0) { u_int32_t es; t1 = 1.0; GET_LDOUBLE_EXP(es,t1); SET_LDOUBLE_EXP(t1,es+k); return t1*w; } else return w; }
long double __roundevenl (long double x) { uint16_t se; uint32_t hx, lx; GET_LDOUBLE_WORDS (se, hx, lx, x); int exponent = se & 0x7fff; if (exponent >= BIAS + MANT_DIG - 1) { /* Integer, infinity or NaN. */ if (exponent == MAX_EXP) /* Infinity or NaN; quiet signaling NaNs. */ return x + x; else return x; } else if (exponent >= BIAS + MANT_DIG - 32) { /* Not necessarily an integer; integer bit is in low word. Locate the bits with exponents 0 and -1. */ int int_pos = (BIAS + MANT_DIG - 1) - exponent; int half_pos = int_pos - 1; uint32_t half_bit = 1U << half_pos; uint32_t int_bit = 1U << int_pos; if ((lx & (int_bit | (half_bit - 1))) != 0) { /* No need to test whether HALF_BIT is set. */ lx += half_bit; if (lx < half_bit) { hx++; if (hx == 0) { hx = 0x80000000; se++; } } } lx &= ~(int_bit - 1); } else if (exponent == BIAS + MANT_DIG - 33) { /* Not necessarily an integer; integer bit is bottom of high word, half bit is top of low word. */ if (((hx & 1) | (lx & 0x7fffffff)) != 0) { lx += 0x80000000; if (lx < 0x80000000) { hx++; if (hx == 0) { hx = 0x80000000; se++; } } } lx = 0; } else if (exponent >= BIAS) { /* At least 1; not necessarily an integer, integer bit and half bit are in the high word. Locate the bits with exponents 0 and -1. */ int int_pos = (BIAS + MANT_DIG - 33) - exponent; int half_pos = int_pos - 1; uint32_t half_bit = 1U << half_pos; uint32_t int_bit = 1U << int_pos; if (((hx & (int_bit | (half_bit - 1))) | lx) != 0) { hx += half_bit; if (hx < half_bit) { hx = 0x80000000; se++; } } hx &= ~(int_bit - 1); lx = 0; } else if (exponent == BIAS - 1 && (hx > 0x80000000 || lx != 0)) { /* Interval (0.5, 1). */ se = (se & 0x8000) | 0x3fff; hx = 0x80000000; lx = 0; } else { /* Rounds to 0. */ se &= 0x8000; hx = 0; lx = 0; } SET_LDOUBLE_WORDS (x, se, hx, lx); return x; }
long double __nextafterl(long double x, long double y) { u_int32_t hx,hy,ix,iy; u_int32_t lx,ly; int32_t esx,esy; GET_LDOUBLE_WORDS(esx,hx,lx,x); GET_LDOUBLE_WORDS(esy,hy,ly,y); ix = esx&0x7fff; /* |x| */ iy = esy&0x7fff; /* |y| */ /* Intel's extended format has the normally implicit 1 explicit present. Sigh! */ if(((ix==0x7fff)&&(((hx&0x7fffffff)|lx)!=0)) || /* x is nan */ ((iy==0x7fff)&&(((hy&0x7fffffff)|ly)!=0))) /* y is nan */ return x+y; if(x==y) return y; /* x=y, return y */ if((ix|hx|lx)==0) { /* x == 0 */ long double u; SET_LDOUBLE_WORDS(x,esy&0x8000,0,1);/* return +-minsubnormal */ u = math_opt_barrier (x); u = u * u; math_force_eval (u); /* raise underflow flag */ return x; } if(esx>=0) { /* x > 0 */ if(esx>esy||((esx==esy) && (hx>hy||((hx==hy)&&(lx>ly))))) { /* x > y, x -= ulp */ if(lx==0) { if (hx <= 0x80000000) { if (esx == 0) { --hx; } else { esx -= 1; hx = hx - 1; if (esx > 0) hx |= 0x80000000; } } else hx -= 1; } lx -= 1; } else { /* x < y, x += ulp */ lx += 1; if(lx==0) { hx += 1; if (hx==0 || (esx == 0 && hx == 0x80000000)) { esx += 1; hx |= 0x80000000; } } } } else { /* x < 0 */ if(esy>=0||(esx>esy||((esx==esy)&&(hx>hy||((hx==hy)&&(lx>ly)))))){ /* x < y, x -= ulp */ if(lx==0) { if (hx <= 0x80000000 && esx != 0xffff8000) { esx -= 1; hx = hx - 1; if ((esx&0x7fff) > 0) hx |= 0x80000000; } else hx -= 1; } lx -= 1; } else { /* x > y, x += ulp */ lx += 1; if(lx==0) { hx += 1; if (hx==0 || (esx == 0xffff8000 && hx == 0x80000000)) { esx += 1; hx |= 0x80000000; } } } } esy = esx&0x7fff; if(esy==0x7fff) { long double u = x + x; /* overflow */ math_force_eval (u); __set_errno (ERANGE); } if(esy==0) { long double u = x*x; /* underflow */ math_force_eval (u); /* raise underflow flag */ __set_errno (ERANGE); } SET_LDOUBLE_WORDS(x,esx,hx,lx); return x; }