diff options
author | Joseph Myers <joseph@codesourcery.com> | 2016-09-19 22:53:30 +0100 |
---|---|---|
committer | Joseph Myers <jsm28@gcc.gnu.org> | 2016-09-19 22:53:30 +0100 |
commit | 1f2071fafdcde5ae2cbff7336b28f43510d78419 (patch) | |
tree | ecf2e5e975a48025cf658592f3b195f1d7698743 | |
parent | 63012d9a57edc950c5f30242d1e19318b5708060 (diff) | |
download | gcc-1f2071fafdcde5ae2cbff7336b28f43510d78419.zip gcc-1f2071fafdcde5ae2cbff7336b28f43510d78419.tar.gz gcc-1f2071fafdcde5ae2cbff7336b28f43510d78419.tar.bz2 |
Define TS 18661-1 CR_DECIMAL_DIG in <float.h>.
TS 18661-1 defines a macro CR_DECIMAL_DIG in <float.h>, for the number
of decimal digits for which conversions between decimal character
strings and (IEEE) binary formats, in both directions, are correctly
rounded. This patch implements support for this macro in GCC's
<float.h>.
The definition __UINTMAX_MAX__ is the right one for GCC's conversions
of floating constants, since I made those use MPFR to make them
correctly rounding. The macro also covers standard library functions
such as strtod and printf. The definition is also correct for current
glibc. If any targets' libcs support correct rounding in a way that
conforms to TS 18661-1 with a smaller value of CR_DECIMAL_DIG, making
<float.h> reflect that could not be done in isolation without changes
to the interpretation of floating constants as well, since a smaller
CR_DECIMAL_DIG requires double rounding of floating constants (first
to CR_DECIMAL_DIG decimal digits, then to the desired binary format).
Boostrapped with no regressions on x86_64-pc-linux-gnu.
gcc:
* ginclude/float.h [__STDC_WANT_IEC_60559_BFP_EXT__]
(CR_DECIMAL_DIG): New macro.
gcc/testsuite:
* gcc.dg/cr-decimal-dig-1.c: New test.
From-SVN: r240249
-rw-r--r-- | gcc/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/ginclude/float.h | 7 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/cr-decimal-dig-1.c | 14 |
4 files changed, 30 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e3ec20e..3b5fc9c 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,10 @@ 2016-09-19 Joseph Myers <joseph@codesourcery.com> + * ginclude/float.h [__STDC_WANT_IEC_60559_BFP_EXT__] + (CR_DECIMAL_DIG): New macro. + +2016-09-19 Joseph Myers <joseph@codesourcery.com> + * ginclude/stddef.h (max_align_t) [__i386__]: Add __float128 element. diff --git a/gcc/ginclude/float.h b/gcc/ginclude/float.h index de46a27..421f735 100644 --- a/gcc/ginclude/float.h +++ b/gcc/ginclude/float.h @@ -185,6 +185,13 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #endif /* C11 */ +#ifdef __STDC_WANT_IEC_60559_BFP_EXT__ +/* Number of decimal digits for which conversions between decimal + character strings and binary formats, in both directions, are + correctly rounded. */ +#define CR_DECIMAL_DIG __UINTMAX_MAX__ +#endif + #ifdef __STDC_WANT_IEC_60559_TYPES_EXT__ /* Constants for _FloatN and _FloatNx types from TS 18661-3. See comments above for their semantics. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 741ec97..c825702 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,9 @@ 2016-09-19 Joseph Myers <joseph@codesourcery.com> + * gcc.dg/cr-decimal-dig-1.c: New test. + +2016-09-19 Joseph Myers <joseph@codesourcery.com> + * gcc.dg/float128-align.c, gcc.dg/float128x-align.c, gcc.dg/float16-align.c, gcc.dg/float32-align.c, gcc.dg/float32x-align.c, gcc.dg/float64-align.c, diff --git a/gcc/testsuite/gcc.dg/cr-decimal-dig-1.c b/gcc/testsuite/gcc.dg/cr-decimal-dig-1.c new file mode 100644 index 0000000..2bbc40c --- /dev/null +++ b/gcc/testsuite/gcc.dg/cr-decimal-dig-1.c @@ -0,0 +1,14 @@ +/* Test TS 18661-1 CR_DECIMAL_DIG. */ +/* { dg-do compile } */ +/* { dg-options "-std=c11" } */ + +#define __STDC_WANT_IEC_60559_BFP_EXT__ +#include <float.h> + +#ifndef CR_DECIMAL_DIG +#error "CR_DECIMAL_DIG not defined" +#endif + +#if CR_DECIMAL_DIG < DECIMAL_DIG + 3 +#error "CR_DECIMAL_DIG too small" +#endif |