]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Fix lgamma*, log10* and log2* results [BZ #21171]
authorTulio Magno Quites Machado Filho <tuliom@linux.vnet.ibm.com>
Fri, 17 Feb 2017 11:07:57 +0000 (09:07 -0200)
committerTulio Magno Quites Machado Filho <tuliom@linux.vnet.ibm.com>
Fri, 17 Feb 2017 11:07:57 +0000 (09:07 -0200)
lgamma(-x) should return +Inf and raise divide-by-zero.
log10(+-0) and log2(+-0) should return -Inf and raise divide-by-zero.

Tested on powerpc, powerpc64, powerpc64le and x86_64.

[BZ #21171]
* sysdeps/ieee754/dbl-64/e_lgamma_r.c (__ieee754_lgamma_r): Return
+Inf and raise divide-by-zero when x is negative.
* sysdeps/ieee754/flt-32/e_lgammaf_r.c (__ieee754_lgammaf_r): Likewise.
* sysdeps/ieee754/ldbl-128/e_lgammal_r.c (__ieee754_lgammal_r): Likewise.

* sysdeps/ieee754/dbl-64/e_log10.c (__ieee754_log10):  Return
-Inf and raise divide-by-zero when x = +-0.
* sysdeps/ieee754/dbl-64/e_log2.c (__ieee754_log2): Likewise.
* sysdeps/ieee754/flt-32/e_log10f.c (__ieee754_log10f): Likewise.
* sysdeps/ieee754/flt-32/e_log2f.c (__ieee754_log2f): Likewise.
* sysdeps/ieee754/ldbl-128/e_log10l.c (__ieee754_log10l): Likewise.
* sysdeps/ieee754/ldbl-128/e_log2l.c (__ieee754_log2l): Likewise.
* sysdeps/ieee754/ldbl-128ibm/e_log10l.c (__ieee754_log10l): Likewise.
* sysdeps/ieee754/ldbl-128ibm/e_log2l.c (__ieee754_log2l): Likewise.

12 files changed:
ChangeLog
sysdeps/ieee754/dbl-64/e_lgamma_r.c
sysdeps/ieee754/dbl-64/e_log10.c
sysdeps/ieee754/dbl-64/e_log2.c
sysdeps/ieee754/flt-32/e_lgammaf_r.c
sysdeps/ieee754/flt-32/e_log10f.c
sysdeps/ieee754/flt-32/e_log2f.c
sysdeps/ieee754/ldbl-128/e_lgammal_r.c
sysdeps/ieee754/ldbl-128/e_log10l.c
sysdeps/ieee754/ldbl-128/e_log2l.c
sysdeps/ieee754/ldbl-128ibm/e_log10l.c
sysdeps/ieee754/ldbl-128ibm/e_log2l.c

index 17f9b165e3fc4e53af29fa06d4f99685b953b449..2f2a65b8bc24dc93bacfb196ca4490766e31025d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2017-02-17  Tulio Magno Quites Machado Filho  <tuliom@linux.vnet.ibm.com>
+
+       [BZ #21171]
+       * sysdeps/ieee754/dbl-64/e_lgamma_r.c (__ieee754_lgamma_r): Return
+       +Inf and raise divide-by-zero when x is negative.
+       * sysdeps/ieee754/flt-32/e_lgammaf_r.c (__ieee754_lgammaf_r): Likewise.
+       * sysdeps/ieee754/ldbl-128/e_lgammal_r.c (__ieee754_lgammal_r): Likewise.
+       * sysdeps/ieee754/dbl-64/e_log10.c (__ieee754_log10):  Return
+       -Inf and raise divide-by-zero when x = +-0.
+       * sysdeps/ieee754/dbl-64/e_log2.c (__ieee754_log2): Likewise.
+       * sysdeps/ieee754/flt-32/e_log10f.c (__ieee754_log10f): Likewise.
+       * sysdeps/ieee754/flt-32/e_log2f.c (__ieee754_log2f): Likewise.
+       * sysdeps/ieee754/ldbl-128/e_log10l.c (__ieee754_log10l): Likewise.
+       * sysdeps/ieee754/ldbl-128/e_log2l.c (__ieee754_log2l): Likewise.
+       * sysdeps/ieee754/ldbl-128ibm/e_log10l.c (__ieee754_log10l): Likewise.
+       * sysdeps/ieee754/ldbl-128ibm/e_log2l.c (__ieee754_log2l): Likewise.
+
 2017-02-16  Zack Weinberg  <zackw@panix.com>
 
        * scripts/build-many-glibcs.py (bot_build_mail): If the
index 15154c0f43199bc673878bba01b3a1942ef8b39a..c337679f7c793eadb63761a2cab3687d18225bdd 100644 (file)
@@ -225,7 +225,7 @@ __ieee754_lgamma_r(double x, int *signgamp)
        if(hx<0) {
            if(__builtin_expect(ix>=0x43300000, 0))
                /* |x|>=2**52, must be -integer */
-               return x/zero;
+               return __fabs (x)/zero;
            if (x < -2.0 && x > -28.0)
                return __lgamma_neg (x, signgamp);
            t = sin_pi(x);
index df59d9dce47ea9b3bdf4d7b73eaf9aeb79863944..bf40bca874c63969a124978242ecf5f94dd5ae29 100644 (file)
@@ -65,7 +65,7 @@ __ieee754_log10 (double x)
   if (hx < 0x00100000)
     {                           /* x < 2**-1022  */
       if (__glibc_unlikely (((hx & 0x7fffffff) | lx) == 0))
-       return -two54 / (x - x);        /* log(+-0)=-inf */
+       return -two54 / __fabs (x);     /* log(+-0)=-inf  */
       if (__glibc_unlikely (hx < 0))
        return (x - x) / (x - x);       /* log(-#) = NaN */
       k -= 54;
index bc6a34192acb8202dbb36df943713da50ddc3f1f..5af68d8ecc9d7e342782b4efd8886add3f776dc1 100644 (file)
@@ -83,7 +83,7 @@ __ieee754_log2 (double x)
   if (hx < 0x00100000)
     {                           /* x < 2**-1022  */
       if (__glibc_unlikely (((hx & 0x7fffffff) | lx) == 0))
-       return -two54 / (x - x);        /* log(+-0)=-inf */
+       return -two54 / __fabs (x);        /* log(+-0)=-inf */
       if (__glibc_unlikely (hx < 0))
        return (x - x) / (x - x);       /* log(-#) = NaN */
       k -= 54;
index 4d8a66bb3949bc1ce255e4f9623fac0f42656690..1bd2122663748fdf64b6693b4a501fe6597f1e68 100644 (file)
@@ -160,7 +160,7 @@ __ieee754_lgammaf_r(float x, int *signgamp)
        }
        if(hx<0) {
            if(ix>=0x4b000000)  /* |x|>=2**23, must be -integer */
-               return x/zero;
+               return __fabsf (x)/zero;
            if (ix > 0x40000000 /* X < 2.0f.  */
                && ix < 0x41700000 /* X > -15.0f.  */)
                return __lgamma_negf (x, signgamp);
index 2cd01b4a500001101584ebfc5359402ca9588c04..aa21bbc9c558c2c0694659687c3f75da3a27d5bb 100644 (file)
@@ -34,7 +34,7 @@ __ieee754_log10f(float x)
        k=0;
        if (hx < 0x00800000) {                  /* x < 2**-126  */
            if (__builtin_expect((hx&0x7fffffff)==0, 0))
-               return -two25/(x-x);            /* log(+-0)=-inf */
+             return -two25/__fabsf (x);        /* log(+-0)=-inf  */
            if (__builtin_expect(hx<0, 0))
                return (x-x)/(x-x);     /* log(-#) = NaN */
            k -= 25; x *= two25; /* subnormal number, scale up x */
index 857d13fb9be23b0d61954bba314d4fb9eacf7df2..782d901094a95afd6d7558b75f5066a2194904e3 100644 (file)
@@ -43,7 +43,7 @@ __ieee754_log2f(float x)
        k=0;
        if (ix < 0x00800000) {                  /* x < 2**-126  */
            if (__builtin_expect((ix&0x7fffffff)==0, 0))
-               return -two25/(x-x);            /* log(+-0)=-inf */
+               return -two25/__fabsf (x);      /* log(+-0)=-inf  */
            if (__builtin_expect(ix<0, 0))
                return (x-x)/(x-x);     /* log(-#) = NaN */
            k -= 25; x *= two25; /* subnormal number, scale up x */
index 6f55b4da6a9919b0544594d3b3c8a8d5c6c73d70..bef2601bce7043ba93bb9542d78608105cf89a7d 100644 (file)
@@ -782,7 +782,7 @@ __ieee754_lgammal_r (_Float128 x, int *signgamp)
       q = -x;
       p = __floorl (q);
       if (p == q)
-       return (one / (p - p));
+       return (one / __fabsl (p - p));
       _Float128 halfp = p * L(0.5);
       if (halfp == __floorl (halfp))
        *signgamp = -1;
index f73cd34ebb2e60d434fa2c69c0b9dbce22c48205..c992f6e5ee3556c0febf909852495069831445dc 100644 (file)
@@ -187,7 +187,7 @@ __ieee754_log10l (_Float128 x)
 /* Test for domain */
   GET_LDOUBLE_WORDS64 (hx, lx, x);
   if (((hx & 0x7fffffffffffffffLL) | lx) == 0)
-    return (-1 / (x - x));
+    return (-1 / __fabsl (x));         /* log10l(+-0)=-inf  */
   if (hx < 0)
     return (x - x) / (x - x);
   if (hx >= 0x7fff000000000000LL)
index 26a8d7e6faed10e3282b57e046b8756ff13d7fd4..cf4a380f16e5751a99adb6f9662295262ee5eb9b 100644 (file)
@@ -181,7 +181,7 @@ __ieee754_log2l (_Float128 x)
 /* Test for domain */
   GET_LDOUBLE_WORDS64 (hx, lx, x);
   if (((hx & 0x7fffffffffffffffLL) | lx) == 0)
-    return (-1 / (x - x));
+    return (-1 / __fabsl (x));         /* log2l(+-0)=-inf  */
   if (hx < 0)
     return (x - x) / (x - x);
   if (hx >= 0x7fff000000000000LL)
index 7477791b77a7852ecca049798830ae9527864990..1fbfa48e13edea258a07eb45e4aaa2ea491f307d 100644 (file)
@@ -189,7 +189,7 @@ __ieee754_log10l (long double x)
   xhi = ldbl_high (x);
   EXTRACT_WORDS64 (hx, xhi);
   if ((hx & 0x7fffffffffffffffLL) == 0)
-    return (-1.0L / (x - x));
+    return (-1.0L / __fabsl (x));              /* log10l(+-0)=-inf  */
   if (hx < 0)
     return (x - x) / (x - x);
   if (hx >= 0x7ff0000000000000LL)
index e39eaba72a7fc941b2e4338a9dfbc094da6ebd33..c820dacf08478120dbcf3bf5d20df270909c2cc4 100644 (file)
@@ -183,7 +183,7 @@ __ieee754_log2l (long double x)
   xhi = ldbl_high (x);
   EXTRACT_WORDS64 (hx, xhi);
   if ((hx & 0x7fffffffffffffffLL) == 0)
-    return (-1.0L / (x - x));
+    return (-1.0L / __fabsl (x));              /* log2l(+-0)=-inf  */
   if (hx < 0)
     return (x - x) / (x - x);
   if (hx >= 0x7ff0000000000000LL)