math: clean up inverse trigonometric functions
[musl] / src / math / atan2l.c
index 45cbfcc..e86dbff 100644 (file)
@@ -24,8 +24,6 @@ long double atan2l(long double y, long double x)
 }
 #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
 #include "__invtrigl.h"
-// FIXME:
-static const volatile long double tiny = 1.0e-300;
 
 long double atan2l(long double y, long double x)
 {
@@ -40,12 +38,12 @@ long double atan2l(long double y, long double x)
        ux.e = x;
        expsignx = ux.xbits.expsign;
        exptx = expsignx & 0x7fff;
-       if ((exptx==BIAS+LDBL_MAX_EXP &&
+       if ((exptx==0x7fff &&
             ((ux.bits.manh&~LDBL_NBIT)|ux.bits.manl)!=0) || /* x is NaN */
-           (expty==BIAS+LDBL_MAX_EXP &&
+           (expty==0x7fff &&
             ((uy.bits.manh&~LDBL_NBIT)|uy.bits.manl)!=0))   /* y is NaN */
                return x+y;
-       if (expsignx==BIAS && ((ux.bits.manh&~LDBL_NBIT)|ux.bits.manl)==0) /* x=1.0 */
+       if (expsignx==0x3fff && ((ux.bits.manh&~LDBL_NBIT)|ux.bits.manl)==0) /* x=1.0 */
                return atanl(y);
        m = ((expsigny>>15)&1) | ((expsignx>>14)&2);  /* 2*sign(x)+sign(y) */
 
@@ -54,39 +52,39 @@ long double atan2l(long double y, long double x)
                switch(m) {
                case 0:
                case 1: return y;           /* atan(+-0,+anything)=+-0 */
-               case 2: return  pi_hi+tiny; /* atan(+0,-anything) = pi */
-               case 3: return -pi_hi-tiny; /* atan(-0,-anything) =-pi */
+               case 2: return  2*pio2_hi+0x1p-1000; /* atan(+0,-anything) = pi */
+               case 3: return -2*pio2_hi-0x1p-1000; /* atan(-0,-anything) =-pi */
                }
        }
        /* when x = 0 */
        if (exptx==0 && ((ux.bits.manh&~LDBL_NBIT)|ux.bits.manl)==0)
-               return expsigny < 0 ? -pio2_hi-tiny : pio2_hi+tiny;
+               return expsigny < 0 ? -pio2_hi-0x1p-1000 : pio2_hi+0x1p-1000;
        /* when x is INF */
-       if (exptx == BIAS+LDBL_MAX_EXP) {
-               if (expty == BIAS+LDBL_MAX_EXP) {
+       if (exptx == 0x7fff) {
+               if (expty == 0x7fff) {
                        switch(m) {
-                       case 0: return  pio2_hi*0.5+tiny; /* atan(+INF,+INF) */
-                       case 1: return -pio2_hi*0.5-tiny; /* atan(-INF,+INF) */
-                       case 2: return  1.5*pio2_hi+tiny; /* atan(+INF,-INF) */
-                       case 3: return -1.5*pio2_hi-tiny; /* atan(-INF,-INF) */
+                       case 0: return  pio2_hi*0.5+0x1p-1000; /* atan(+INF,+INF) */
+                       case 1: return -pio2_hi*0.5-0x1p-1000; /* atan(-INF,+INF) */
+                       case 2: return  1.5*pio2_hi+0x1p-1000; /* atan(+INF,-INF) */
+                       case 3: return -1.5*pio2_hi-0x1p-1000; /* atan(-INF,-INF) */
                        }
                } else {
                        switch(m) {
                        case 0: return  0.0;        /* atan(+...,+INF) */
                        case 1: return -0.0;        /* atan(-...,+INF) */
-                       case 2: return  pi_hi+tiny; /* atan(+...,-INF) */
-                       case 3: return -pi_hi-tiny; /* atan(-...,-INF) */
+                       case 2: return  2*pio2_hi+0x1p-1000; /* atan(+...,-INF) */
+                       case 3: return -2*pio2_hi-0x1p-1000; /* atan(-...,-INF) */
                        }
                }
        }
        /* when y is INF */
-       if (expty == BIAS+LDBL_MAX_EXP)
-               return expsigny < 0 ? -pio2_hi-tiny : pio2_hi+tiny;
+       if (expty == 0x7fff)
+               return expsigny < 0 ? -pio2_hi-0x1p-1000 : pio2_hi+0x1p-1000;
 
        /* compute y/x */
        k = expty-exptx;
        if(k > LDBL_MANT_DIG+2) { /* |y/x| huge */
-               z = pio2_hi+pio2_lo;
+               z = pio2_hi+0x1p-1000;
                m &= 1;
        } else if (expsignx < 0 && k < -LDBL_MANT_DIG-2) /* |y/x| tiny, x<0 */
                z = 0.0;
@@ -95,9 +93,9 @@ long double atan2l(long double y, long double x)
        switch (m) {
        case 0: return z;               /* atan(+,+) */
        case 1: return -z;              /* atan(-,+) */
-       case 2: return pi_hi-(z-pi_lo); /* atan(+,-) */
+       case 2: return 2*pio2_hi-(z-2*pio2_lo); /* atan(+,-) */
        default: /* case 3 */
-               return (z-pi_lo)-pi_hi; /* atan(-,-) */
+               return (z-2*pio2_lo)-2*pio2_hi; /* atan(-,-) */
        }
 }
 #endif