public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/57363] New: IBM long double: adding NaN and number raises inexact exception
@ 2013-05-21 19:42 azanella at linux dot vnet.ibm.com
  2013-07-02 18:43 ` [Bug target/57363] " rth at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: azanella at linux dot vnet.ibm.com @ 2013-05-21 19:42 UTC (permalink / raw)
  To: gcc-bugs

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;


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-12-03 19:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-21 19:42 [Bug target/57363] New: IBM long double: adding NaN and number raises inexact exception azanella at linux dot vnet.ibm.com
2013-07-02 18:43 ` [Bug target/57363] " rth at gcc dot gnu.org
2013-07-03 13:43 ` azanella at linux dot vnet.ibm.com
2013-11-13 20:59 ` uweigand at gcc dot gnu.org
2013-12-03 19:00 ` uweigand at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).