From 314b93ea9a11200b8b5480588f38d406cdb8d741 Mon Sep 17 00:00:00 2001 From: jsm28 Date: Fri, 29 Jul 2005 01:24:38 +0000 Subject: [PATCH] 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@102539 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 6 ++++++ gcc/real.c | 4 ++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/hex-round-1.c | 31 +++++++++++++++++++++++++++++++ 4 files changed, 46 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/hex-round-1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 070443d860d..6f10df5e64e 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2005-07-29 Joseph S. Myers + + 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 PR rtl-opt/22619 diff --git a/gcc/real.c b/gcc/real.c index 9099f410f8d..045a803a594 100644 --- a/gcc/real.c +++ b/gcc/real.c @@ -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++; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a8badc528d3..45f6324e3a5 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2005-07-29 Joseph S. Myers + + PR c/21720 + * gcc.dg/hex-round-1.c: New test. + 2005-07-28 Jan Hubicka * 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 index 00000000000..1ce9c35c0fa --- /dev/null +++ b/gcc/testsuite/gcc.dg/hex-round-1.c @@ -0,0 +1,31 @@ +/* Test for hexadecimal float rounding: bug 21720. */ +/* { dg-do link } */ +/* { dg-options "-O -std=gnu99" } */ + +#include + +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; +} -- 2.11.0