diff mbox

[PR,57363] IBM long double: adding qNaN and number raises inexact exception

Message ID 528A6D9E.8090705@linux.vnet.ibm.com
State New
Headers show

Commit Message

Adhemerval Zanella Nov. 18, 2013, 7:42 p.m. UTC
On 15-11-2013 19:54, Ulrich Weigand wrote:
> Should this be qNaN instead of sNaN here?

Yes, indeed.

>
> Also, since you already have a test case, I think it would be good to add it
> to the GCC test suite ...
>
> Otherwise, this looks reasonable to me (but I cannot approve the patch):
>
> Bye,
> Ulrich
>
Here it is with updated ChangeLog. Tested on PPC32 and PPC64. The testcase
fails at runtime without the fix with a FLoating-Point Exception.

---

2013-11-15  Adhemerval Zanella  <azanella@linux.vnet.ibm.com>

	* libgcc/config/rs6000/ibm-ldouble.c (__gcc_qadd): Fix add
 	of normal number and qNaN to not raise an inexact exception.
	* gcc/testsuite/gcc.target/powerpc/pr57363.c: New file: check for
	PR#57363.

--
diff mbox

Patch

diff --git a/gcc/testsuite/gcc.target/powerpc/pr57363.c b/gcc/testsuite/gcc.target/powerpc/pr57363.c
new file mode 100644
index 0000000..cc9b1d7
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/pr57363.c
@@ -0,0 +1,19 @@ 
+/* { dg-do run { target { powerpc*-*-linux* } } } */
+/* { dg-options "-mlong-double-128" } */
+
+/* Check if adding a sNAN and a normal long double does not generate a
+   inexact exception.  */
+
+#define _GNU_SOURCE
+#include <fenv.h>
+
+int main(void)
+{
+  double x = __builtin_nan ("");
+  long double y = 1.1L;
+
+  feenableexcept (FE_INEXACT);
+  feclearexcept (FE_ALL_EXCEPT);
+  x = x + y;
+  return fetestexcept(FE_INEXACT);
+}
diff --git a/libgcc/config/rs6000/ibm-ldouble.c b/libgcc/config/rs6000/ibm-ldouble.c
index 28e02e9..7ca900c 100644
--- a/libgcc/config/rs6000/ibm-ldouble.c
+++ b/libgcc/config/rs6000/ibm-ldouble.c
@@ -104,6 +104,8 @@  __gcc_qadd (double a, double aa, double c, double cc)
 
   if (nonfinite (z))
     {
+      if (fabs (z) != inf())
+	return z;
       z = cc + aa + c + a;
       if (nonfinite (z))
 	return z;