invalid_fn (double x, double fn) { if (__rint (fn) != fn) return (fn - fn) / (fn - fn); else if (fn > 65000.0) return __scalbn (x, 65000); else return __scalbn (x,-65000); }
__complex__ double __clog (__complex__ double x) { __complex__ double result; int rcls = fpclassify (__real__ x); int icls = fpclassify (__imag__ x); if (__builtin_expect (rcls == FP_ZERO && icls == FP_ZERO, 0)) { /* Real and imaginary part are 0.0. */ __imag__ result = signbit (__real__ x) ? M_PI : 0.0; __imag__ result = __copysign (__imag__ result, __imag__ x); /* Yes, the following line raises an exception. */ __real__ result = -1.0 / fabs (__real__ x); } else if (__builtin_expect (rcls != FP_NAN && icls != FP_NAN, 1)) { /* Neither real nor imaginary part is NaN. */ double d; int scale = 0; if (fabs (__real__ x) > DBL_MAX / 2.0 || fabs (__imag__ x) > DBL_MAX / 2.0) { scale = -1; __real__ x = __scalbn (__real__ x, scale); __imag__ x = __scalbn (__imag__ x, scale); } else if (fabs (__real__ x) < DBL_MIN && fabs (__imag__ x) < DBL_MIN) { scale = DBL_MANT_DIG; __real__ x = __scalbn (__real__ x, scale); __imag__ x = __scalbn (__imag__ x, scale); } d = __ieee754_hypot (__real__ x, __imag__ x); __real__ result = __ieee754_log (d) - scale * M_LN2; __imag__ result = __ieee754_atan2 (__imag__ x, __real__ x); } else { __imag__ result = __nan (""); if (rcls == FP_INFINITE || icls == FP_INFINITE) /* Real or imaginary part is infinite. */ __real__ result = HUGE_VAL; else __real__ result = __nan (""); } return result; }
double __ldexp(double value, int exp) { if(!isfinite(value)||value==0.0) return value; value = __scalbn(value,exp); if(!isfinite(value)||value==0.0) __set_errno (ERANGE); return value; }
int __kernel_rem_pio2 (double *x, double *y, int e0, int nx, int prec, const int32_t *ipio2) { int32_t jz, jx, jv, jp, jk, carry, n, iq[20], i, j, k, m, q0, ih; double z, fw, f[20], fq[20], q[20]; /* initialize jk*/ jk = init_jk[prec]; jp = jk; /* determine jx,jv,q0, note that 3>q0 */ jx = nx - 1; jv = (e0 - 3) / 24; if (jv < 0) jv = 0; q0 = e0 - 24 * (jv + 1); /* set up f[0] to f[jx+jk] where f[jx+jk] = ipio2[jv+jk] */ j = jv - jx; m = jx + jk; for (i = 0; i <= m; i++, j++) f[i] = (j < 0) ? zero : (double) ipio2[j]; /* compute q[0],q[1],...q[jk] */ for (i = 0; i <= jk; i++) { for (j = 0, fw = 0.0; j <= jx; j++) fw += x[j] * f[jx + i - j]; q[i] = fw; } jz = jk; recompute: /* distill q[] into iq[] reversingly */ for (i = 0, j = jz, z = q[jz]; j > 0; i++, j--) { fw = (double) ((int32_t) (twon24 * z)); iq[i] = (int32_t) (z - two24 * fw); z = q[j - 1] + fw; } /* compute n */ z = __scalbn (z, q0); /* actual value of z */ z -= 8.0 * floor (z * 0.125); /* trim off integer >= 8 */ n = (int32_t) z; z -= (double) n; ih = 0; if (q0 > 0) /* need iq[jz-1] to determine n */ { i = (iq[jz - 1] >> (24 - q0)); n += i; iq[jz - 1] -= i << (24 - q0); ih = iq[jz - 1] >> (23 - q0); }
double __ieee754_scalb (double x, double fn) { if (__glibc_unlikely (isnan (x))) return x * fn; if (__glibc_unlikely (!isfinite (fn))) { if (isnan (fn) || fn > 0.0) return x * fn; if (x == 0.0) return x; return x / -fn; } if (__glibc_unlikely (fabs (fn) >= 0x1p31 || (double) (int) fn != fn)) return invalid_fn (x, fn); return __scalbn (x, (int) fn); }
double jumpto__scalbn(double x, int n) { return __scalbn(x, n); }
Err mathlib_scalbn(UInt16 refnum, double x, Int16 exponent, double *result) { #pragma unused(refnum) *result = __scalbn(x, exponent); return mlErrNone; }
double remquo ( double x, double y, int *quo) { int iclx,icly; /* classify results of x,y */ int32_t iquo; /* low 32 bits of integral quotient */ int32_t iscx, iscy, idiff; /* logb values and difference */ int i; /* loop variable */ double absy,x1,y1,z; /* local floating-point variables */ double rslt; fenv_t OldEnv; hexdouble OldEnvironment; int newexc; FEGETENVD ( OldEnvironment.d ); FESETENVD ( 0.0 ); __NOOP; __NOOP; OldEnv = OldEnvironment.i.lo; *quo = 0; /* initialize quotient result */ iclx = ___fpclassifyd(x); icly = ___fpclassifyd(y); if (likely((iclx & icly) >= FP_NORMAL)) { /* x,y both nonzero finite case */ x1 = __FABS(x); /* work with absolute values */ absy = __FABS(y); iquo = 0; /* zero local quotient */ iscx = (int32_t) __logb(x1); /* get binary exponents */ iscy = (int32_t) __logb(absy); idiff = iscx - iscy; /* exponent difference */ if (idiff >= 0) { /* exponent of x1 >= exponent of y1 */ if (idiff != 0) { /* exponent of x1 > exponent of y1 */ y1 = __scalbn(absy,-iscy); /* scale |y| to unit binade */ x1 = __scalbn(x1,-iscx); /* ditto for |x| */ for (i = idiff; i != 0; i--) { /* begin remainder loop */ if ((z = x1 - y1) >= 0) { /* nonzero remainder step result */ x1 = z; /* update remainder (x1) */ iquo += 1; /* increment quotient */ } iquo += iquo; /* shift quotient left one bit */ x1 += x1; /* shift (double) remainder */ } /* end of remainder loop */ x1 = __scalbn(x1,iscy); /* scale remainder to binade of |y| */ } /* remainder has exponent <= exponent of y */ if (x1 >= absy) { /* last remainder step */ x1 -= absy; iquo +=1; } /* end of last remainder step */ } /* remainder (x1) has smaller exponent than y */ if (likely( x1 < HugeHalved.d )) z = x1 + x1; /* double remainder, without overflow */ else z = Huge.d; if ((z > absy) || ((z == absy) && ((iquo & 1) != 0))) { x1 -= absy; /* final remainder correction */ iquo += 1; } if (x < 0.0) x1 = -x1; /* remainder if x is negative */ iquo &= 0x0000007f; /* retain low 7 bits of integer quotient */ if ((___signbitd(x) ^ ___signbitd(y)) != 0) /* take care of sign of quotient */ iquo = -iquo; *quo = iquo; /* deliver quotient result */ rslt = x1; goto ret; } /* end of x,y both nonzero finite case */ else if ((iclx <= FP_QNAN) || (icly <= FP_QNAN)) { rslt = x+y; /* at least one NaN operand */ goto ret; } else if ((iclx == FP_INFINITE)||(icly == FP_ZERO)) { /* invalid result */ rslt = nan(REM_NAN); OldEnvironment.i.lo |= SET_INVALID; FESETENVD_GRP( OldEnvironment.d ); goto ret; } else /* trivial cases (finite REM infinite */ rslt = x; /* or zero REM nonzero) with *quo = 0 */ ret: FEGETENVD_GRP( OldEnvironment.d ); newexc = OldEnvironment.i.lo & FE_ALL_EXCEPT; OldEnvironment.i.lo = OldEnv; if ((newexc & FE_INVALID) != 0) OldEnvironment.i.lo |= SET_INVALID; OldEnvironment.i.lo |= newexc & ( FE_INEXACT | FE_DIVBYZERO | FE_UNDERFLOW | FE_OVERFLOW ); FESETENVD_GRP( OldEnvironment.d ); return rslt; }
__complex__ double __csqrt (__complex__ double x) { __complex__ double res; int rcls = fpclassify (__real__ x); int icls = fpclassify (__imag__ x); if (__builtin_expect (rcls <= FP_INFINITE || icls <= FP_INFINITE, 0)) { if (icls == FP_INFINITE) { __real__ res = HUGE_VAL; __imag__ res = __imag__ x; } else if (rcls == FP_INFINITE) { if (__real__ x < 0.0) { __real__ res = icls == FP_NAN ? __nan ("") : 0; __imag__ res = __copysign (HUGE_VAL, __imag__ x); } else { __real__ res = __real__ x; __imag__ res = (icls == FP_NAN ? __nan ("") : __copysign (0.0, __imag__ x)); } } else { __real__ res = __nan (""); __imag__ res = __nan (""); } } else { if (__builtin_expect (icls == FP_ZERO, 0)) { if (__real__ x < 0.0) { __real__ res = 0.0; __imag__ res = __copysign (__ieee754_sqrt (-__real__ x), __imag__ x); } else { __real__ res = fabs (__ieee754_sqrt (__real__ x)); __imag__ res = __copysign (0.0, __imag__ x); } } else if (__builtin_expect (rcls == FP_ZERO, 0)) { double r; if (fabs (__imag__ x) >= 2.0 * DBL_MIN) r = __ieee754_sqrt (0.5 * fabs (__imag__ x)); else r = 0.5 * __ieee754_sqrt (2.0 * fabs (__imag__ x)); __real__ res = r; __imag__ res = __copysign (r, __imag__ x); } else { double d, r, s; int scale = 0; if (fabs (__real__ x) > DBL_MAX / 4.0) { scale = 1; __real__ x = __scalbn (__real__ x, -2 * scale); __imag__ x = __scalbn (__imag__ x, -2 * scale); } else if (fabs (__imag__ x) > DBL_MAX / 4.0) { scale = 1; if (fabs (__real__ x) >= 4.0 * DBL_MIN) __real__ x = __scalbn (__real__ x, -2 * scale); else __real__ x = 0.0; __imag__ x = __scalbn (__imag__ x, -2 * scale); } else if (fabs (__real__ x) < DBL_MIN && fabs (__imag__ x) < DBL_MIN) { scale = -(DBL_MANT_DIG / 2); __real__ x = __scalbn (__real__ x, -2 * scale); __imag__ x = __scalbn (__imag__ x, -2 * scale); } d = __ieee754_hypot (__real__ x, __imag__ x); /* Use the identity 2 Re res Im res = Im x to avoid cancellation error in d +/- Re x. */ if (__real__ x > 0) { r = __ieee754_sqrt (0.5 * (d + __real__ x)); s = 0.5 * (__imag__ x / r); } else { s = __ieee754_sqrt (0.5 * (d - __real__ x)); r = fabs (0.5 * (__imag__ x / s)); } if (scale) { r = __scalbn (r, scale); s = __scalbn (s, scale); } __real__ res = r; __imag__ res = __copysign (s, __imag__ x); } } return res; }
double __ieee754_gamma_r (double x, int *signgamp) { int32_t hx; u_int32_t lx; EXTRACT_WORDS (hx, lx, x); if (__glibc_unlikely (((hx & 0x7fffffff) | lx) == 0)) { /* Return value for x == 0 is Inf with divide by zero exception. */ *signgamp = 0; return 1.0 / x; } if (__builtin_expect (hx < 0, 0) && (u_int32_t) hx < 0xfff00000 && __rint (x) == x) { /* Return value for integer x < 0 is NaN with invalid exception. */ *signgamp = 0; return (x - x) / (x - x); } if (__glibc_unlikely ((unsigned int) hx == 0xfff00000 && lx == 0)) { /* x == -Inf. According to ISO this is NaN. */ *signgamp = 0; return x - x; } if (__glibc_unlikely ((hx & 0x7ff00000) == 0x7ff00000)) { /* Positive infinity (return positive infinity) or NaN (return NaN). */ *signgamp = 0; return x + x; } if (x >= 172.0) { /* Overflow. */ *signgamp = 0; return DBL_MAX * DBL_MAX; } else if (x > 0.0) { *signgamp = 0; int exp2_adj; double ret = gamma_positive (x, &exp2_adj); return __scalbn (ret, exp2_adj); } else if (x >= -DBL_EPSILON / 4.0) { *signgamp = 0; return 1.0 / x; } else { double tx = __trunc (x); *signgamp = (tx == 2.0 * __trunc (tx / 2.0)) ? -1 : 1; if (x <= -184.0) /* Underflow. */ return DBL_MIN * DBL_MIN; double frac = tx - x; if (frac > 0.5) frac = 1.0 - frac; double sinpix = (frac <= 0.25 ? __sin (M_PI * frac) : __cos (M_PI * (0.5 - frac))); int exp2_adj; double ret = M_PI / (-x * sinpix * gamma_positive (-x, &exp2_adj)); return __scalbn (ret, -exp2_adj); } }
__complex__ double __clog (__complex__ double x) { __complex__ double result; int rcls = fpclassify (__real__ x); int icls = fpclassify (__imag__ x); if (__glibc_unlikely (rcls == FP_ZERO && icls == FP_ZERO)) { /* Real and imaginary part are 0.0. */ __imag__ result = signbit (__real__ x) ? M_PI : 0.0; __imag__ result = __copysign (__imag__ result, __imag__ x); /* Yes, the following line raises an exception. */ __real__ result = -1.0 / fabs (__real__ x); } else if (__glibc_likely (rcls != FP_NAN && icls != FP_NAN)) { /* Neither real nor imaginary part is NaN. */ double absx = fabs (__real__ x), absy = fabs (__imag__ x); int scale = 0; if (absx < absy) { double t = absx; absx = absy; absy = t; } if (absx > DBL_MAX / 2.0) { scale = -1; absx = __scalbn (absx, scale); absy = (absy >= DBL_MIN * 2.0 ? __scalbn (absy, scale) : 0.0); } else if (absx < DBL_MIN && absy < DBL_MIN) { scale = DBL_MANT_DIG; absx = __scalbn (absx, scale); absy = __scalbn (absy, scale); } if (absx == 1.0 && scale == 0) { __real__ result = __log1p (absy * absy) / 2.0; math_check_force_underflow_nonneg (__real__ result); } else if (absx > 1.0 && absx < 2.0 && absy < 1.0 && scale == 0) { double d2m1 = (absx - 1.0) * (absx + 1.0); if (absy >= DBL_EPSILON) d2m1 += absy * absy; __real__ result = __log1p (d2m1) / 2.0; } else if (absx < 1.0 && absx >= 0.5 && absy < DBL_EPSILON / 2.0 && scale == 0) { double d2m1 = (absx - 1.0) * (absx + 1.0); __real__ result = __log1p (d2m1) / 2.0; } else if (absx < 1.0 && absx >= 0.5 && scale == 0 && absx * absx + absy * absy >= 0.5) { double d2m1 = __x2y2m1 (absx, absy); __real__ result = __log1p (d2m1) / 2.0; } else { double d = __ieee754_hypot (absx, absy); __real__ result = __ieee754_log (d) - scale * M_LN2; } __imag__ result = __ieee754_atan2 (__imag__ x, __real__ x); } else { __imag__ result = __nan (""); if (rcls == FP_INFINITE || icls == FP_INFINITE) /* Real or imaginary part is infinite. */ __real__ result = HUGE_VAL; else __real__ result = __nan (""); } return result; }
__complex__ double __clog10 (__complex__ double x) { __complex__ double result; int rcls = fpclassify (__real__ x); int icls = fpclassify (__imag__ x); if (__builtin_expect (rcls == FP_ZERO && icls == FP_ZERO, 0)) { /* Real and imaginary part are 0.0. */ __imag__ result = signbit (__real__ x) ? M_PI : 0.0; __imag__ result = __copysign (__imag__ result, __imag__ x); /* Yes, the following line raises an exception. */ __real__ result = -1.0 / fabs (__real__ x); } else if (__builtin_expect (rcls != FP_NAN && icls != FP_NAN, 1)) { /* Neither real nor imaginary part is NaN. */ double absx = fabs (__real__ x), absy = fabs (__imag__ x); int scale = 0; if (absx < absy) { double t = absx; absx = absy; absy = t; } if (absx > DBL_MAX / 2.0) { scale = -1; absx = __scalbn (absx, scale); absy = (absy >= DBL_MIN * 2.0 ? __scalbn (absy, scale) : 0.0); } else if (absx < DBL_MIN && absy < DBL_MIN) { scale = DBL_MANT_DIG; absx = __scalbn (absx, scale); absy = __scalbn (absy, scale); } if (absx == 1.0 && scale == 0) { double absy2 = absy * absy; if (absy2 <= DBL_MIN * 2.0 * M_LN10) { #if __FLT_EVAL_METHOD__ == 0 __real__ result = (absy2 / 2.0 - absy2 * absy2 / 4.0) * M_LOG10E; #else volatile double force_underflow = absy2 * absy2 / 4.0; __real__ result = (absy2 / 2.0 - force_underflow) * M_LOG10E; #endif } else __real__ result = __log1p (absy2) * (M_LOG10E / 2.0); } else if (absx > 1.0 && absx < 2.0 && absy < 1.0 && scale == 0) { double d2m1 = (absx - 1.0) * (absx + 1.0); if (absy >= DBL_EPSILON) d2m1 += absy * absy; __real__ result = __log1p (d2m1) * (M_LOG10E / 2.0); } else if (absx < 1.0 && absx >= 0.75 && absy < DBL_EPSILON / 2.0 && scale == 0) { double d2m1 = (absx - 1.0) * (absx + 1.0); __real__ result = __log1p (d2m1) * (M_LOG10E / 2.0); } else if (absx < 1.0 && (absx >= 0.75 || absy >= 0.5) && scale == 0) { double d2m1 = __x2y2m1 (absx, absy); __real__ result = __log1p (d2m1) * (M_LOG10E / 2.0); } else { double d = __ieee754_hypot (absx, absy); __real__ result = __ieee754_log10 (d) - scale * M_LOG10_2; } __imag__ result = M_LOG10E * __ieee754_atan2 (__imag__ x, __real__ x); } else { __imag__ result = __nan (""); if (rcls == FP_INFINITE || icls == FP_INFINITE) /* Real or imaginary part is infinite. */ __real__ result = HUGE_VAL; else __real__ result = __nan (""); } return result; }