diff mbox

[BZ,#17031,PowerPC64] Fix nearbyintl failure for few inputs

Message ID 1402485135-72573-1-git-send-email-raji@linux.vnet.ibm.com
State New
Headers show

Commit Message

Rajalakshmi Srinivasaraghavan June 11, 2014, 11:12 a.m. UTC
This patch fixes few failures in nearbyintl() where the fraction part is close
to 0.5.The new tests added report few extra failures in nearbyint_downward and
nearbyint_towardzero which is a known issue.

	[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.

Signed-off-by: Rajalakshmi Srinivasaraghavan <raji@linux.vnet.ibm.com>
---
 NEWS                                       | 2 +-
 math/libm-test.inc                         | 8 ++++++++
 sysdeps/ieee754/ldbl-128ibm/s_nearbyintl.c | 5 +++++
 3 files changed, 14 insertions(+), 1 deletion(-)

Comments

Adhemerval Zanella June 17, 2014, 1:45 p.m. UTC | #1
Thanks Vidya, this patch looks ok. Joseph, do you have any more regards about this
change?


On 11-06-2014 08:12, Rajalakshmi Srinivasaraghavan wrote:
> This patch fixes few failures in nearbyintl() where the fraction part is close
> to 0.5.The new tests added report few extra failures in nearbyint_downward and
> nearbyint_towardzero which is a known issue.
>
> 	[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.
>
> Signed-off-by: Rajalakshmi Srinivasaraghavan <raji@linux.vnet.ibm.com>
> ---
>  NEWS                                       | 2 +-
>  math/libm-test.inc                         | 8 ++++++++
>  sysdeps/ieee754/ldbl-128ibm/s_nearbyintl.c | 5 +++++
>  3 files changed, 14 insertions(+), 1 deletion(-)
>
> diff --git a/NEWS b/NEWS
> index ca3ef63..066a2c8 100644
> --- a/NEWS
> +++ b/NEWS
> @@ -19,7 +19,7 @@ Version 2.20
>    16791, 16796, 16799, 16800, 16815, 16823, 16824, 16831, 16838, 16849,
>    16854, 16876, 16877, 16878, 16882, 16885, 16888, 16890, 16912, 16915,
>    16916, 16917, 16922, 16927, 16928, 16932, 16943, 16958, 16965, 16966,
> -  16967, 16977, 16978, 16984, 16990, 17009, 17042.
> +  16967, 16977, 16978, 16984, 16990, 17009, 17031, 17042.
>
>  * The minimum Linux kernel version that this version of the GNU C Library
>    can be used with is 2.6.32.
> diff --git a/math/libm-test.inc b/math/libm-test.inc
> index fa8e238..d98d85c 100644
> --- a/math/libm-test.inc
> +++ b/math/libm-test.inc
> @@ -8188,6 +8188,10 @@ static const struct test_f_f_data nearbyint_test_data[] =
>      TEST_f_f (nearbyint, 4503599627370496.75L, 4503599627370496.0L, NO_INEXACT_EXCEPTION, 4503599627370497.0L, NO_INEXACT_EXCEPTION, 4503599627370496.0L, NO_INEXACT_EXCEPTION, 4503599627370497.0L, NO_INEXACT_EXCEPTION),
>      TEST_f_f (nearbyint, 4503599627370497.5L, 4503599627370497.0L, NO_INEXACT_EXCEPTION, 4503599627370498.0L, NO_INEXACT_EXCEPTION, 4503599627370497.0L, NO_INEXACT_EXCEPTION, 4503599627370498.0L, NO_INEXACT_EXCEPTION),
>  # if LDBL_MANT_DIG > 100
> +    TEST_f_f (nearbyint, 1024.5000000000001L, 1024.0L, NO_INEXACT_EXCEPTION, 1025.0L, NO_INEXACT_EXCEPTION, 1024.0L, NO_INEXACT_EXCEPTION, 1025.0L, NO_INEXACT_EXCEPTION),
> +    TEST_f_f (nearbyint, 1025.5000000000001L, 1025.0L, NO_INEXACT_EXCEPTION, 1026.0L, NO_INEXACT_EXCEPTION, 1025.0L, NO_INEXACT_EXCEPTION, 1026.0L, NO_INEXACT_EXCEPTION),
> +    TEST_f_f (nearbyint, -1024.5000000000001L, -1025.0L, NO_INEXACT_EXCEPTION, -1025.0L, NO_INEXACT_EXCEPTION, -1024.0L, NO_INEXACT_EXCEPTION, -1024.0L, NO_INEXACT_EXCEPTION),
> +    TEST_f_f (nearbyint, -1025.5000000000001L, -1026.0L, NO_INEXACT_EXCEPTION, -1026.0L, NO_INEXACT_EXCEPTION, -1025.0L, NO_INEXACT_EXCEPTION, -1025.0L, NO_INEXACT_EXCEPTION),
>      TEST_f_f (nearbyint, 4503599627370494.5000000000001L, 4503599627370494.0L, NO_INEXACT_EXCEPTION, 4503599627370495.0L, NO_INEXACT_EXCEPTION, 4503599627370494.0L, NO_INEXACT_EXCEPTION, 4503599627370495.0L, NO_INEXACT_EXCEPTION),
>      TEST_f_f (nearbyint, 4503599627370495.5000000000001L, 4503599627370495.0L, NO_INEXACT_EXCEPTION, 4503599627370496.0L, NO_INEXACT_EXCEPTION, 4503599627370495.0L, NO_INEXACT_EXCEPTION, 4503599627370496.0L, NO_INEXACT_EXCEPTION),
>      TEST_f_f (nearbyint, 4503599627370496.5000000000001L, 4503599627370496.0L, NO_INEXACT_EXCEPTION, 4503599627370497.0L, NO_INEXACT_EXCEPTION, 4503599627370496.0L, NO_INEXACT_EXCEPTION, 4503599627370497.0L, NO_INEXACT_EXCEPTION),
> @@ -8890,6 +8894,10 @@ static const struct test_f_f_data rint_test_data[] =
>      TEST_f_f (rint, 4503599627370496.75L, 4503599627370496.0L, INEXACT_EXCEPTION, 4503599627370497.0L, INEXACT_EXCEPTION, 4503599627370496.0L, INEXACT_EXCEPTION, 4503599627370497.0L, INEXACT_EXCEPTION),
>      TEST_f_f (rint, 4503599627370497.5L, 4503599627370497.0L, INEXACT_EXCEPTION, 4503599627370498.0L, INEXACT_EXCEPTION, 4503599627370497.0L, INEXACT_EXCEPTION, 4503599627370498.0L, INEXACT_EXCEPTION),
>  # if LDBL_MANT_DIG > 100
> +    TEST_f_f (rint, 1024.5000000000001L, 1024.0L, INEXACT_EXCEPTION, 1025.0L, INEXACT_EXCEPTION, 1024.0L, INEXACT_EXCEPTION, 1025.0L, INEXACT_EXCEPTION),
> +    TEST_f_f (rint, 1025.5000000000001L, 1025.0L, INEXACT_EXCEPTION, 1026.0L, INEXACT_EXCEPTION, 1025.0L, INEXACT_EXCEPTION, 1026.0L, INEXACT_EXCEPTION),
> +    TEST_f_f (rint, -1024.5000000000001L, -1025.0L, INEXACT_EXCEPTION, -1025.0L, INEXACT_EXCEPTION, -1024.0L, INEXACT_EXCEPTION, -1024.0L, INEXACT_EXCEPTION),
> +    TEST_f_f (rint, -1025.5000000000001L, -1026.0L, INEXACT_EXCEPTION, -1026.0L, INEXACT_EXCEPTION, -1025.0L, INEXACT_EXCEPTION, -1025.0L, INEXACT_EXCEPTION),
>      TEST_f_f (rint, 4503599627370494.5000000000001L, 4503599627370494.0L, INEXACT_EXCEPTION, 4503599627370495.0L, INEXACT_EXCEPTION, 4503599627370494.0L, INEXACT_EXCEPTION, 4503599627370495.0L, INEXACT_EXCEPTION),
>      TEST_f_f (rint, 4503599627370495.5000000000001L, 4503599627370495.0L, INEXACT_EXCEPTION, 4503599627370496.0L, INEXACT_EXCEPTION, 4503599627370495.0L, INEXACT_EXCEPTION, 4503599627370496.0L, INEXACT_EXCEPTION),
>      TEST_f_f (rint, 4503599627370496.5000000000001L, 4503599627370496.0L, INEXACT_EXCEPTION, 4503599627370497.0L, INEXACT_EXCEPTION, 4503599627370496.0L, INEXACT_EXCEPTION, 4503599627370497.0L, INEXACT_EXCEPTION),
> diff --git a/sysdeps/ieee754/ldbl-128ibm/s_nearbyintl.c b/sysdeps/ieee754/ldbl-128ibm/s_nearbyintl.c
> index 4e997a6..8f34604 100644
> --- a/sysdeps/ieee754/ldbl-128ibm/s_nearbyintl.c
> +++ b/sysdeps/ieee754/ldbl-128ibm/s_nearbyintl.c
> @@ -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]);
Joseph Myers June 17, 2014, 2:25 p.m. UTC | #2
On Tue, 17 Jun 2014, Adhemerval Zanella wrote:

> Thanks Vidya, this patch looks ok. Joseph, do you have any more regards about this
> change?

I have no further comments on this patch.
Adhemerval Zanella June 17, 2014, 4:45 p.m. UTC | #3
On 17-06-2014 11:25, Joseph S. Myers wrote:
> On Tue, 17 Jun 2014, Adhemerval Zanella wrote:
>
>> Thanks Vidya, this patch looks ok. Joseph, do you have any more regards about this
>> change?
> I have no further comments on this patch.
>
Pushed upstream as 754c5a08aacb44895d1ab97c553ce424eb43f761.  Raij, don't forget
to close the bugzilla.
diff mbox

Patch

diff --git a/NEWS b/NEWS
index ca3ef63..066a2c8 100644
--- a/NEWS
+++ b/NEWS
@@ -19,7 +19,7 @@  Version 2.20
   16791, 16796, 16799, 16800, 16815, 16823, 16824, 16831, 16838, 16849,
   16854, 16876, 16877, 16878, 16882, 16885, 16888, 16890, 16912, 16915,
   16916, 16917, 16922, 16927, 16928, 16932, 16943, 16958, 16965, 16966,
-  16967, 16977, 16978, 16984, 16990, 17009, 17042.
+  16967, 16977, 16978, 16984, 16990, 17009, 17031, 17042.
 
 * The minimum Linux kernel version that this version of the GNU C Library
   can be used with is 2.6.32.
diff --git a/math/libm-test.inc b/math/libm-test.inc
index fa8e238..d98d85c 100644
--- a/math/libm-test.inc
+++ b/math/libm-test.inc
@@ -8188,6 +8188,10 @@  static const struct test_f_f_data nearbyint_test_data[] =
     TEST_f_f (nearbyint, 4503599627370496.75L, 4503599627370496.0L, NO_INEXACT_EXCEPTION, 4503599627370497.0L, NO_INEXACT_EXCEPTION, 4503599627370496.0L, NO_INEXACT_EXCEPTION, 4503599627370497.0L, NO_INEXACT_EXCEPTION),
     TEST_f_f (nearbyint, 4503599627370497.5L, 4503599627370497.0L, NO_INEXACT_EXCEPTION, 4503599627370498.0L, NO_INEXACT_EXCEPTION, 4503599627370497.0L, NO_INEXACT_EXCEPTION, 4503599627370498.0L, NO_INEXACT_EXCEPTION),
 # if LDBL_MANT_DIG > 100
+    TEST_f_f (nearbyint, 1024.5000000000001L, 1024.0L, NO_INEXACT_EXCEPTION, 1025.0L, NO_INEXACT_EXCEPTION, 1024.0L, NO_INEXACT_EXCEPTION, 1025.0L, NO_INEXACT_EXCEPTION),
+    TEST_f_f (nearbyint, 1025.5000000000001L, 1025.0L, NO_INEXACT_EXCEPTION, 1026.0L, NO_INEXACT_EXCEPTION, 1025.0L, NO_INEXACT_EXCEPTION, 1026.0L, NO_INEXACT_EXCEPTION),
+    TEST_f_f (nearbyint, -1024.5000000000001L, -1025.0L, NO_INEXACT_EXCEPTION, -1025.0L, NO_INEXACT_EXCEPTION, -1024.0L, NO_INEXACT_EXCEPTION, -1024.0L, NO_INEXACT_EXCEPTION),
+    TEST_f_f (nearbyint, -1025.5000000000001L, -1026.0L, NO_INEXACT_EXCEPTION, -1026.0L, NO_INEXACT_EXCEPTION, -1025.0L, NO_INEXACT_EXCEPTION, -1025.0L, NO_INEXACT_EXCEPTION),
     TEST_f_f (nearbyint, 4503599627370494.5000000000001L, 4503599627370494.0L, NO_INEXACT_EXCEPTION, 4503599627370495.0L, NO_INEXACT_EXCEPTION, 4503599627370494.0L, NO_INEXACT_EXCEPTION, 4503599627370495.0L, NO_INEXACT_EXCEPTION),
     TEST_f_f (nearbyint, 4503599627370495.5000000000001L, 4503599627370495.0L, NO_INEXACT_EXCEPTION, 4503599627370496.0L, NO_INEXACT_EXCEPTION, 4503599627370495.0L, NO_INEXACT_EXCEPTION, 4503599627370496.0L, NO_INEXACT_EXCEPTION),
     TEST_f_f (nearbyint, 4503599627370496.5000000000001L, 4503599627370496.0L, NO_INEXACT_EXCEPTION, 4503599627370497.0L, NO_INEXACT_EXCEPTION, 4503599627370496.0L, NO_INEXACT_EXCEPTION, 4503599627370497.0L, NO_INEXACT_EXCEPTION),
@@ -8890,6 +8894,10 @@  static const struct test_f_f_data rint_test_data[] =
     TEST_f_f (rint, 4503599627370496.75L, 4503599627370496.0L, INEXACT_EXCEPTION, 4503599627370497.0L, INEXACT_EXCEPTION, 4503599627370496.0L, INEXACT_EXCEPTION, 4503599627370497.0L, INEXACT_EXCEPTION),
     TEST_f_f (rint, 4503599627370497.5L, 4503599627370497.0L, INEXACT_EXCEPTION, 4503599627370498.0L, INEXACT_EXCEPTION, 4503599627370497.0L, INEXACT_EXCEPTION, 4503599627370498.0L, INEXACT_EXCEPTION),
 # if LDBL_MANT_DIG > 100
+    TEST_f_f (rint, 1024.5000000000001L, 1024.0L, INEXACT_EXCEPTION, 1025.0L, INEXACT_EXCEPTION, 1024.0L, INEXACT_EXCEPTION, 1025.0L, INEXACT_EXCEPTION),
+    TEST_f_f (rint, 1025.5000000000001L, 1025.0L, INEXACT_EXCEPTION, 1026.0L, INEXACT_EXCEPTION, 1025.0L, INEXACT_EXCEPTION, 1026.0L, INEXACT_EXCEPTION),
+    TEST_f_f (rint, -1024.5000000000001L, -1025.0L, INEXACT_EXCEPTION, -1025.0L, INEXACT_EXCEPTION, -1024.0L, INEXACT_EXCEPTION, -1024.0L, INEXACT_EXCEPTION),
+    TEST_f_f (rint, -1025.5000000000001L, -1026.0L, INEXACT_EXCEPTION, -1026.0L, INEXACT_EXCEPTION, -1025.0L, INEXACT_EXCEPTION, -1025.0L, INEXACT_EXCEPTION),
     TEST_f_f (rint, 4503599627370494.5000000000001L, 4503599627370494.0L, INEXACT_EXCEPTION, 4503599627370495.0L, INEXACT_EXCEPTION, 4503599627370494.0L, INEXACT_EXCEPTION, 4503599627370495.0L, INEXACT_EXCEPTION),
     TEST_f_f (rint, 4503599627370495.5000000000001L, 4503599627370495.0L, INEXACT_EXCEPTION, 4503599627370496.0L, INEXACT_EXCEPTION, 4503599627370495.0L, INEXACT_EXCEPTION, 4503599627370496.0L, INEXACT_EXCEPTION),
     TEST_f_f (rint, 4503599627370496.5000000000001L, 4503599627370496.0L, INEXACT_EXCEPTION, 4503599627370497.0L, INEXACT_EXCEPTION, 4503599627370496.0L, INEXACT_EXCEPTION, 4503599627370497.0L, INEXACT_EXCEPTION),
diff --git a/sysdeps/ieee754/ldbl-128ibm/s_nearbyintl.c b/sysdeps/ieee754/ldbl-128ibm/s_nearbyintl.c
index 4e997a6..8f34604 100644
--- a/sysdeps/ieee754/ldbl-128ibm/s_nearbyintl.c
+++ b/sysdeps/ieee754/ldbl-128ibm/s_nearbyintl.c
@@ -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]);