double tan(double x) { double y[2], z = 0.0; int n, ix; /* high word of x */ ix = ((int *) &x)[HIWORD]; /* |x| ~< pi/4 */ ix &= 0x7fffffff; if (ix <= 0x3fe921fb) return (__k_tan(x, z, 0)); /* tan(Inf or NaN) is NaN */ else if (ix >= 0x7ff00000) { #if defined(FPADD_TRAPS_INCOMPLETE_ON_NAN) return (ix >= 0x7ff80000 ? x : x - x); /* NaN */ /* assumes sparc-like QNaN */ #else return (x - x); /* NaN */ #endif } /* argument reduction needed */ else { n = __rem_pio2(x, y); return (__k_tan(y[0], y[1], n & 1)); } }
double sin(double x) { double y[2]; uint32_t ix; unsigned n; /* High word of x. */ GET_HIGH_WORD(ix, x); ix &= 0x7fffffff; /* |x| ~< pi/4 */ if (ix <= 0x3fe921fb) { if (ix < 0x3e500000) { /* |x| < 2**-26 */ /* raise inexact if x != 0 and underflow if subnormal*/ FORCE_EVAL(ix < 0x00100000 ? x/0x1p120f : x+0x1p120f); return x; } return __sin(x, 0.0, 0); } /* sin(Inf or NaN) is NaN */ if (ix >= 0x7ff00000) return x - x; /* argument reduction needed */ n = __rem_pio2(x, y); switch (n&3) { case 0: return __sin(y[0], y[1], 1); case 1: return __cos(y[0], y[1]); case 2: return -__sin(y[0], y[1], 1); default: return -__cos(y[0], y[1]); } }
double tan(double x) { double y[2]; uint32_t ix; unsigned n; GET_HIGH_WORD(ix, x); ix &= 0x7fffffff; /* |x| ~< pi/4 */ if (ix <= 0x3fe921fb) { if (ix < 0x3e400000) { /* |x| < 2**-27 */ /* raise inexact if x!=0 and underflow if subnormal */ FORCE_EVAL(ix < 0x00100000 ? x / 0x1p120f : x + 0x1p120f); return x; } return __tan(x, 0.0, 0); } /* tan(Inf or NaN) is NaN */ if (ix >= 0x7ff00000) return x - x; /* argument reduction */ n = __rem_pio2(x, y); return __tan(y[0], y[1], n & 1); }
double cos(double x) { double y[2],z=0.0; int32_t n, ix; GET_HIGH_WORD(ix, x); /* |x| ~< pi/4 */ ix &= 0x7fffffff; if (ix <= 0x3fe921fb) { if (ix < 0x3e46a09e) /* if x < 2**-27 * sqrt(2) */ /* raise inexact if x != 0 */ if ((int)x == 0) return 1.0; return __cos(x, z); } /* cos(Inf or NaN) is NaN */ if (ix >= 0x7ff00000) return x-x; /* argument reduction needed */ n = __rem_pio2(x, y); switch (n&3) { case 0: return __cos(y[0], y[1]); case 1: return -__sin(y[0], y[1], 1); case 2: return -__cos(y[0], y[1]); default: return __sin(y[0], y[1], 1); } }
void sincos(double x, double *sin, double *cos) { double y[2], s, c; uint32_t ix; unsigned n; GET_HIGH_WORD(ix, x); ix &= 0x7fffffff; /* |x| ~< pi/4 */ if (ix <= 0x3fe921fb) { /* if |x| < 2**-27 * sqrt(2) */ if (ix < 0x3e46a09e) { /* raise inexact if x!=0 and underflow if subnormal */ FORCE_EVAL(ix < 0x00100000 ? x/0x1p120f : x+0x1p120f); *sin = x; *cos = 1.0; return; } *sin = __sin(x, 0.0, 0); *cos = __cos(x, 0.0); return; } /* sincos(Inf or NaN) is NaN */ if (ix >= 0x7ff00000) { *sin = *cos = x - x; return; } /* argument reduction needed */ n = __rem_pio2(x, y); s = __sin(y[0], y[1], 1); c = __cos(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; } }