summaryrefslogtreecommitdiff
path: root/gcc/c-family/c-pretty-print.c
diff options
context:
space:
mode:
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2011-10-11 10:57:40 +0000
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2011-10-11 10:57:40 +0000
commitd4a627f3c9e95c844f08902a339cb5b092fa2e27 (patch)
treeaf6cc51f4876ec81b86bbe16b497e6e4e0cf52d8 /gcc/c-family/c-pretty-print.c
parentdc78196b1a0856aa5551fd449b960cc168041188 (diff)
downloadgcc-d4a627f3c9e95c844f08902a339cb5b092fa2e27.tar.gz
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@179797 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/c-family/c-pretty-print.c')
-rw-r--r--gcc/c-family/c-pretty-print.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/gcc/c-family/c-pretty-print.c b/gcc/c-family/c-pretty-print.c
index 53d39d643d0..91195613ff1 100644
--- a/gcc/c-family/c-pretty-print.c
+++ b/gcc/c-family/c-pretty-print.c
@@ -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');