diff options
author | Joseph Myers <joseph@codesourcery.com> | 2005-07-29 22:14:22 +0100 |
---|---|---|
committer | Joseph Myers <jsm28@gcc.gnu.org> | 2005-07-29 22:14:22 +0100 |
commit | bc1594c1428a6202a739b157bcdd0f4db2c5faf7 (patch) | |
tree | 5016d5b89f3bdb36574cad26940fb18ba94a1653 /gcc | |
parent | 3aca4bff532e98480b7a9e9b41b9df608bd90fed (diff) | |
download | gcc-bc1594c1428a6202a739b157bcdd0f4db2c5faf7.zip gcc-bc1594c1428a6202a739b157bcdd0f4db2c5faf7.tar.gz gcc-bc1594c1428a6202a739b157bcdd0f4db2c5faf7.tar.bz2 |
re PR middle-end/21720 (GCC incorrectly rounds hex floats)
PR c/21720
* real.c (real_from_string): Also set last bit if there is a
nonzero hex digit beyond GCC's internal precision after ".".
testsuite:
* gcc.dg/hex-round-1.c: Test more cases.
* gcc.dg/hex-round-2.c: New test.
From-SVN: r102567
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/real.c | 4 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/hex-round-1.c | 82 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/hex-round-2.c | 114 |
5 files changed, 212 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 980c491..781ab8b 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2005-07-29 Joseph S. Myers <joseph@codesourcery.com> + + PR c/21720 + * real.c (real_from_string): Also set last bit if there is a + nonzero hex digit beyond GCC's internal precision after ".". + 2005-07-29 David Edelsohn <edelsohn@gnu.org> * config/rs6000/altivec.md: Convert UNSPEC numerical values to @@ -1815,6 +1815,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; str++; } } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index aa60bc1..9516f68 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2005-07-29 Joseph S. Myers <joseph@codesourcery.com> + + PR c/21720 + * gcc.dg/hex-round-1.c: Test more cases. + * gcc.dg/hex-round-2.c: New test. + 2005-07-29 Diego Novillo <dnovillo@redhat.com> PR 22550 diff --git a/gcc/testsuite/gcc.dg/hex-round-1.c b/gcc/testsuite/gcc.dg/hex-round-1.c index 1ce9c35..3276ad4 100644 --- a/gcc/testsuite/gcc.dg/hex-round-1.c +++ b/gcc/testsuite/gcc.dg/hex-round-1.c @@ -10,6 +10,64 @@ int main (void) { #if FLT_RADIX == 2 && FLT_MANT_DIG == 24 + if (0x1.0000011p0f == 1) + link_failure (); + if (0x1.00000101p0f == 1) + link_failure (); + if (0x1.000001001p0f == 1) + link_failure (); + if (0x1.0000010001p0f == 1) + link_failure (); + if (0x1.00000100001p0f == 1) + link_failure (); + if (0x1.000001000001p0f == 1) + link_failure (); + if (0x1.0000010000001p0f == 1) + link_failure (); + if (0x1.00000100000001p0f == 1) + link_failure (); + if (0x1.000001000000001p0f == 1) + link_failure (); + if (0x1.0000010000000001p0f == 1) + link_failure (); + if (0x1.00000100000000001p0f == 1) + link_failure (); + if (0x1.000001000000000001p0f == 1) + link_failure (); + if (0x1.0000010000000000001p0f == 1) + link_failure (); + if (0x1.00000100000000000001p0f == 1) + link_failure (); + if (0x1.000001000000000000001p0f == 1) + link_failure (); + if (0x1.0000010000000000000001p0f == 1) + link_failure (); + if (0x1.00000100000000000000001p0f == 1) + link_failure (); + if (0x1.000001000000000000000001p0f == 1) + link_failure (); + if (0x1.0000010000000000000000001p0f == 1) + link_failure (); + if (0x1.00000100000000000000000001p0f == 1) + link_failure (); + if (0x1.000001000000000000000000001p0f == 1) + link_failure (); + if (0x1.0000010000000000000000000001p0f == 1) + link_failure (); + if (0x1.00000100000000000000000000001p0f == 1) + link_failure (); + if (0x1.000001000000000000000000000001p0f == 1) + link_failure (); + if (0x1.0000010000000000000000000000001p0f == 1) + link_failure (); + if (0x1.00000100000000000000000000000001p0f == 1) + link_failure (); + if (0x1.000001000000000000000000000000001p0f == 1) + link_failure (); + if (0x1.0000010000000000000000000000000001p0f == 1) + link_failure (); + if (0x1.00000100000000000000000000000000001p0f == 1) + link_failure (); if (0x1.000001000000000000000000000000000001p0f == 1) link_failure (); if (0x1.0000010000000000000000000000000000001p0f == 1) @@ -26,6 +84,30 @@ main (void) link_failure (); if (0x1.0000010000000000000000000000000000000000001p0f == 1) link_failure (); + if (0x1.00000100000000000000000000000000000000000001p0f == 1) + link_failure (); + if (0x1.000001000000000000000000000000000000000000001p0f == 1) + link_failure (); + if (0x1.0000010000000000000000000000000000000000000001p0f == 1) + link_failure (); + if (0x1.00000100000000000000000000000000000000000000001p0f == 1) + link_failure (); + if (0x1.000001000000000000000000000000000000000000000001p0f == 1) + link_failure (); + if (0x1.0000010000000000000000000000000000000000000000001p0f == 1) + link_failure (); + if (0x1.00000100000000000000000000000000000000000000000001p0f == 1) + link_failure (); + if (0x1.000001000000000000000000000000000000000000000000001p0f == 1) + link_failure (); + if (0x1.0000010000000000000000000000000000000000000000000001p0f == 1) + link_failure (); + if (0x1.00000100000000000000000000000000000000000000000000001p0f == 1) + link_failure (); + if (0x1.000001000000000000000000000000000000000000000000000001p0f == 1) + link_failure (); + if (0x1.0000010000000000000000000000000000000000000000000000001p0f == 1) + link_failure (); #endif return 0; } diff --git a/gcc/testsuite/gcc.dg/hex-round-2.c b/gcc/testsuite/gcc.dg/hex-round-2.c new file mode 100644 index 0000000..ba9b8bf --- /dev/null +++ b/gcc/testsuite/gcc.dg/hex-round-2.c @@ -0,0 +1,114 @@ +/* Test for hexadecimal float rounding: bug 21720. Test with no "." + in number. */ +/* { 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 (0x10000011p-28f == 1) + link_failure (); + if (0x100000101p-32f == 1) + link_failure (); + if (0x1000001001p-36f == 1) + link_failure (); + if (0x10000010001p-40f == 1) + link_failure (); + if (0x100000100001p-44f == 1) + link_failure (); + if (0x1000001000001p-48f == 1) + link_failure (); + if (0x10000010000001p-52f == 1) + link_failure (); + if (0x100000100000001p-56f == 1) + link_failure (); + if (0x1000001000000001p-60f == 1) + link_failure (); + if (0x10000010000000001p-64f == 1) + link_failure (); + if (0x100000100000000001p-68f == 1) + link_failure (); + if (0x1000001000000000001p-72f == 1) + link_failure (); + if (0x10000010000000000001p-76f == 1) + link_failure (); + if (0x100000100000000000001p-80f == 1) + link_failure (); + if (0x1000001000000000000001p-84f == 1) + link_failure (); + if (0x10000010000000000000001p-88f == 1) + link_failure (); + if (0x100000100000000000000001p-92f == 1) + link_failure (); + if (0x1000001000000000000000001p-96f == 1) + link_failure (); + if (0x10000010000000000000000001p-100f == 1) + link_failure (); + if (0x100000100000000000000000001p-104f == 1) + link_failure (); + if (0x1000001000000000000000000001p-108f == 1) + link_failure (); + if (0x10000010000000000000000000001p-112f == 1) + link_failure (); + if (0x100000100000000000000000000001p-116f == 1) + link_failure (); + if (0x1000001000000000000000000000001p-120f == 1) + link_failure (); + if (0x10000010000000000000000000000001p-124f == 1) + link_failure (); + if (0x100000100000000000000000000000001p-128f == 1) + link_failure (); + if (0x1000001000000000000000000000000001p-132f == 1) + link_failure (); + if (0x10000010000000000000000000000000001p-136f == 1) + link_failure (); + if (0x100000100000000000000000000000000001p-140f == 1) + link_failure (); + if (0x1000001000000000000000000000000000001p-144f == 1) + link_failure (); + if (0x10000010000000000000000000000000000001p-148f == 1) + link_failure (); + if (0x100000100000000000000000000000000000001p-152f == 1) + link_failure (); + if (0x1000001000000000000000000000000000000001p-156f == 1) + link_failure (); + if (0x10000010000000000000000000000000000000001p-160f == 1) + link_failure (); + if (0x100000100000000000000000000000000000000001p-164f == 1) + link_failure (); + if (0x1000001000000000000000000000000000000000001p-168f == 1) + link_failure (); + if (0x10000010000000000000000000000000000000000001p-172f == 1) + link_failure (); + if (0x100000100000000000000000000000000000000000001p-176f == 1) + link_failure (); + if (0x1000001000000000000000000000000000000000000001p-180f == 1) + link_failure (); + if (0x10000010000000000000000000000000000000000000001p-184f == 1) + link_failure (); + if (0x100000100000000000000000000000000000000000000001p-188f == 1) + link_failure (); + if (0x1000001000000000000000000000000000000000000000001p-192f == 1) + link_failure (); + if (0x10000010000000000000000000000000000000000000000001p-196f == 1) + link_failure (); + if (0x100000100000000000000000000000000000000000000000001p-200f == 1) + link_failure (); + if (0x1000001000000000000000000000000000000000000000000001p-204f == 1) + link_failure (); + if (0x10000010000000000000000000000000000000000000000000001p-208f == 1) + link_failure (); + if (0x100000100000000000000000000000000000000000000000000001p-212f == 1) + link_failure (); + if (0x1000001000000000000000000000000000000000000000000000001p-216f == 1) + link_failure (); + if (0x10000010000000000000000000000000000000000000000000000001p-220f == 1) + link_failure (); +#endif + return 0; +} |