public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Define TS 18661-1 CR_DECIMAL_DIG in <float.h>
@ 2016-09-09 21:15 Joseph Myers
  2016-09-15 13:14 ` Ping " Joseph Myers
  0 siblings, 1 reply; 3+ messages in thread
From: Joseph Myers @ 2016-09-09 21:15 UTC (permalink / raw)
  To: gcc-patches

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.  OK to commit?

gcc:
2016-09-09  Joseph Myers  <joseph@codesourcery.com>

	* ginclude/float.h [__STDC_WANT_IEC_60559_BFP_EXT__]
	(CR_DECIMAL_DIG): New macro.

gcc/testsuite:
2016-09-09  Joseph Myers  <joseph@codesourcery.com>

	* gcc.dg/cr-decimal-dig-1.c: New test.

Index: gcc/ginclude/float.h
===================================================================
--- gcc/ginclude/float.h	(revision 240048)
+++ gcc/ginclude/float.h	(working copy)
@@ -185,6 +185,13 @@
 
 #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.  */
Index: gcc/testsuite/gcc.dg/cr-decimal-dig-1.c
===================================================================
--- gcc/testsuite/gcc.dg/cr-decimal-dig-1.c	(nonexistent)
+++ gcc/testsuite/gcc.dg/cr-decimal-dig-1.c	(working copy)
@@ -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

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Ping Re: Define TS 18661-1 CR_DECIMAL_DIG in <float.h>
  2016-09-09 21:15 Define TS 18661-1 CR_DECIMAL_DIG in <float.h> Joseph Myers
@ 2016-09-15 13:14 ` Joseph Myers
  2016-09-19 20:54   ` Jeff Law
  0 siblings, 1 reply; 3+ messages in thread
From: Joseph Myers @ 2016-09-15 13:14 UTC (permalink / raw)
  To: gcc-patches

Ping.  This patch 
<https://gcc.gnu.org/ml/gcc-patches/2016-09/msg00546.html> is pending 
review.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Ping Re: Define TS 18661-1 CR_DECIMAL_DIG in <float.h>
  2016-09-15 13:14 ` Ping " Joseph Myers
@ 2016-09-19 20:54   ` Jeff Law
  0 siblings, 0 replies; 3+ messages in thread
From: Jeff Law @ 2016-09-19 20:54 UTC (permalink / raw)
  To: Joseph Myers, gcc-patches

On 09/15/2016 06:56 AM, Joseph Myers wrote:
> Ping.  This patch
> <https://gcc.gnu.org/ml/gcc-patches/2016-09/msg00546.html> is pending
> review.
I suspect you know more about this than anyone else here, so ISTM you're 
the authority on correctness.

Rubber stamp OK. :-)

jeff

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-09-19 20:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-09 21:15 Define TS 18661-1 CR_DECIMAL_DIG in <float.h> Joseph Myers
2016-09-15 13:14 ` Ping " Joseph Myers
2016-09-19 20:54   ` Jeff Law

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).