long double cbrtl(long double x) { long double s, t, r, w, y; double dx, dy; int *py = (int *) &dy; int n, m, m3, sx; if (!finitel(x)) return (x + x); if (iszerol(x)) return (x); sx = signbitl(x); x = fabsl(x); n = ilogbl(x); m = n / 3; m3 = m + m + m; y = scalbnl(x, -m3); dx = (double) y; dy = cbrt(dx); py[1 - n0] += 2; if (py[1 - n0] == 0) py[n0] += 1; /* one step newton iteration to 113 bits with error < 0.667ulps */ t = (long double) dy; t = scalbnl(t, m); s = t * t; r = x / s; w = t + t; r = (r - t) / (w + r); t += t * r; return (sx == 0 ? t : -t); }
long double log10l(long double x) { long double y, z; enum fp_direction_type rd; int n; if (!finitel(x)) return (x + fabsl(x)); /* x is +-INF or NaN */ else if (x > zero) { n = ilogbl(x); if (n < 0) n += 1; rd = __swapRD(fp_nearest); y = n; x = scalbnl(x, -n); z = y * log10_2lo + ivln10 * logl(x); z += y * log10_2hi; if (rd != fp_nearest) (void) __swapRD(rd); return (z); } else if (x == zero) /* -INF */ return (-one / zero); else /* x <0 , return NaN */ return (zero / zero); }
long double tanhl(long double x) { long double t, y, z; int signx; #ifndef lint volatile long double dummy; #endif if (isnanl(x)) return (x + x); /* x is NaN */ signx = signbitl(x); t = fabsl(x); z = one; if (t <= threshold) { if (t > one) z = one - two / (expm1l(t + t) + two); else if (t > small) { y = expm1l(-t - t); z = -y / (y + two); } else { #ifndef lint dummy = t + big; /* inexact if t != 0 */ #endif return (x); } } else if (!finitel(t)) return (copysignl(one, x)); else return (signx ? -z + small * small : z - small * small); return (signx ? -z : z); }
long double floorl(long double x) { long double t; if (!finitel(x)) return (x + x); t = rintl(x); if (t <= x) return (t); /* already floor(x) */ else /* x < t case: return t-1 */ return (copysignl(t - qone, x)); }
long double ceill(long double x) { long double t; if (!finitel(x)) return (x + x); t = rintl(x); if (t >= x) /* already ceil(x) */ return (t); else /* t < x case: return t+1 */ return (copysignl(t + qone, x)); }
long double aintl(long double x) { long double t, w; if (!finitel(x)) return (x + x); w = fabsl(x); t = rintl(w); if (t <= w) return (copysignl(t, x)); /* NaN or already aint(|x|) */ else /* |t|>|x| case */ return (copysignl(t - qone, x)); /* |t-1|*sign(x) */ }
long double sinhl(long double x) { long double r, t; if (!finitel(x)) return (x + x); /* x is INF or NaN */ r = fabsl(x); if (r < lnovft) { t = expm1l(r); r = copysignl((t + t / (one + t)) * half, x); } else { r = copysignl(expl((r - lnovft) - lnovlo), x); r = scalbnl(r, 16383); } return (r); }
long double anintl(long double x) { long double t, w, z; if (!finitel(x)) return (x + x); w = fabsl(x); t = rintl(w); if (t == w) return (copysignl(t, x)); z = t - w; if (z > qhalf) t = t - qone; else if (z <= qmhalf) t = t + qone; return (copysignl(t, x)); }
void sincosl(long double x, long double *s, long double *c) { long double y[2], z = 0.0L; int n, ix; #if defined(__i386) || defined(__amd64) int *px = (int *) &x; #endif /* trig(Inf or NaN) is NaN */ if (!finitel(x)) { *s = *c = x - x; return; } /* High word of x. */ #if defined(__i386) || defined(__amd64) XTOI(px, ix); #else ix = *(int *) &x; #endif /* |x| ~< pi/4 */ ix &= 0x7fffffff; if (ix <= 0x3ffe9220) *s = __k_sincosl(x, z, c); /* argument reduction needed */ else { n = __rem_pio2l(x, y); switch (n & 3) { case 0: *s = __k_sincosl(y[0], y[1], c); break; case 1: *c = -__k_sincosl(y[0], y[1], s); break; case 2: *s = -__k_sincosl(y[0], y[1], c); *c = -*c; break; case 3: *c = __k_sincosl(y[0], y[1], s); *s = -*s; } } }
long double coshl(long double x) { long double t, w; w = fabsl(x); if (!finitel(w)) return (w + w); /* x is INF or NaN */ if (w < thr1) { t = w < tinyl ? w : expm1l(w); w = one + t; if (w != one) w = one + (t * t) / (w + w); return (w); } else if (w < thr2) { t = expl(w); return (half * (t + one / t)); } else if (w <= lnovftL) return (half * expl(w)); else { return (scalbnl(expl((w - MEP1 * ln2hi) - MEP1 * ln2lo), ME)); } }
long double coshl(long double x) { long double w, t; w = fabsl(x); if (!finitel(w)) return (w + w); /* x is INF or NaN */ if (w < thr1) { if (w < tinyl) return (one + w); /* inexact+directed rounding */ t = expm1l(w); w = one + t; w = one + (t * t) / (w + w); return (w); } if (w < thr2) { t = expl(w); return (half * (t + one / t)); } if (w <= lnovft) return (half * expl(w)); return (scalbnl(expl((w - lnovft) - lnovlo), 16383)); }
long double atan2l(long double y, long double x) { long double t, z; int k, m, signy, signx; if (x != x || y != y) return (x + y); /* return NaN if x or y is NAN */ signy = signbitl(y); signx = signbitl(x); if (x == one) return (atanl(y)); m = signy + signx + signx; /* when y = 0 */ if (y == zero) switch (m) { case 0: return (y); /* atan(+0,+anything) */ case 1: return (y); /* atan(-0,+anything) */ case 2: return (PI + tiny); /* atan(+0,-anything) */ case 3: return (-PI - tiny); /* atan(-0,-anything) */ } /* when x = 0 */ if (x == zero) return (signy == 1 ? -PIo2 - tiny : PIo2 + tiny); /* when x is INF */ if (!finitel(x)) if (!finitel(y)) { switch (m) { case 0: return (PIo4 + tiny); /* atan(+INF,+INF) */ case 1: return (-PIo4 - tiny); /* atan(-INF,+INF) */ case 2: return (PI3o4 + tiny); /* atan(+INF,-INF) */ case 3: return (-PI3o4 - tiny); /* atan(-INF,-INF) */ } } else { switch (m) { case 0: return (zero); /* atan(+...,+INF) */ case 1: return (-zero); /* atan(-...,+INF) */ case 2: return (PI + tiny); /* atan(+...,-INF) */ case 3: return (-PI - tiny); /* atan(-...,-INF) */ } } /* when y is INF */ if (!finitel(y)) return (signy == 1 ? -PIo2 - tiny : PIo2 + tiny); /* compute y/x */ x = fabsl(x); y = fabsl(y); t = PI_lo; k = (ilogbl(y) - ilogbl(x)); if (k > 120) z = PIo2 + half * t; else if (m > 1 && k < -120) z = zero; else z = atanl(y / x); switch (m) { case 0: return (z); /* atan(+,+) */ case 1: return (-z); /* atan(-,+) */ case 2: return (PI - (z - t)); /* atan(+,-) */ case 3: return ((z - t) - PI); /* atan(-,-) */ } /* NOTREACHED */ }