public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/54036] New: Negating a DFP NAN in C++ produces NAN not -NAN
@ 2012-07-19 20:46 bergner at gcc dot gnu.org
  2012-07-24 21:08 ` [Bug libstdc++/54036] " bergner at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: bergner at gcc dot gnu.org @ 2012-07-19 20:46 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 54036
           Summary: Negating a DFP NAN in C++ produces NAN not -NAN
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: bergner@gcc.gnu.org
        ReportedBy: bergner@gcc.gnu.org
            Target: powerpc*-linux, x86*-linux


When negating a DFP NaN, we produce another NaN and not a -NaN like we do when
using a C test case or with binary floating point (C or C++).  This happens on
both my power64-linux and x86_64-linux systems.

bergner@bns:~> cat dfp-nan.C 
#include <stdio.h>
#include <decimal/decimal>
using namespace std;

decimal::decimal64
my_nan (void)
{
  decimal::decimal64 z = 0.0DD;
  decimal::decimal64 v = z/z;
  return v;
}

int
main (void)
{
  decimal::decimal64 v;
  v = my_nan ();
  printf ("value is %Dg\n", v);
  v = -v;
  printf ("-value is %Dg\n", v);
  return 0;
}
bergner@bns:~> g++ dfp-nan.C -ldfp
bergner@bns:~> ./a.out 
value is nan
-value is nan

The problem seems to be due to the following lines in
libstdc++-v3/include/decimal/decimal.h:

#define _DEFINE_DECIMAL_UNARY_OP(_Op, _Tp)      \
  inline _Tp operator _Op(_Tp __rhs)            \
  {                                             \
    _Tp __tmp;                                  \
    __tmp.__setval(0 _Op __rhs.__getval());     \
    return __tmp;                               \
  }

  _DEFINE_DECIMAL_UNARY_OP(+, decimal32)
  _DEFINE_DECIMAL_UNARY_OP(+, decimal64)
  _DEFINE_DECIMAL_UNARY_OP(+, decimal128)
  _DEFINE_DECIMAL_UNARY_OP(-, decimal32)
  _DEFINE_DECIMAL_UNARY_OP(-, decimal64)
  _DEFINE_DECIMAL_UNARY_OP(-, decimal128)

This causes us to compute a "0 - nan" rather than a "-nan" and "0 - nan" will
not produce a -nan.  The following change fixes the problem for me:

-    __tmp.__setval(0 _Op __rhs.__getval());    \
+    __tmp.__setval(_Op __rhs.__getval());    \


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

* [Bug libstdc++/54036] Negating a DFP NAN in C++ produces NAN not -NAN
  2012-07-19 20:46 [Bug c++/54036] New: Negating a DFP NAN in C++ produces NAN not -NAN bergner at gcc dot gnu.org
@ 2012-07-24 21:08 ` bergner at gcc dot gnu.org
  2012-07-25 17:02 ` bergner at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: bergner at gcc dot gnu.org @ 2012-07-24 21:08 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Peter Bergner <bergner at gcc dot gnu.org> 2012-07-24 21:07:58 UTC ---
Author: bergner
Date: Tue Jul 24 21:07:53 2012
New Revision: 189824

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=189824
Log:
    Backport prospective patch from mainline

libstdc++-v3/
        PR libstdc++/54036
        * include/decimal/decimal.h (_DEFINE_DECIMAL_UNARY_OP): Use _Op as
        a unary operator.

gcc/testsuite/
        PR libstdc++/54036
        * g++.dg/dfp/pr54036-1.C: New test.
        * g++.dg/dfp/pr54036-2.C: Likewise.
        * g++.dg/dfp/pr54036-3.C: Likewise.

Added:
    branches/ibm/gcc-4_7-branch/gcc/testsuite/g++.dg/dfp/pr54036-1.C
    branches/ibm/gcc-4_7-branch/gcc/testsuite/g++.dg/dfp/pr54036-2.C
    branches/ibm/gcc-4_7-branch/gcc/testsuite/g++.dg/dfp/pr54036-3.C
    branches/ibm/gcc-4_7-branch/libstdc++-v3/ChangeLog.ibm
Modified:
    branches/ibm/gcc-4_7-branch/gcc/testsuite/ChangeLog.ibm
    branches/ibm/gcc-4_7-branch/libstdc++-v3/include/decimal/decimal.h


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

* [Bug libstdc++/54036] Negating a DFP NAN in C++ produces NAN not -NAN
  2012-07-19 20:46 [Bug c++/54036] New: Negating a DFP NAN in C++ produces NAN not -NAN bergner at gcc dot gnu.org
  2012-07-24 21:08 ` [Bug libstdc++/54036] " bergner at gcc dot gnu.org
@ 2012-07-25 17:02 ` bergner at gcc dot gnu.org
  2012-08-06 18:00 ` paolo at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: bergner at gcc dot gnu.org @ 2012-07-25 17:02 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Peter Bergner <bergner at gcc dot gnu.org> 2012-07-25 17:02:39 UTC ---
Author: bergner
Date: Wed Jul 25 17:02:27 2012
New Revision: 189857

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=189857
Log:
    Backport prospective patch from mainline

libstdc++-v3/
        PR libstdc++/54036
        * include/decimal/decimal.h (_DEFINE_DECIMAL_UNARY_OP): Use _Op as
        a unary operator.

gcc/testsuite/
        PR libstdc++/54036
        * g++.dg/dfp/pr54036-1.C: New test.
        * g++.dg/dfp/pr54036-2.C: Likewise.
        * g++.dg/dfp/pr54036-3.C: Likewise.

Added:
    branches/ibm/gcc-4_6-branch/gcc/testsuite/g++.dg/dfp/pr54036-1.C
    branches/ibm/gcc-4_6-branch/gcc/testsuite/g++.dg/dfp/pr54036-2.C
    branches/ibm/gcc-4_6-branch/gcc/testsuite/g++.dg/dfp/pr54036-3.C
Modified:
    branches/ibm/gcc-4_6-branch/gcc/testsuite/ChangeLog.ibm
    branches/ibm/gcc-4_6-branch/libstdc++-v3/ChangeLog.ibm
    branches/ibm/gcc-4_6-branch/libstdc++-v3/include/decimal/decimal.h


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

* [Bug libstdc++/54036] Negating a DFP NAN in C++ produces NAN not -NAN
  2012-07-19 20:46 [Bug c++/54036] New: Negating a DFP NAN in C++ produces NAN not -NAN bergner at gcc dot gnu.org
  2012-07-24 21:08 ` [Bug libstdc++/54036] " bergner at gcc dot gnu.org
  2012-07-25 17:02 ` bergner at gcc dot gnu.org
@ 2012-08-06 18:00 ` paolo at gcc dot gnu.org
  2012-08-06 18:07 ` paolo.carlini at oracle dot com
  2012-08-06 18:07 ` paolo at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: paolo at gcc dot gnu.org @ 2012-08-06 18:00 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from paolo at gcc dot gnu.org <paolo at gcc dot gnu.org> 2012-08-06 18:00:11 UTC ---
Author: paolo
Date: Mon Aug  6 18:00:00 2012
New Revision: 190185

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=190185
Log:
2012-08-06  Peter Bergner  <bergner@vnet.ibm.com>

    PR libstdc++/54036
    * include/decimal/decimal.h (_DEFINE_DECIMAL_UNARY_OP): Use _Op as
    a unary operator.
    * testsuite/decimal/pr54036-1.cc: New test.
    * testsuite/decimal/pr54036-2.cc: Likewise.
    * testsuite/decimal/pr54036-3.cc: Likewise.

Added:
    branches/gcc-4_7-branch/libstdc++-v3/testsuite/decimal/pr54036-1.cc
    branches/gcc-4_7-branch/libstdc++-v3/testsuite/decimal/pr54036-2.cc
    branches/gcc-4_7-branch/libstdc++-v3/testsuite/decimal/pr54036-3.cc
Modified:
    branches/gcc-4_7-branch/libstdc++-v3/ChangeLog
    branches/gcc-4_7-branch/libstdc++-v3/include/decimal/decimal.h


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

* [Bug libstdc++/54036] Negating a DFP NAN in C++ produces NAN not -NAN
  2012-07-19 20:46 [Bug c++/54036] New: Negating a DFP NAN in C++ produces NAN not -NAN bergner at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2012-08-06 18:00 ` paolo at gcc dot gnu.org
@ 2012-08-06 18:07 ` paolo.carlini at oracle dot com
  2012-08-06 18:07 ` paolo at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-08-06 18:07 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.7.2

--- Comment #5 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-08-06 18:07:35 UTC ---
Fixed mainline and 4.7.2.


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

* [Bug libstdc++/54036] Negating a DFP NAN in C++ produces NAN not -NAN
  2012-07-19 20:46 [Bug c++/54036] New: Negating a DFP NAN in C++ produces NAN not -NAN bergner at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2012-08-06 18:07 ` paolo.carlini at oracle dot com
@ 2012-08-06 18:07 ` paolo at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: paolo at gcc dot gnu.org @ 2012-08-06 18:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from paolo at gcc dot gnu.org <paolo at gcc dot gnu.org> 2012-08-06 18:06:46 UTC ---
Author: paolo
Date: Mon Aug  6 18:06:42 2012
New Revision: 190186

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=190186
Log:
2012-08-06  Paolo Carlini  <paolo.carlini@oracle.com>

    * testsuite/decimal/mixed-mode-cmp_neg.cc: Add test variable; minor
    tweaks.
    * testsuite/decimal/unary-arith.cc: Likewise.
    * testsuite/decimal/ctor.cc: Likewise.
    * testsuite/decimal/conversion-to-integral.cc: Likewise.
    * testsuite/decimal/make-decimal.cc: Likewise.
    * testsuite/decimal/comparison.cc: Likewise.
    * testsuite/decimal/incdec-memfunc.cc: Likewise.
    * testsuite/decimal/conversion-to-generic-float.cc: Likewise.
    * testsuite/decimal/compound-assignment-memfunc.cc: Likewise.
    * testsuite/decimal/cast_neg.cc: Likewise.
    * testsuite/decimal/incdec.cc: Likewise.
    * testsuite/decimal/mixed-mode-arith_neg.cc: Likewise.
    * testsuite/decimal/binary-arith.cc: Likewise.
    * testsuite/decimal/conversion-from-float.cc: Likewise.
    * testsuite/decimal/conversion-from-integral.cc: Likewise.
    * testsuite/decimal/compound-assignment.cc: Likewise.

2012-08-06  Peter Bergner  <bergner@vnet.ibm.com>

    PR libstdc++/54036
    * include/decimal/decimal.h (_DEFINE_DECIMAL_UNARY_OP): Use _Op as
    a unary operator.
    * testsuite/decimal/pr54036-1.cc: New test.
    * testsuite/decimal/pr54036-2.cc: Likewise.
    * testsuite/decimal/pr54036-3.cc: Likewise.

Added:
    trunk/libstdc++-v3/testsuite/decimal/pr54036-1.cc
    trunk/libstdc++-v3/testsuite/decimal/pr54036-2.cc
    trunk/libstdc++-v3/testsuite/decimal/pr54036-3.cc
Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/include/decimal/decimal.h
    trunk/libstdc++-v3/testsuite/decimal/binary-arith.cc
    trunk/libstdc++-v3/testsuite/decimal/cast_neg.cc
    trunk/libstdc++-v3/testsuite/decimal/comparison.cc
    trunk/libstdc++-v3/testsuite/decimal/compound-assignment-memfunc.cc
    trunk/libstdc++-v3/testsuite/decimal/compound-assignment.cc
    trunk/libstdc++-v3/testsuite/decimal/conversion-from-float.cc
    trunk/libstdc++-v3/testsuite/decimal/conversion-from-integral.cc
    trunk/libstdc++-v3/testsuite/decimal/conversion-to-generic-float.cc
    trunk/libstdc++-v3/testsuite/decimal/conversion-to-integral.cc
    trunk/libstdc++-v3/testsuite/decimal/ctor.cc
    trunk/libstdc++-v3/testsuite/decimal/incdec-memfunc.cc
    trunk/libstdc++-v3/testsuite/decimal/incdec.cc
    trunk/libstdc++-v3/testsuite/decimal/make-decimal.cc
    trunk/libstdc++-v3/testsuite/decimal/mixed-mode-arith_neg.cc
    trunk/libstdc++-v3/testsuite/decimal/mixed-mode-cmp_neg.cc
    trunk/libstdc++-v3/testsuite/decimal/unary-arith.cc


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

end of thread, other threads:[~2012-08-06 18:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-19 20:46 [Bug c++/54036] New: Negating a DFP NAN in C++ produces NAN not -NAN bergner at gcc dot gnu.org
2012-07-24 21:08 ` [Bug libstdc++/54036] " bergner at gcc dot gnu.org
2012-07-25 17:02 ` bergner at gcc dot gnu.org
2012-08-06 18:00 ` paolo at gcc dot gnu.org
2012-08-06 18:07 ` paolo.carlini at oracle dot com
2012-08-06 18:07 ` paolo 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).