re PR middle-end/21720 (GCC incorrectly rounds hex floats)
authorJoseph Myers <joseph@codesourcery.com>
Fri, 29 Jul 2005 01:24:38 +0000 (02:24 +0100)
committerJoseph Myers <jsm28@gcc.gnu.org>
Fri, 29 Jul 2005 01:24:38 +0000 (02:24 +0100)
PR c/21720
* real.c (real_from_string): Set last bit if there is a nonzero
hex digit beyond GCC's internal precision.

testsuite:
* gcc.dg/hex-round-1.c: New test.

From-SVN: r102539

gcc/ChangeLog
gcc/real.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/hex-round-1.c [new file with mode: 0644]

index 070443d860dbe2e4490f14339f48521ed2c25609..6f10df5e64e0c3d220b10c38707dd5d82027a09a 100644 (file)
@@ -1,3 +1,9 @@
+2005-07-29  Joseph S. Myers  <joseph@codesourcery.com>
+
+       PR c/21720
+       * real.c (real_from_string): Set last bit if there is a nonzero
+       hex digit beyond GCC's internal precision.
+
 2005-07-28  Richard Henderson  <rth@redhat.com>
 
        PR rtl-opt/22619
index 9099f410f8ddfb04c16b86ea36c8a2556d1225f9..045a803a59425747fc984960a8f12f1da26239ec 100644 (file)
@@ -1789,6 +1789,10 @@ real_from_string (REAL_VALUE_TYPE *r, const char *str)
                |= (unsigned long) d << (pos % HOST_BITS_PER_LONG);
              pos -= 4;
            }
+         else if (d)
+           /* Ensure correct rounding by setting last bit if there is
+              a subsequent nonzero digit.  */
+           r->sig[0] |= 1;
          exp += 4;
          str++;
        }
index a8badc528d3f815135b9284376bdfe046dfba137..45f6324e3a5e3c68f44e5f5b12a8c7afb9159332 100644 (file)
@@ -1,3 +1,8 @@
+2005-07-29  Joseph S. Myers  <joseph@codesourcery.com>
+
+       PR c/21720
+       * gcc.dg/hex-round-1.c: New test.
+
 2005-07-28  Jan Hubicka  <jh@suse.cz>
 
        * inliner-1.c: Do not dump everything.
diff --git a/gcc/testsuite/gcc.dg/hex-round-1.c b/gcc/testsuite/gcc.dg/hex-round-1.c
new file mode 100644 (file)
index 0000000..1ce9c35
--- /dev/null
@@ -0,0 +1,31 @@
+/* Test for hexadecimal float rounding: bug 21720.  */
+/* { dg-do link } */
+/* { dg-options "-O -std=gnu99" } */
+
+#include <float.h>
+
+extern void link_failure (void);
+
+int
+main (void)
+{
+#if FLT_RADIX == 2 && FLT_MANT_DIG == 24
+  if (0x1.000001000000000000000000000000000001p0f == 1)
+    link_failure ();
+  if (0x1.0000010000000000000000000000000000001p0f == 1)
+    link_failure ();
+  if (0x1.00000100000000000000000000000000000001p0f == 1)
+    link_failure ();
+  if (0x1.000001000000000000000000000000000000001p0f == 1)
+    link_failure ();
+  if (0x1.0000010000000000000000000000000000000001p0f == 1)
+    link_failure ();
+  if (0x1.00000100000000000000000000000000000000001p0f == 1)
+    link_failure ();
+  if (0x1.000001000000000000000000000000000000000001p0f == 1)
+    link_failure ();
+  if (0x1.0000010000000000000000000000000000000000001p0f == 1)
+    link_failure ();
+#endif
+  return 0;
+}