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

* [Bug target/57363] IBM long double: adding NaN and number raises inexact exception
  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 ` rth at gcc dot gnu.org
  2013-07-03 13:43 ` azanella at linux dot vnet.ibm.com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: rth at gcc dot gnu.org @ 2013-07-02 18:43 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57363

Richard Henderson <rth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rth at gcc dot gnu.org

--- Comment #1 from Richard Henderson <rth at gcc dot gnu.org> ---
(In reply to Adhemerval Zanella from comment #0)
> Adding any number to NaN should not raise any exception.

Not quite true -- QNaN should not raise any exception,
but SNaN should raise Invalid.


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

* [Bug target/57363] IBM long double: adding NaN and number raises inexact exception
  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
  3 siblings, 0 replies; 5+ messages in thread
From: azanella at linux dot vnet.ibm.com @ 2013-07-03 13:43 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57363

--- Comment #2 from Adhemerval Zanella <azanella at linux dot vnet.ibm.com> ---
You are correct and I meant in my first comment QNaN for the NaN work. And I
believe the patch is still correct: for IBM long double SNaN will be
represented
by first double being the NaN (the second double is ignored) and the first sum
(z = a + c) will trigger exception if any.


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

* [Bug target/57363] IBM long double: adding NaN and number raises inexact exception
  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
  3 siblings, 0 replies; 5+ messages in thread
From: uweigand at gcc dot gnu.org @ 2013-11-13 20:59 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57363

Ulrich Weigand <uweigand at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |uweigand at gcc dot gnu.org

--- Comment #3 from Ulrich Weigand <uweigand at gcc dot gnu.org> ---
Hi Adhemerval, I'm also seeing that this patch fixes some glibc failures.

What's the status of this?  Were you planning to submit it for inclusion?

B.t.w. I'm wondering if we don't need to use

+      if (fabs (z) != inf())
+       return z;

instead; z could still be minus infinity, right?


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

* [Bug target/57363] IBM long double: adding NaN and number raises inexact exception
  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
                   ` (2 preceding siblings ...)
  2013-11-13 20:59 ` uweigand at gcc dot gnu.org
@ 2013-12-03 19:00 ` uweigand at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: uweigand at gcc dot gnu.org @ 2013-12-03 19:00 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57363

Ulrich Weigand <uweigand at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |FIXED

--- Comment #4 from Ulrich Weigand <uweigand at gcc dot gnu.org> ---
Fixed.
http://gcc.gnu.org/ml/gcc-cvs/2013-12/msg00087.html


^ 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).