re PR c++/33067 (Awkward long decimal expansion for double literal in error.)
authorPaolo Carlini <paolo.carlini@oracle.com>
Tue, 11 Oct 2011 10:57:40 +0000 (10:57 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Tue, 11 Oct 2011 10:57:40 +0000 (10:57 +0000)
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.

From-SVN: r179797

gcc/ChangeLog
gcc/c-family/c-pretty-print.c

index bd97d6d885815fb3fb923d6a05d83e2412b72e94..e83c515eb52502d400dc6f56adf817edc285a82b 100644 (file)
@@ -1,3 +1,9 @@
+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.
+
 2011-10-11  Richard Sandiford  <richard.sandiford@linaro.org>
 
        * modulo-sched.c: Fix comment typo.  Mention the possibility
index 53d39d643d08e425d2162d5ba75320baf55c8c26..91195613ff12abbbdc58213c4809bb379bfb58ab 100644 (file)
@@ -1018,8 +1018,20 @@ pp_c_enumeration_constant (c_pretty_printer *pp, tree e)
 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');