===================================================================
@@ -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');