From patchwork Tue Oct 11 10:57:14 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 118929 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 2CC87B6F72 for ; Tue, 11 Oct 2011 21:59:16 +1100 (EST) Received: (qmail 349 invoked by alias); 11 Oct 2011 10:59:14 -0000 Received: (qmail 335 invoked by uid 22791); 11 Oct 2011 10:59:13 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from rcsinet15.oracle.com (HELO rcsinet15.oracle.com) (148.87.113.117) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 11 Oct 2011 10:58:59 +0000 Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238]) by rcsinet15.oracle.com (Switch-3.4.4/Switch-3.4.4) with ESMTP id p9BAwrBh003758 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 11 Oct 2011 10:58:55 GMT Received: from acsmt358.oracle.com (acsmt358.oracle.com [141.146.40.158]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id p9BAwqOg012453 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 11 Oct 2011 10:58:52 GMT Received: from abhmt111.oracle.com (abhmt111.oracle.com [141.146.116.63]) by acsmt358.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id p9BAwjEv010760; Tue, 11 Oct 2011 05:58:45 -0500 Received: from [192.168.1.4] (/79.43.213.58) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 11 Oct 2011 03:58:45 -0700 Message-ID: <4E94210A.3060502@oracle.com> Date: Tue, 11 Oct 2011 12:57:14 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20110929 Thunderbird/7.0.1 MIME-Version: 1.0 To: Jason Merrill CC: "gcc-patches@gcc.gnu.org" , "Joseph S. Myers" , Gabriel Dos Reis Subject: Re: [C++ Patch / RFC] PR 33067 References: <4E92D995.2070907@oracle.com> <4E939620.7010707@redhat.com> In-Reply-To: <4E939620.7010707@redhat.com> X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org 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 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. 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');