]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Fix log (1) in round-downward mode (bug 16731).
authorJoseph Myers <joseph@codesourcery.com>
Fri, 21 Mar 2014 18:13:58 +0000 (18:13 +0000)
committerJoseph Myers <joseph@codesourcery.com>
Fri, 21 Mar 2014 18:13:58 +0000 (18:13 +0000)
According to ISO C Annex F, log (1) should be +0 in all rounding
modes, but some implementations in glibc wrongly return -0 in
round-downward mode (mapping to log1p (x - 1) is problematic because 1
- 1 is -0 in round-downward mode, and log1p (-0) is -0).  This patch
fixes this.  (It helps with some implementations of other functions
such as acosh, log2 and log10 that call out to log, but not enough to
enable all-rounding-modes testing for those functions without further
fixes to other implementations of them.)

Tested x86_64 and x86 and ulps updated accordingly, and did spot tests
for mips64 for the ldbl-128 fix, and i586 for the sysdeps/i386/fpu
implementations shadowed by those in sysdeps/i386/i686/fpu.

[BZ #16731]
* sysdeps/i386/fpu/e_log.S (__ieee754_log): Take absolute value
when x - 1 is zero.
* sysdeps/i386/fpu/e_logf.S (__ieee754_logf): Likewise.
* sysdeps/i386/fpu/e_logl.S (__ieee754_logl): Likewise.
* sysdeps/i386/i686/fpu/e_logl.S (__ieee754_logl): Likewise.
* sysdeps/ieee754/dbl-64/e_log.c (__ieee754_log): Return +0 when
argument is 1.
* sysdeps/ieee754/ldbl-128/e_logl.c (__ieee754_logl): Likewise.
* sysdeps/x86_64/fpu/e_logl.S: Take absolute value when x - 1 is
zero.
* math/libm-test.inc (log_test): Use ALL_RM_TEST.
* sysdeps/i386/fpu/libm-test-ulps: Update.
* sysdeps/x86_64/fpu/libm-test-ulps: Likewise.

12 files changed:
ChangeLog
NEWS
math/libm-test.inc
sysdeps/i386/fpu/e_log.S
sysdeps/i386/fpu/e_logf.S
sysdeps/i386/fpu/e_logl.S
sysdeps/i386/fpu/libm-test-ulps
sysdeps/i386/i686/fpu/e_logl.S
sysdeps/ieee754/dbl-64/e_log.c
sysdeps/ieee754/ldbl-128/e_logl.c
sysdeps/x86_64/fpu/e_logl.S
sysdeps/x86_64/fpu/libm-test-ulps

index f8f87bdb06e48743bc5a6050e867bb8881a09da9..e3601495d02751fdbee8872c4a7d504fb84caa9a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2014-03-21  Joseph Myers  <joseph@codesourcery.com>
+
+       [BZ #16731]
+       * sysdeps/i386/fpu/e_log.S (__ieee754_log): Take absolute value
+       when x - 1 is zero.
+       * sysdeps/i386/fpu/e_logf.S (__ieee754_logf): Likewise.
+       * sysdeps/i386/fpu/e_logl.S (__ieee754_logl): Likewise.
+       * sysdeps/i386/i686/fpu/e_logl.S (__ieee754_logl): Likewise.
+       * sysdeps/ieee754/dbl-64/e_log.c (__ieee754_log): Return +0 when
+       argument is 1.
+       * sysdeps/ieee754/ldbl-128/e_logl.c (__ieee754_logl): Likewise.
+       * sysdeps/x86_64/fpu/e_logl.S: Take absolute value when x - 1 is
+       zero.
+       * math/libm-test.inc (log_test): Use ALL_RM_TEST.
+       * sysdeps/i386/fpu/libm-test-ulps: Update.
+       * sysdeps/x86_64/fpu/libm-test-ulps: Likewise.
+
 2014-03-21  Siddhesh Poyarekar  <siddhesh@redhat.com>
 
        * scripts/bench.pl: Remove file.
diff --git a/NEWS b/NEWS
index 5f9ffcc569f310fc26e955a71e523850b7653193..5df0277beeeb616015fac527a1540f18442a93ae 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -11,7 +11,7 @@ Version 2.20
 
   15347, 15804, 15894, 16447, 16532, 16545, 16574, 16600, 16609, 16610,
   16611, 16613, 16623, 16632, 16639, 16642, 16649, 16670, 16674, 16677,
-  16680, 16683, 16689, 16695, 16701, 16706, 16707.
+  16680, 16683, 16689, 16695, 16701, 16706, 16707, 16731.
 
 * Running the testsuite no longer terminates as soon as a test fails.
   Instead, a file tests.sum (xtests.sum from "make xcheck") is generated,
index 7abc7c14b5c2eff3e48b42ae2a76e568a57533d3..5e50f0ee3dcfbb7e827967a5419e712e6aa11bae 100644 (file)
@@ -7786,9 +7786,7 @@ static const struct test_f_f_data log_test_data[] =
 static void
 log_test (void)
 {
-  START (log, 0);
-  RUN_TEST_LOOP_f_f (log, log_test_data, );
-  END;
+  ALL_RM_TEST (log, 0, log_test_data, RUN_TEST_LOOP_f_f, END);
 }
 
 
index 087792499817d4e911a029520ea142046166fbcb..3fa32aad3c0e7bfb77e37e6389c6b6aef105fcee 100644 (file)
@@ -46,7 +46,13 @@ ENTRY(__ieee754_log)
        fnstsw                  // x-1 : x : log(2)
        andb    $0x45, %ah
        jz      2f
-       fstp    %st(1)          // x-1 : log(2)
+       fxam
+       fnstsw
+       andb    $0x45, %ah
+       cmpb    $0x40, %ah
+       jne     5f
+       fabs                    // log(1) is +0 in all rounding modes.
+5:     fstp    %st(1)          // x-1 : log(2)
        fyl2xp1                 // log(x)
        ret
 
index 485180e9096eaa82d91d90fd9bdaa5339ef3dd74..ca83d39cef3139292454a72bb464060afc63aa61 100644 (file)
@@ -47,7 +47,13 @@ ENTRY(__ieee754_logf)
        fnstsw                  // x-1 : x : log(2)
        andb    $0x45, %ah
        jz      2f
-       fstp    %st(1)          // x-1 : log(2)
+       fxam
+       fnstsw
+       andb    $0x45, %ah
+       cmpb    $0x40, %ah
+       jne     5f
+       fabs                    // log(1) is +0 in all rounding modes.
+5:     fstp    %st(1)          // x-1 : log(2)
        fyl2xp1                 // log(x)
        ret
 
index d7a459a6270b83a9927d6577665873bd2dbe5d76..edae1d70df8a3331d806b2cab3c528b1f4c5e77c 100644 (file)
@@ -47,7 +47,13 @@ ENTRY(__ieee754_logl)
        fnstsw                  // x-1 : x : log(2)
        andb    $0x45, %ah
        jz      2f
-       fstp    %st(1)          // x-1 : log(2)
+       fxam
+       fnstsw
+       andb    $0x45, %ah
+       cmpb    $0x40, %ah
+       jne     5f
+       fabs                    // log(1) is +0 in all rounding modes.
+5:     fstp    %st(1)          // x-1 : log(2)
        fyl2xp1                 // log(x)
        ret
 
index 3be1806826d071b92c2033f2893545fa7d7459f2..b7b2e12b5474d2deec5e495b42d8279a5b8adcf0 100644 (file)
@@ -1096,6 +1096,18 @@ Function: "log1p":
 ildouble: 1
 ldouble: 1
 
+Function: "log_downward":
+ildouble: 1
+ldouble: 1
+
+Function: "log_towardzero":
+ildouble: 1
+ldouble: 1
+
+Function: "log_upward":
+ildouble: 1
+ldouble: 1
+
 Function: "pow":
 ildouble: 1
 ldouble: 1
index 8a86222b1351e478536cfb7c2f9fd360596fdc45..a0d1107dc066e6dfd4174bd7ffeceb9d20a971a5 100644 (file)
@@ -46,7 +46,13 @@ ENTRY(__ieee754_logl)
        fcomip  %st(1)          // |x-1| : x-1 : x : log(2)
        fstp    %st(0)          // x-1 : x : log(2)
        jc      2f
-       fstp    %st(1)          // x-1 : log(2)
+       fxam
+       fnstsw
+       andb    $0x45, %ah
+       cmpb    $0x40, %ah
+       jne     4f
+       fabs                    // log(1) is +0 in all rounding modes.
+4:     fstp    %st(1)          // x-1 : log(2)
        fyl2xp1                 // log(x)
        ret
 
index 05d318b786e5d1881d555ce80b55d032687fdcb1..4ecd3722f5b369fb26a788a4073565e97bef95ba 100644 (file)
@@ -96,6 +96,10 @@ __ieee754_log (double x)
   if (__glibc_likely (ABS (w) > U03))
     goto case_03;
 
+  /* log (1) is +0 in all rounding modes.  */
+  if (w == 0.0)
+    return 0.0;
+
   /*--- Stage I, the case abs(x-1) < 0.03 */
 
   t8 = MHALF * w;
index 3d1034dd6198e4f9167ab3b751711e42d3f4f8bc..cb4381679334d2a7f618d9286afbd7a160e8bad3 100644 (file)
@@ -240,6 +240,8 @@ __ieee754_logl(long double x)
   /* On this interval the table is not used due to cancellation error.  */
   if ((x <= 1.0078125L) && (x >= 0.9921875L))
     {
+      if (x == 1.0L)
+       return 0.0L;
       z = x - 1.0L;
       k = 64;
       t.value  = 1.0L;
index a8e31084babe8a2890f1e9f41f2299379ed43015..315afc00338cb4b4c20fea93185ae8ab048b648f 100644 (file)
@@ -45,7 +45,13 @@ ENTRY(__ieee754_logl)
        fnstsw                  // x-1 : x : log(2)
        andb    $0x45, %ah
        jz      2f
-       fstp    %st(1)          // x-1 : log(2)
+       fxam
+       fnstsw
+       andb    $0x45, %ah
+       cmpb    $0x40, %ah
+       jne     5f
+       fabs                    // log(1) is +0 in all rounding modes.
+5:     fstp    %st(1)          // x-1 : log(2)
        fyl2xp1                 // log(x)
        ret
 
index 5f4ab06050dedd5de95772f642c02e3721b88ab8..301eaa6542738c139042ebbbb8119299d39e5845 100644 (file)
@@ -1170,6 +1170,22 @@ ifloat: 1
 ildouble: 1
 ldouble: 1
 
+Function: "log_downward":
+float: 1
+ifloat: 1
+ildouble: 1
+ldouble: 1
+
+Function: "log_towardzero":
+ildouble: 1
+ldouble: 1
+
+Function: "log_upward":
+float: 1
+ifloat: 1
+ildouble: 1
+ldouble: 1
+
 Function: "pow":
 float: 1
 ifloat: 1