diff mbox

Fix ldbl-128ibm nearbyintl use of signaling comparisons on NaNs (bug 18857)

Message ID alpine.DEB.2.10.1509152048320.16292@digraph.polyomino.org.uk
State New
Headers show

Commit Message

Joseph Myers Sept. 15, 2015, 8:49 p.m. UTC
The ldbl-128ibm implementation of nearbyintl wrongly uses signaling
comparisons such as "if (fabs (u.d[0].d) < TWO52)" on arguments that
might be NaNs, when "invalid" exceptions should not be raised.  (For
hard float, this issue may be hidden by
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58684>, powerpc GCC
wrongly only using unordered comparison instructions.)  This patch
fixes this by just returning the argument if it is not finite (because
of the arbitrary value of the low part of a NaN in IBM long double,
there are quite a lot of comparisons that could end up involving a NaN
when the argument to nearbyintl is a NaN, so excluding NaN arguments
at the start is the simplest and safest fix).

Tested for powerpc-nofpu, where it removes failures for spurious
"invalid" exceptions from nearbyintl.

2015-09-15  Joseph Myers  <joseph@codesourcery.com>

	[BZ #18857]
	* sysdeps/ieee754/ldbl-128ibm/s_nearbyintl.c (__nearbyintl): Just
	return non-finite argument without doing ordered comparisons on
	it.
diff mbox

Patch

diff --git a/sysdeps/ieee754/ldbl-128ibm/s_nearbyintl.c b/sysdeps/ieee754/ldbl-128ibm/s_nearbyintl.c
index 5f92a5f..99f4747 100644
--- a/sysdeps/ieee754/ldbl-128ibm/s_nearbyintl.c
+++ b/sysdeps/ieee754/ldbl-128ibm/s_nearbyintl.c
@@ -36,7 +36,9 @@  __nearbyintl (long double x)
   union ibm_extended_long_double u;
   u.ld = x;
 
-  if (fabs (u.d[0].d) < TWO52)
+  if (!isfinite (u.d[0].d))
+    return x;
+  else if (fabs (u.d[0].d) < TWO52)
     {
       double xh = u.d[0].d;
       double high = u.d[0].d;