]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
PowerPC: Fix nearbyintl failure for few inputs
authorRajalakshmi Srinivasaraghavan <raji@linux.vnet.ibm.com>
Tue, 17 Jun 2014 13:46:25 +0000 (08:46 -0500)
committerAdhemerval Zanella <azanella@linux.vnet.ibm.com>
Thu, 28 Aug 2014 13:25:47 +0000 (09:25 -0400)
This patch fixes few failures in nearbyintl() where the fraction part is
close to 0.5.i  The new tests added report few extra failures in
nearbyint_downward and nearbyint_towardzero which is a known issue.

Fixes #17031.

This is a backport of 754c5a08aacb44895d1ab97c553ce424eb43f761.

ChangeLog
NEWS
math/libm-test.inc
sysdeps/ieee754/ldbl-128ibm/s_nearbyintl.c

index a8a24b512783f3e205251ae5fabd784d9aa01b18..95dcce84ac7db12e77d605d928f0fba67eed894b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2014-16-17  Rajalakshmi Srinivasaraghavan <raji@linux.vnet.ibm.com>
+
+       [BZ #17031]
+       * sysdeps/ieee754/ldbl-128ibm/s_nearbyintl.c: Consider the low
+       double, adjusted for any remainder from the high double.
+       * math/libm-test.inc (nearbyint): Add tests.
+       (rint): Likewise.
+
 2014-06-11  Vidya Ranganathan  <vidya@linux.vnet.ibm.com>
 
        * sysdeps/powerpc/powerpc64/power7/strcmp.S: New file: Optimization.
diff --git a/NEWS b/NEWS
index 99bda3c9b89d4a6389d10f880c1d2976690b9d4e..96b7621c0f2e34f71adb2f1f740d768ee932e8e4 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -9,7 +9,8 @@ Version 2.19.1
 
 * The following bugs are resolved with this release:
 
-  16545, 16683, 16689, 16701, 16706, 16707, 16739, 16815, 16619, 16740.
+  16545, 16683, 16689, 16701, 16706, 16707, 16739, 16815, 16619, 16740,
+  17031.
 \f
 Version 2.19
 
index 1c5c022f4f6c6282e858dc34ff20de59e95d3335..848b89ee7b86ec5865a371a04759bbaded604e2e 100644 (file)
@@ -10519,6 +10519,10 @@ static const struct test_f_f_data nearbyint_test_data[] =
     TEST_f_f (nearbyint,  34503599627370498.515625L, 34503599627370499.0L),
     TEST_f_f (nearbyint, -34503599627370498.515625L, -34503599627370499.0L),
 # if LDBL_MANT_DIG >= 106
+    TEST_f_f (nearbyint, 1024.5000000000001L, 1025.0L, NO_INEXACT_EXCEPTION),
+    TEST_f_f (nearbyint, 1025.5000000000001L, 1026.0L, NO_INEXACT_EXCEPTION),
+    TEST_f_f (nearbyint, -1024.5000000000001L, -1025.0L, NO_INEXACT_EXCEPTION),
+    TEST_f_f (nearbyint, -1025.5000000000001L, -1026.0L, NO_INEXACT_EXCEPTION),
     TEST_f_f (nearbyint,  1192568192774434123539907640624.484375L, 1192568192774434123539907640624.0L),
     TEST_f_f (nearbyint, -1192568192774434123539907640624.484375L, -1192568192774434123539907640624.0L),
 # endif
@@ -11335,6 +11339,10 @@ static const struct test_f_f_data rint_test_data[] =
     TEST_f_f (rint, 4503599627370497.5L, 4503599627370498.0L, INEXACT_EXCEPTION),
 
 # if LDBL_MANT_DIG > 100
+    TEST_f_f (rint, 1024.5000000000001L, 1025.0L, INEXACT_EXCEPTION),
+    TEST_f_f (rint, 1025.5000000000001L, 1026.0L, INEXACT_EXCEPTION),
+    TEST_f_f (rint, -1024.5000000000001L, -1025.0L, INEXACT_EXCEPTION),
+    TEST_f_f (rint, -1025.5000000000001L, -1026.0L, INEXACT_EXCEPTION),
     TEST_f_f (rint, 4503599627370494.5000000000001L, 4503599627370495.0L, INEXACT_EXCEPTION),
     TEST_f_f (rint, 4503599627370495.5000000000001L, 4503599627370496.0L, INEXACT_EXCEPTION),
     TEST_f_f (rint, 4503599627370496.5000000000001L, 4503599627370497.0L, INEXACT_EXCEPTION),
index 4e997a68f9a70d139da9b6001efdbf5664f708fc..8f34604f54cc1d0c21c3193030d1d9939182660a 100644 (file)
@@ -38,6 +38,7 @@ __nearbyintl (long double x)
 
   if (fabs (u.d[0].d) < TWO52)
     {
+      double xh = u.d[0].d;
       double high = u.d[0].d;
       feholdexcept (&env);
       if (high > 0.0)
@@ -52,6 +53,10 @@ __nearbyintl (long double x)
          high += TWO52;
           if (high == 0.0) high = -0.0;
        }
+      if (u.d[1].d > 0.0 && (xh - high == 0.5))
+        high += 1.0;
+      else if (u.d[1].d < 0.0 && (-(xh - high) == 0.5))
+        high -= 1.0;
       u.d[0].d = high;
       u.d[1].d = 0.0;
       math_force_eval (u.d[0]);