diff options
author | Rich Felker <dalias@aerifal.cx> | 2013-05-18 12:06:42 -0400 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2013-05-18 12:06:42 -0400 |
commit | 83af1dd65a11f3da3f99ba861248a841c402ccaa (patch) | |
tree | dece0960d64fb52abcf7a8195bf5082523cea70b /src/math/tanl.c | |
parent | 69ee9b2cb169ee843ac9e209f919d088499152f7 (diff) | |
parent | bfda37935867f9bf271d6074db0accf05c63ad10 (diff) | |
download | musl-83af1dd65a11f3da3f99ba861248a841c402ccaa.tar.gz musl-83af1dd65a11f3da3f99ba861248a841c402ccaa.tar.xz musl-83af1dd65a11f3da3f99ba861248a841c402ccaa.zip |
Merge remote-tracking branch 'nsz/review'
Diffstat (limited to 'src/math/tanl.c')
-rw-r--r-- | src/math/tanl.c | 38 |
1 files changed, 12 insertions, 26 deletions
diff --git a/src/math/tanl.c b/src/math/tanl.c index 0194eaf7..546c7a02 100644 --- a/src/math/tanl.c +++ b/src/math/tanl.c @@ -41,42 +41,28 @@ long double tanl(long double x) long double tanl(long double x) { union IEEEl2bits z; - int e0, s; long double y[2]; - long double hi, lo; + unsigned n; z.e = x; - s = z.bits.sign; z.bits.sign = 0; - /* If x = +-0 or x is subnormal, then tan(x) = x. */ - if (z.bits.exp == 0) - return x; - /* If x = NaN or Inf, then tan(x) = NaN. */ - if (z.bits.exp == 32767) + if (z.bits.exp == 0x7fff) return (x - x) / (x - x); - /* Optimize the case where x is already within range. */ + /* |x| < (double)pi/4 */ if (z.e < M_PI_4) { - hi = __tanl(z.e, 0, 0); - return s ? -hi : hi; + /* |x| < 0x1p-64 */ + if (z.bits.exp < 0x3fff - 64) { + /* raise inexact if x!=0 and underflow if subnormal */ + FORCE_EVAL(z.bits.exp == 0 ? x/0x1p120f : x+0x1p120f); + return x; + } + return __tanl(x, 0, 0); } - e0 = __rem_pio2l(x, y); - hi = y[0]; - lo = y[1]; - - switch (e0 & 3) { - case 0: - case 2: - hi = __tanl(hi, lo, 0); - break; - case 1: - case 3: - hi = __tanl(hi, lo, 1); - break; - } - return hi; + n = __rem_pio2l(x, y); + return __tanl(y[0], y[1], n&1); } #endif |