long double cosl(long double x) { union ldshape u = {x}; unsigned n; long double y[2], hi, lo; u.i.se &= 0x7fff; if (u.i.se == 0x7fff) return x - x; x = u.f; if (x < M_PI_4) { if (u.i.se < 0x3fff - LDBL_MANT_DIG) /* raise inexact if x!=0 */ return 1.0 + x; return __cosl(x, 0); } n = __rem_pio2l(x, y); hi = y[0]; lo = y[1]; switch (n & 3) { case 0: return __cosl(hi, lo); case 1: return -__sinl(hi, lo, 1); case 2: return -__cosl(hi, lo); case 3: default: return __sinl(hi, lo, 1); } }
long double sinl(long double x) { union ldshape u = {x}; unsigned n; long double y[2], hi, lo; u.i.se &= 0x7fff; if (u.i.se == 0x7fff) return x - x; if (u.f < M_PI_4) { if (u.i.se < 0x3fff - LDBL_MANT_DIG/2) { /* raise inexact if x!=0 and underflow if subnormal */ FORCE_EVAL(u.i.se == 0 ? x*0x1p-120f : x+0x1p120f); return x; } return __sinl(x, 0.0, 0); } n = __rem_pio2l(x, y); hi = y[0]; lo = y[1]; switch (n & 3) { case 0: return __sinl(hi, lo, 1); case 1: return __cosl(hi, lo); case 2: return -__sinl(hi, lo, 1); case 3: default: return -__cosl(hi, lo); } }
void _CDTOD(d_complex_t *ret_val, d_complex_t x, _f_real16 *r) { _f_real16 __atan2l(_f_real16 ax, _f_real16 bx); _f_real16 __cosl(_f_real16 ax); _f_real16 __expl(_f_real16 ax); _f_real16 __logl(_f_real16 ax); _f_real16 __sinl(_f_real16 ax); _f_real16 _CDABS(d_complex_t z); _f_real16 y = *r; _f_real16 one; _f_real16 two; if (x.real == (_f_real16) 0.0 && x.imag == (_f_real16) 0.0) { if (y == (_f_real16) 0.0) { ret_val->real = _DBL_NaN; ret_val->imag = _DBL_NaN; } else { ret_val->real = (_f_real16) 0.0; ret_val->imag = (_f_real16) 0.0; } return; } one = y * __atan2l(x.imag, x.real); two = y * __logl(_CDABS(x)); ret_val->real = __expl(two) * __cosl(one); ret_val->imag = __expl(two) * __sinl(one); }
void _CDTOCD(d_complex_t *ret_val, d_complex_t x, d_complex_t y) { _f_real16 __atan2l(_f_real16 ax, _f_real16 bx); _f_real16 __cosl(_f_real16 ax); _f_real16 __expl(_f_real16 ax); _f_real16 __logl(_f_real16 ax); _f_real16 __sinl(_f_real16 ax); _f_real16 __sqrtl(_f_real16 ax); _f_real16 a; _f_real16 b; _f_real16 c; _f_real16 d; _f_real16 one; _f_real16 two; REGISTER_16 realx; REGISTER_16 imagx; _f_real16 loglabsx, atn2l, expltwo; if (x.real == 0.0 && x.imag == 0.0) { if (y.real == 0.0 && y.imag == 0.0) { ret_val->real = _DBL_NaN; ret_val->imag = _DBL_NaN; } else { ret_val->real = (_f_real16) 0.0; ret_val->imag = (_f_real16) 0.0; } return; } realx.f = x.real; imagx.f = x.imag; a = x.real; b = x.imag; c = y.real; d = y.imag; /* clear sign bit */ realx.ui[0] &= ~IEEE_128_64_SIGN_BIT; imagx.ui[0] &= ~IEEE_128_64_SIGN_BIT; atn2l = __atan2l(b,a); if (realx.f > imagx.f) loglabsx = __logl(realx.f * __sqrtl(1.0 + (imagx.f/realx.f) * (imagx.f/realx.f))); else loglabsx = __logl(imagx.f * __sqrtl(1.0 + (realx.f/imagx.f) * (realx.f/imagx.f))); one = d * loglabsx + c * atn2l; two = c * loglabsx - d * atn2l; expltwo = __expl(two); ret_val->real = expltwo * __cosl(one); ret_val->imag = expltwo * __sinl(one); }
void _CDEXP(d_complex_t *ret_val, d_complex_t z ) { _f_real16 __expl(_f_real16 x); _f_real16 __cosl(_f_real16 x); _f_real16 __sinl(_f_real16 x); ret_val->real = __expl(z.real) * __cosl(z.imag); ret_val->imag = __expl(z.real) * __sinl(z.imag); }
void sincosl(long double x, long double *sin, long double *cos) { union IEEEl2bits u; unsigned n; long double y[2], s, c; u.e = x; u.bits.sign = 0; /* x = nan or inf */ if (u.bits.exp == 0x7fff) { *sin = *cos = x - x; return; } /* |x| < (double)pi/4 */ if (u.e < M_PI_4) { /* |x| < 0x1p-64 */ if (u.bits.exp < 0x3fff - 64) { /* raise underflow if subnormal */ if (u.bits.exp == 0) FORCE_EVAL(x*0x1p-120f); *sin = x; /* raise inexact if x!=0 */ *cos = 1.0 + x; return; } *sin = __sinl(x, 0, 0); *cos = __cosl(x, 0); return; } n = __rem_pio2l(x, y); s = __sinl(y[0], y[1], 1); c = __cosl(y[0], y[1]); switch (n & 3) { case 0: *sin = s; *cos = c; break; case 1: *sin = c; *cos = -s; break; case 2: *sin = -s; *cos = -c; break; case 3: default: *sin = -c; *cos = s; break; } }
void sincosl(long double x, long double *sin, long double *cos) { union IEEEl2bits u; int n; long double y[2], s, c; u.e = x; u.bits.sign = 0; /* x = +-0 or subnormal */ if (!u.bits.exp) { *sin = x; *cos = 1.0; return; } /* x = nan or inf */ if (u.bits.exp == 0x7fff) { *sin = *cos = x - x; return; } /* |x| < pi/4 */ if (u.e < M_PI_4) { *sin = __sinl(x, 0, 0); *cos = __cosl(x, 0); return; } n = __rem_pio2l(x, y); s = __sinl(y[0], y[1], 1); c = __cosl(y[0], y[1]); switch (n & 3) { case 0: *sin = s; *cos = c; break; case 1: *sin = c; *cos = -s; break; case 2: *sin = -s; *cos = -c; break; case 3: default: *sin = -c; *cos = s; break; } }
static long double lg_cospi (long double x) { if (x <= 0.25L) return __cosl (M_PIl * x); else return __sinl (M_PIl * (0.5L - x)); }
long double cosl(long double x) { union IEEEl2bits z; unsigned n; long double y[2]; long double hi, lo; z.e = x; z.bits.sign = 0; /* If x = NaN or Inf, then cos(x) = NaN. */ if (z.bits.exp == 0x7fff) return (x - x) / (x - x); /* |x| < (double)pi/4 */ if (z.e < M_PI_4) { /* |x| < 0x1p-64 */ if (z.bits.exp < 0x3fff - 64) /* raise inexact if x!=0 */ return 1.0 + x; return __cosl(z.e, 0); } n = __rem_pio2l(x, y); hi = y[0]; lo = y[1]; switch (n & 3) { case 0: hi = __cosl(hi, lo); break; case 1: hi = -__sinl(hi, lo, 1); break; case 2: hi = -__cosl(hi, lo); break; case 3: hi = __sinl(hi, lo, 1); break; } return hi; }
long double __ieee754_lgammal_r (long double x, int *signgamp) { long double p, q, w, z, nx; int i, nn; *signgamp = 1; if (! __finitel (x)) return x * x; if (x == 0.0L) { if (__signbitl (x)) *signgamp = -1; } if (x < 0.0L) { q = -x; p = __floorl (q); if (p == q) return (one / (p - p)); i = p; if ((i & 1) == 0) *signgamp = -1; else *signgamp = 1; if (q < 0x1p-120L) return -__logl (q); z = q - p; if (z > 0.5L) { p += 1.0L; z = p - q; } z = q * __sinl (PIL * z); w = __ieee754_lgammal_r (q, &i); z = __logl (PIL / z) - w; return (z); } if (x < 13.5L) { p = 0.0L; nx = __floorl (x + 0.5L); nn = nx; switch (nn) { case 0: /* log gamma (x + 1) = log(x) + log gamma(x) */ if (x < 0x1p-120L) return -__logl (x); else if (x <= 0.125) { p = x * neval (x, RN1, NRN1) / deval (x, RD1, NRD1); } else if (x <= 0.375) { z = x - 0.25L; p = z * neval (z, RN1r25, NRN1r25) / deval (z, RD1r25, NRD1r25); p += lgam1r25b; p += lgam1r25a; } else if (x <= 0.625) { z = x + (1.0L - x0a); z = z - x0b; p = neval (z, RN1r5, NRN1r5) / deval (z, RD1r5, NRD1r5); p = p * z * z; p = p + y0b; p = p + y0a; } else if (x <= 0.875) { z = x - 0.75L; p = z * neval (z, RN1r75, NRN1r75) / deval (z, RD1r75, NRD1r75); p += lgam1r75b; p += lgam1r75a; } else { z = x - 1.0L; p = z * neval (z, RN2, NRN2) / deval (z, RD2, NRD2); } p = p - __logl (x); break; case 1: if (x < 0.875L) { if (x <= 0.625) { z = x + (1.0L - x0a); z = z - x0b; p = neval (z, RN1r5, NRN1r5) / deval (z, RD1r5, NRD1r5); p = p * z * z; p = p + y0b; p = p + y0a; } else if (x <= 0.875) { z = x - 0.75L; p = z * neval (z, RN1r75, NRN1r75) / deval (z, RD1r75, NRD1r75); p += lgam1r75b; p += lgam1r75a; } else { z = x - 1.0L; p = z * neval (z, RN2, NRN2) / deval (z, RD2, NRD2); } p = p - __logl (x); } else if (x < 1.0L) { z = x - 1.0L; p = z * neval (z, RNr9, NRNr9) / deval (z, RDr9, NRDr9); } else if (x == 1.0L) p = 0.0L; else if (x <= 1.125L) { z = x - 1.0L; p = z * neval (z, RN1, NRN1) / deval (z, RD1, NRD1); } else if (x <= 1.375) { z = x - 1.25L; p = z * neval (z, RN1r25, NRN1r25) / deval (z, RD1r25, NRD1r25); p += lgam1r25b; p += lgam1r25a; } else { /* 1.375 <= x+x0 <= 1.625 */ z = x - x0a; z = z - x0b; p = neval (z, RN1r5, NRN1r5) / deval (z, RD1r5, NRD1r5); p = p * z * z; p = p + y0b; p = p + y0a; } break; case 2: if (x < 1.625L) { z = x - x0a; z = z - x0b; p = neval (z, RN1r5, NRN1r5) / deval (z, RD1r5, NRD1r5); p = p * z * z; p = p + y0b; p = p + y0a; } else if (x < 1.875L) { z = x - 1.75L; p = z * neval (z, RN1r75, NRN1r75) / deval (z, RD1r75, NRD1r75); p += lgam1r75b; p += lgam1r75a; } else if (x == 2.0L) p = 0.0L; else if (x < 2.375L) { z = x - 2.0L; p = z * neval (z, RN2, NRN2) / deval (z, RD2, NRD2); } else { z = x - 2.5L; p = z * neval (z, RN2r5, NRN2r5) / deval (z, RD2r5, NRD2r5); p += lgam2r5b; p += lgam2r5a; } break; case 3: if (x < 2.75) { z = x - 2.5L; p = z * neval (z, RN2r5, NRN2r5) / deval (z, RD2r5, NRD2r5); p += lgam2r5b; p += lgam2r5a; } else { z = x - 3.0L; p = z * neval (z, RN3, NRN3) / deval (z, RD3, NRD3); p += lgam3b; p += lgam3a; } break; case 4: z = x - 4.0L; p = z * neval (z, RN4, NRN4) / deval (z, RD4, NRD4); p += lgam4b; p += lgam4a; break; case 5: z = x - 5.0L; p = z * neval (z, RN5, NRN5) / deval (z, RD5, NRD5); p += lgam5b; p += lgam5a; break; case 6: z = x - 6.0L; p = z * neval (z, RN6, NRN6) / deval (z, RD6, NRD6); p += lgam6b; p += lgam6a; break; case 7: z = x - 7.0L; p = z * neval (z, RN7, NRN7) / deval (z, RD7, NRD7); p += lgam7b; p += lgam7a; break; case 8: z = x - 8.0L; p = z * neval (z, RN8, NRN8) / deval (z, RD8, NRD8); p += lgam8b; p += lgam8a; break; case 9: z = x - 9.0L; p = z * neval (z, RN9, NRN9) / deval (z, RD9, NRD9); p += lgam9b; p += lgam9a; break; case 10: z = x - 10.0L; p = z * neval (z, RN10, NRN10) / deval (z, RD10, NRD10); p += lgam10b; p += lgam10a; break; case 11: z = x - 11.0L; p = z * neval (z, RN11, NRN11) / deval (z, RD11, NRD11); p += lgam11b; p += lgam11a; break; case 12: z = x - 12.0L; p = z * neval (z, RN12, NRN12) / deval (z, RD12, NRD12); p += lgam12b; p += lgam12a; break; case 13: z = x - 13.0L; p = z * neval (z, RN13, NRN13) / deval (z, RD13, NRD13); p += lgam13b; p += lgam13a; break; } return p; } if (x > MAXLGM) return (*signgamp * huge * huge); q = ls2pi - x; q = (x - 0.5L) * __logl (x) + q; if (x > 1.0e18L) return (q); p = 1.0L / (x * x); q += neval (p, RASY, NRASY) / x; return (q); }
long double __ieee754_gammal_r (long double x, int *signgamp) { int64_t hx; u_int64_t lx; long double ret; GET_LDOUBLE_WORDS64 (hx, lx, x); if (((hx & 0x7fffffffffffffffLL) | lx) == 0) { /* Return value for x == 0 is Inf with divide by zero exception. */ *signgamp = 0; return 1.0 / x; } if (hx < 0 && (u_int64_t) hx < 0xffff000000000000ULL && __rintl (x) == x) { /* Return value for integer x < 0 is NaN with invalid exception. */ *signgamp = 0; return (x - x) / (x - x); } if (hx == 0xffff000000000000ULL && lx == 0) { /* x == -Inf. According to ISO this is NaN. */ *signgamp = 0; return x - x; } if ((hx & 0x7fff000000000000ULL) == 0x7fff000000000000ULL) { /* Positive infinity (return positive infinity) or NaN (return NaN). */ *signgamp = 0; return x + x; } if (x >= 1756.0L) { /* Overflow. */ *signgamp = 0; return LDBL_MAX * LDBL_MAX; } else { SET_RESTORE_ROUNDL (FE_TONEAREST); if (x > 0.0L) { *signgamp = 0; int exp2_adj; ret = gammal_positive (x, &exp2_adj); ret = __scalbnl (ret, exp2_adj); } else if (x >= -LDBL_EPSILON / 4.0L) { *signgamp = 0; ret = 1.0L / x; } else { long double tx = __truncl (x); *signgamp = (tx == 2.0L * __truncl (tx / 2.0L)) ? -1 : 1; if (x <= -1775.0L) /* Underflow. */ ret = LDBL_MIN * LDBL_MIN; else { long double frac = tx - x; if (frac > 0.5L) frac = 1.0L - frac; long double sinpix = (frac <= 0.25L ? __sinl (M_PIl * frac) : __cosl (M_PIl * (0.5L - frac))); int exp2_adj; ret = M_PIl / (-x * sinpix * gammal_positive (-x, &exp2_adj)); ret = __scalbnl (ret, -exp2_adj); } } } if (isinf (ret) && x != 0) { if (*signgamp < 0) return -(-__copysignl (LDBL_MAX, ret) * LDBL_MAX); else return __copysignl (LDBL_MAX, ret) * LDBL_MAX; } else if (ret == 0) { if (*signgamp < 0) return -(-__copysignl (LDBL_MIN, ret) * LDBL_MIN); else return __copysignl (LDBL_MIN, ret) * LDBL_MIN; } else return ret; }
long double __ieee754_gammal_r (long double x, int *signgamp) { u_int32_t es, hx, lx; GET_LDOUBLE_WORDS (es, hx, lx, x); if (__glibc_unlikely (((es & 0x7fff) | hx | lx) == 0)) { /* Return value for x == 0 is Inf with divide by zero exception. */ *signgamp = 0; return 1.0 / x; } if (__glibc_unlikely (es == 0xffffffff && ((hx & 0x7fffffff) | lx) == 0)) { /* x == -Inf. According to ISO this is NaN. */ *signgamp = 0; return x - x; } if (__glibc_unlikely ((es & 0x7fff) == 0x7fff)) { /* Positive infinity (return positive infinity) or NaN (return NaN). */ *signgamp = 0; return x + x; } if (__builtin_expect ((es & 0x8000) != 0, 0) && __rintl (x) == x) { /* Return value for integer x < 0 is NaN with invalid exception. */ *signgamp = 0; return (x - x) / (x - x); } if (x >= 1756.0L) { /* Overflow. */ *signgamp = 0; return LDBL_MAX * LDBL_MAX; } else if (x > 0.0L) { *signgamp = 0; int exp2_adj; long double ret = gammal_positive (x, &exp2_adj); return __scalbnl (ret, exp2_adj); } else if (x >= -LDBL_EPSILON / 4.0L) { *signgamp = 0; return 1.0f / x; } else { long double tx = __truncl (x); *signgamp = (tx == 2.0L * __truncl (tx / 2.0L)) ? -1 : 1; if (x <= -1766.0L) /* Underflow. */ return LDBL_MIN * LDBL_MIN; long double frac = tx - x; if (frac > 0.5L) frac = 1.0L - frac; long double sinpix = (frac <= 0.25L ? __sinl (M_PIl * frac) : __cosl (M_PIl * (0.5L - frac))); int exp2_adj; long double ret = M_PIl / (-x * sinpix * gammal_positive (-x, &exp2_adj)); return __scalbnl (ret, -exp2_adj); } }