math: use 0x1p-120f and 0x1p120f for tiny and huge values
authorSzabolcs Nagy <nsz@port70.net>
Sun, 16 Dec 2012 19:28:43 +0000 (20:28 +0100)
committerSzabolcs Nagy <nsz@port70.net>
Sun, 16 Dec 2012 19:28:43 +0000 (20:28 +0100)
previously 0x1p-1000 and 0x1p1000 was used for raising inexact
exception like x+tiny (when x is big) or x+huge (when x is small)

the rational is that these float consts are large enough
(0x1p-120 + 1 raises inexact even on ld128 which has 113 mant bits)
and float consts maybe smaller or easier to load on some platforms
(on i386 this reduced the object file size by 4bytes in some cases)

src/math/acos.c
src/math/acosl.c
src/math/asin.c
src/math/asinh.c
src/math/asinhl.c
src/math/asinl.c
src/math/atan.c
src/math/atan2l.c
src/math/atanl.c
src/math/exp2f.c

index be95d25e24a14fda2d7e672dd2424585266a851c..cd5d06a632921a668eaa7e7bf63ab449de423478 100644 (file)
@@ -72,7 +72,7 @@ double acos(double x)
                if ((ix-0x3ff00000 | lx) == 0) {
                        /* acos(1)=0, acos(-1)=pi */
                        if (hx >> 31)
-                               return 2*pio2_hi + 0x1p-1000;
+                               return 2*pio2_hi + 0x1p-120f;
                        return 0;
                }
                return 0/(x-x);
@@ -80,7 +80,7 @@ double acos(double x)
        /* |x| < 0.5 */
        if (ix < 0x3fe00000) {
                if (ix <= 0x3c600000)  /* |x| < 2**-57 */
-                       return pio2_hi + 0x1p-1000;
+                       return pio2_hi + 0x1p-120f;
                return pio2_hi - (x - (pio2_lo-x*R(x*x)));
        }
        /* x < -0.5 */
index 9e9b01e41fbf693c2953ac3104764aa5edf85091..9e7b7fb3a146c0c978070cd4b9eb428d873a0d21 100644 (file)
@@ -38,14 +38,14 @@ long double acosl(long double x)
                        ((u.bits.manh & ~LDBL_NBIT) | u.bits.manl) == 0) {
                        if (expsign > 0)
                                return 0;  /* acos(1) = 0 */
-                       return 2*pio2_hi + 0x1p-1000;  /* acos(-1)= pi */
+                       return 2*pio2_hi + 0x1p-120f;  /* acos(-1)= pi */
                }
                return 0/(x-x);  /* acos(|x|>1) is NaN */
        }
        /* |x| < 0.5 */
        if (expt < 0x3fff - 1) {
                if (expt < 0x3fff - 65)
-                       return pio2_hi + 0x1p-1000;  /* x < 0x1p-65: acosl(x)=pi/2 */
+                       return pio2_hi + 0x1p-120f;  /* x < 0x1p-65: acosl(x)=pi/2 */
                return pio2_hi - (x - (pio2_lo - x * __invtrigl_R(x*x)));
        }
        /* x < -0.5 */
index a1906b0849cc29b5aea208562201d6cbc0555338..d61c04b4b86ef0452a76238663991747024335e4 100644 (file)
@@ -77,14 +77,14 @@ double asin(double x)
                GET_LOW_WORD(lx, x);
                if ((ix-0x3ff00000 | lx) == 0)
                        /* asin(1) = +-pi/2 with inexact */
-                       return x*pio2_hi + 0x1p-1000;
+                       return x*pio2_hi + 0x1p-120f;
                return 0/(x-x);
        }
        /* |x| < 0.5 */
        if (ix < 0x3fe00000) {
                if (ix < 0x3e500000) {
                        /* |x|<0x1p-26, return x with inexact if x!=0*/
-                       FORCE_EVAL(x + 0x1p1000);
+                       FORCE_EVAL(x + 0x1p120f);
                        return x;
                }
                return x + x*R(x*x);
index 4152dc39916d5fa502b0e1d3ae0eadaa3405f93c..0829f228ef9d2540578c6512736c107b25c2bc06 100644 (file)
@@ -22,7 +22,7 @@ double asinh(double x)
                x = log1p(x + x*x/(sqrt(x*x+1)+1));
        } else {
                /* |x| < 0x1p-26, raise inexact if x != 0 */
-               FORCE_EVAL(x + 0x1p1000);
+               FORCE_EVAL(x + 0x1p120f);
        }
        return s ? -x : x;
 }
index db9662468ac244db9c81346d03f12cf2fe2a1ec6..3ea887455925f1098dafb4cce417ecf056dacabe 100644 (file)
@@ -31,7 +31,7 @@ long double asinhl(long double x)
                x = log1pl(x + x*x/(sqrtl(x*x+1)+1));
        } else {
                /* |x| < 0x1p-32, raise inexact if x!=0 */
-               FORCE_EVAL(x + 0x1p1000);
+               FORCE_EVAL(x + 0x1p120f);
        }
        return s ? -x : x;
 }
index 0ef9853b1b0f6d02e45c15fa163ae0675c03d429..8799341d568fd81a8d94d439b3c86297fe644566 100644 (file)
@@ -39,13 +39,13 @@ long double asinl(long double x)
                if (expt == 0x3fff &&
                    ((u.bits.manh&~LDBL_NBIT)|u.bits.manl) == 0)
                        /* asin(+-1)=+-pi/2 with inexact */
-                       return x*pio2_hi + 0x1p-1000;
+                       return x*pio2_hi + 0x1p-120f;
                return 0/(x-x);
        }
        if (expt < 0x3fff - 1) {  /* |x| < 0.5 */
                if (expt < 0x3fff - 32) {  /* |x|<0x1p-32, asinl(x)=x */
                        /* return x with inexact if x!=0 */
-                       FORCE_EVAL(x + 0x1p1000);
+                       FORCE_EVAL(x + 0x1p120f);
                        return x;
                }
                return x + x*__invtrigl_R(x*x);
index 7fd8a3b8a1a35f22a7b61345f20ffb32beea8cdd..3c9a59ff3067abdeca4a1c6270f89dc9882e7e9d 100644 (file)
@@ -72,13 +72,13 @@ double atan(double x)
        if (ix >= 0x44100000) {   /* if |x| >= 2^66 */
                if (isnan(x))
                        return x;
-               z = atanhi[3] + 0x1p-1000;
+               z = atanhi[3] + 0x1p-120f;
                return sign ? -z : z;
        }
        if (ix < 0x3fdc0000) {    /* |x| < 0.4375 */
                if (ix < 0x3e400000) {  /* |x| < 2^-27 */
                        /* raise inexact if x!=0 */
-                       FORCE_EVAL(x + 0x1p1000);
+                       FORCE_EVAL(x + 0x1p120f);
                        return x;
                }
                id = -1;
index e86dbffb79860c0737ec5029d66822ef3017a0c6..7cb42c2fe31180241a5538f8e1958d5a5cd9300b 100644 (file)
@@ -52,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  2*pio2_hi+0x1p-1000; /* atan(+0,-anything) = pi */
-               case 3: return -2*pio2_hi-0x1p-1000; /* atan(-0,-anything) =-pi */
+               case 2: return  2*pio2_hi+0x1p-120f; /* atan(+0,-anything) = pi */
+               case 3: return -2*pio2_hi-0x1p-120f; /* atan(-0,-anything) =-pi */
                }
        }
        /* when x = 0 */
        if (exptx==0 && ((ux.bits.manh&~LDBL_NBIT)|ux.bits.manl)==0)
-               return expsigny < 0 ? -pio2_hi-0x1p-1000 : pio2_hi+0x1p-1000;
+               return expsigny < 0 ? -pio2_hi-0x1p-120f : pio2_hi+0x1p-120f;
        /* when x is INF */
        if (exptx == 0x7fff) {
                if (expty == 0x7fff) {
                        switch(m) {
-                       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) */
+                       case 0: return  pio2_hi*0.5+0x1p-120f; /* atan(+INF,+INF) */
+                       case 1: return -pio2_hi*0.5-0x1p-120f; /* atan(-INF,+INF) */
+                       case 2: return  1.5*pio2_hi+0x1p-120f; /* atan(+INF,-INF) */
+                       case 3: return -1.5*pio2_hi-0x1p-120f; /* atan(-INF,-INF) */
                        }
                } else {
                        switch(m) {
                        case 0: return  0.0;        /* atan(+...,+INF) */
                        case 1: return -0.0;        /* atan(-...,+INF) */
-                       case 2: return  2*pio2_hi+0x1p-1000; /* atan(+...,-INF) */
-                       case 3: return -2*pio2_hi-0x1p-1000; /* atan(-...,-INF) */
+                       case 2: return  2*pio2_hi+0x1p-120f; /* atan(+...,-INF) */
+                       case 3: return -2*pio2_hi-0x1p-120f; /* atan(-...,-INF) */
                        }
                }
        }
        /* when y is INF */
        if (expty == 0x7fff)
-               return expsigny < 0 ? -pio2_hi-0x1p-1000 : pio2_hi+0x1p-1000;
+               return expsigny < 0 ? -pio2_hi-0x1p-120f : pio2_hi+0x1p-120f;
 
        /* compute y/x */
        k = expty-exptx;
        if(k > LDBL_MANT_DIG+2) { /* |y/x| huge */
-               z = pio2_hi+0x1p-1000;
+               z = pio2_hi+0x1p-120f;
                m &= 1;
        } else if (expsignx < 0 && k < -LDBL_MANT_DIG-2) /* |y/x| tiny, x<0 */
                z = 0.0;
index 6a480a7a983492913215e0d633ecb469c0d67e38..e76693e47d339baf503a08832898ff9f34d431d9 100644 (file)
@@ -80,7 +80,7 @@ long double atanl(long double x)
                if (expt == 0x7fff &&
                    ((u.bits.manh&~LDBL_NBIT)|u.bits.manl)!=0)  /* NaN */
                        return x+x;
-               z = atanhi[3] + 0x1p-1000;
+               z = atanhi[3] + 0x1p-120f;
                return expsign < 0 ? -z : z;
        }
        /* Extract the exponent and the first few bits of the mantissa. */
@@ -89,7 +89,7 @@ long double atanl(long double x)
        if (expman < ((0x3fff - 2) << 8) + 0xc0) {  /* |x| < 0.4375 */
                if (expt < 0x3fff - 32) {   /* if |x| is small, atanl(x)~=x */
                        /* raise inexact if x!=0 */
-                       FORCE_EVAL(x + 0x1p1000);
+                       FORCE_EVAL(x + 0x1p120f);
                        return x;
                }
                id = -1;
index 279f32dea3b95ed6cd5ef2e2a2a2405f03f8fc5a..ea50db4afa42a923ff69f6d0430f87a76c03e23e 100644 (file)
@@ -97,11 +97,11 @@ float exp2f(float x)
                        return x;
                }
                if (x >= 128) {
-                       STRICT_ASSIGN(float, x, x * 0x1p127);
+                       STRICT_ASSIGN(float, x, x * 0x1p127f);
                        return x;
                }
                if (x <= -150) {
-                       STRICT_ASSIGN(float, x, 0x1p-100*0x1p-100);
+                       STRICT_ASSIGN(float, x, 0x1p-100f*0x1p-100f);
                        return x;
                }
        } else if (ix <= 0x33000000) {  /* |x| <= 0x1p-25 */