rework langinfo code for ABI compat and for use by time code
[musl] / src / math / tanl.c
index 462ead9..546c7a0 100644 (file)
@@ -38,47 +38,31 @@ long double tanl(long double x)
        return tan(x);
 }
 #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
-#include "__rem_pio2l.h"
-
 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