Patchwork [C++,/,RFC] PR 33067

login
register
mail settings
Submitter Paolo Carlini
Date Oct. 11, 2011, 10:57 a.m.
Message ID <4E94210A.3060502@oracle.com>
Download mbox | patch
Permalink /patch/118929/
State New
Headers show

Comments

Paolo Carlini - Oct. 11, 2011, 10:57 a.m.
On 10/11/2011 03:04 AM, Jason Merrill wrote:
> On 10/10/2011 12:40 PM, Paolo Carlini wrote:
>> +  // The fraction 643/2136 approximates log10(2) to 7 significant 
>> digits.
>> +  int max_digits10 = 2 + (is_decimal ? fmt->p : fmt->p * 643L / 2136);
>
> Please cite N1822 in the comment and convert it to C syntax.  OK with 
> that change.
Thanks. The below is what I actually applied.

Paolo.

/////////////////
2011-10-11  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/33067
	* c-family/c-pretty-print.c (pp_c_floating_constant): Output
	max_digits10 (in the ISO C++ WG N1822 sense) decimal digits.

Patch

Index: c-family/c-pretty-print.c
===================================================================
--- c-family/c-pretty-print.c	(revision 179792)
+++ c-family/c-pretty-print.c	(working copy)
@@ -1018,8 +1018,20 @@  pp_c_enumeration_constant (c_pretty_printer *pp, t
 static void
 pp_c_floating_constant (c_pretty_printer *pp, tree r)
 {
+  const struct real_format *fmt
+    = REAL_MODE_FORMAT (TYPE_MODE (TREE_TYPE (r)));
+
+  REAL_VALUE_TYPE floating_cst = TREE_REAL_CST (r);
+  bool is_decimal = floating_cst.decimal;
+
+  /* See ISO C++ WG N1822.  Note: The fraction 643/2136 approximates
+     log10(2) to 7 significant digits.  */
+  int max_digits10 = 2 + (is_decimal ? fmt->p : fmt->p * 643L / 2136);
+
   real_to_decimal (pp_buffer (pp)->digit_buffer, &TREE_REAL_CST (r),
-		   sizeof (pp_buffer (pp)->digit_buffer), 0, 1);
+		   sizeof (pp_buffer (pp)->digit_buffer),
+		   max_digits10, 1);
+
   pp_string (pp, pp_buffer(pp)->digit_buffer);
   if (TREE_TYPE (r) == float_type_node)
     pp_character (pp, 'f');