PR c/39035
authorjanis <janis@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 6 Feb 2009 21:01:46 +0000 (21:01 +0000)
committerjanis <janis@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 6 Feb 2009 21:01:46 +0000 (21:01 +0000)
* real.c (do_compare): Special-case compare of zero against
decimal float value.

* gcc.dg/dfp/pr39035.c: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@143992 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/real.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/dfp/pr39035.c [new file with mode: 0644]

index fcbe406..1e45010 100644 (file)
@@ -1,3 +1,9 @@
+2009-02-06  Janis Johnson  <janis187@us.ibm.com>
+
+       PR c/39035
+       * real.c (do_compare): Special-case compare of zero against
+       decimal float value.
+
 2009-02-06  Joseph Myers  <joseph@codesourcery.com>
 
        PR c/36432
index d26b0cb..29fee83 100644 (file)
@@ -905,15 +905,23 @@ do_compare (const REAL_VALUE_TYPE *a, const REAL_VALUE_TYPE *b,
       /* Sign of zero doesn't matter for compares.  */
       return 0;
 
+    case CLASS2 (rvc_normal, rvc_zero):
+      /* Decimal float zero is special and uses rvc_normal, not rvc_zero.  */
+      if (a->decimal)
+       return decimal_do_compare (a, b, nan_result);
+      /* Fall through.  */
     case CLASS2 (rvc_inf, rvc_zero):
     case CLASS2 (rvc_inf, rvc_normal):
-    case CLASS2 (rvc_normal, rvc_zero):
       return (a->sign ? -1 : 1);
 
     case CLASS2 (rvc_inf, rvc_inf):
       return -a->sign - -b->sign;
 
     case CLASS2 (rvc_zero, rvc_normal):
+      /* Decimal float zero is special and uses rvc_normal, not rvc_zero.  */
+      if (b->decimal)
+       return decimal_do_compare (a, b, nan_result);
+      /* Fall through.  */
     case CLASS2 (rvc_zero, rvc_inf):
     case CLASS2 (rvc_normal, rvc_inf):
       return (b->sign ? 1 : -1);
index f88b297..bf0aca7 100644 (file)
@@ -1,3 +1,8 @@
+2009-02-06  Janis Johnson  <janis187@us.ibm.com>
+
+       PR c/39035
+       * gcc.dg/dfp/pr39035.c: New test.
+
 2009-02-06  Joseph Myers  <joseph@codesourcery.com>
 
        PR c/36432
diff --git a/gcc/testsuite/gcc.dg/dfp/pr39035.c b/gcc/testsuite/gcc.dg/dfp/pr39035.c
new file mode 100644 (file)
index 0000000..2d44e06
--- /dev/null
@@ -0,0 +1,81 @@
+/* { dg-do run } */
+/* { dg-options "-std=gnu99 -O" } */
+
+/* DFP TR 24732 == WG14 / N1176, N1312 */
+/* Based on a test from Fred Tydeman.  */
+
+extern void abort (void);
+int failures = 0;
+
+#ifdef DBG
+#include <stdio.h>
+#define FAILURE(MSG) { printf ("line %d: %s\n", __LINE__, MSG); failures++; }
+#else
+#define FAILURE(MSG) failures++;
+#endif
+
+/* Test runtime computations.  */
+
+void
+runtime32 (void)
+{
+  volatile _Decimal32 d;
+  d = 0.0DF;
+  if (d)
+    FAILURE ("0.0DF should be zero")
+}
+
+void
+runtime64 (void)
+{
+  volatile _Decimal64 d;
+  d = 0.0DD;
+  if (d)
+    FAILURE ("0.0DD should be zero")
+}
+
+void
+runtime128 (void)
+{
+  volatile _Decimal128 d;
+  d = 0.0DL;
+  if (d)
+    FAILURE ("0.0DL should be zero")
+}
+
+void
+fold32 (void)
+{
+  if (0.0DF)
+    FAILURE ("0.0DF should be zero")
+}
+
+void
+fold64 (void)
+{
+  if (0.0DD)
+    FAILURE ("0.0DD should be zero")
+}
+
+void
+fold128 (void)
+{
+  if (0.0DL)
+    FAILURE ("0.0DL should be zero")
+}
+
+int
+main(void)
+{
+  runtime32 ();
+  runtime64 ();
+  runtime128 ();
+
+  fold32 ();
+  fold64 ();
+  fold128 ();
+
+  if (failures != 0)
+    abort ();
+  return 0;
+}