http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57363
Bug ID: 57363
Summary: IBM long double: adding NaN and number raises inexact
exception
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: azanella at linux dot vnet.ibm.com
For IBM long double, adding a normal number to a NaN raises an inexact
exception. Adding any number to NaN should not raise any exception. The
following testcase triggers the issue (the testcase is meant to run a gnu
compatible libc):
--------------------------------------------------------------
$ cat gcc_testcase.c
#include <math.h>
#include <fenv.h>
#include <stdio.h>
double
sum (double x, long double y)
{
return x + y;
}
int main ()
{
feenableexcept (FE_INEXACT);
double x = __builtin_nan ("");
long double y = 1.1L;
printf ("%e\n", sum (x, y));
return 0;
}
$ gcc -O3 -m64 -fno-inline gcc_testcase.c -o gcc_testcase -lm
$ ./gcc_testcase
Floating point exception (core dumped)
--------------------------------------------------------------
The issue is in __gcc_qadd implementation at
libgcc/config/rs6000/ibm-ldouble.c,
if the number if non finite, there is not check if it a NaN before actually
summing all the components. A possible solution would be to add an extra test
and return the first sum if the number if not infinity:
Index: libgcc/config/rs6000/ibm-ldouble.c
===================================================================
--- libgcc/config/rs6000/ibm-ldouble.c (revision 199159)
+++ libgcc/config/rs6000/ibm-ldouble.c (working copy)
@@ -104,6 +104,8 @@
if (nonfinite (z))
{
+ if (z != inf())
+ return z;
z = cc + aa + c + a;
if (nonfinite (z))
return z;