long double __truncl (long double x) { double xh, xl, hi, lo; ldbl_unpack (x, &xh, &xl); /* Return Inf, Nan, +/-0 unchanged. */ if (__builtin_expect (xh != 0.0 && __builtin_isless (__builtin_fabs (xh), __builtin_inf ()), 1)) { hi = __trunc (xh); if (hi != xh) { /* The high part is not an integer; the low part does not affect the result. */ xh = hi; xl = 0; } else { /* The high part is a nonzero integer. */ lo = xh > 0 ? __floor (xl) : __ceil (xl); xh = hi; xl = lo; ldbl_canonicalize_int (&xh, &xl); } } return ldbl_pack (xh, xl); }
Err mathlib_trunc(UInt16 refnum, double x, double *result) { #pragma unused(refnum) *result = __trunc(x); return mlErrNone; }
long double __qint(double uhi,double ulo ) { ldquad result; #include "msg.h" if ( uhi != uhi ) { result.q.hi = uhi; result.q.lo = ulo; return ( result.ld ); } if ( uhi >= 0.0 ) { if ( uhi < twop52.d ) { /* binary point occurs in uhi; truncate uhi to an integer */ result.q.hi = __trunc(uhi); result.q.lo = 0.0; if ( result.q.hi < uhi ) return ( result.ld ); /* must adjust result by one if ulo < 0.0 */ if ( ulo < 0.0 ) { result.q.hi -= 1.0; return ( result.ld ); } return ( result.ld ); } else if ( fabs(ulo) < twop52.d ) { /* binary point occurs in ulo; truncate ulo to an integer */ result.q.hi = uhi; result.q.lo = __trunc(ulo); if ( result.q.lo > ulo ) { result.q.lo -= 1.0; } return ( result.ld ); } /* arg is an integer */ result.q.hi = uhi; result.q.lo = ulo; return ( result.ld ); } else { if ( fabs(uhi) < twop52.d ) { /* binary point occurs in uhi; truncate uhi to an integer */ result.q.hi = __trunc(uhi); result.q.lo = 0.0; if ( result.q.hi > uhi ) return ( result.ld ); /* must adjust result by one if ulo > 0.0 */ if ( ulo > 0.0 ) { result.q.hi += 1.0; return ( result.ld ); } return ( result.ld ); } else if ( fabs(ulo) < twop52.d ) { /* binary point occurs in ulo; truncate ulo to an integer */ result.q.hi = uhi; result.q.lo = __trunc(ulo); if ( result.q.lo < ulo ) { result.q.lo += 1.0; } return ( result.ld ); } /* arg is an integer */ result.q.hi = uhi; result.q.lo = ulo; return ( result.ld ); } }
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); } }