Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:51438 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 84960 invoked from network); 8 Feb 2011 23:43:10 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Feb 2011 23:43:10 -0000 Authentication-Results: pb1.pair.com smtp.mail=glopes@nebm.ist.utl.pt; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=glopes@nebm.ist.utl.pt; sender-id=unknown Received-SPF: error (pb1.pair.com: domain nebm.ist.utl.pt from 193.136.128.21 cause and error) X-PHP-List-Original-Sender: glopes@nebm.ist.utl.pt X-Host-Fingerprint: 193.136.128.21 smtp1.ist.utl.pt Linux 2.6 Received: from [193.136.128.21] ([193.136.128.21:42959] helo=smtp1.ist.utl.pt) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 05/BB-18268-A05D15D4 for ; Tue, 08 Feb 2011 18:43:07 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp1.ist.utl.pt (Postfix) with ESMTP id 324507000438 for ; Tue, 8 Feb 2011 23:43:03 +0000 (WET) X-Virus-Scanned: by amavisd-new-2.6.4 (20090625) (Debian) at ist.utl.pt Received: from smtp1.ist.utl.pt ([127.0.0.1]) by localhost (smtp1.ist.utl.pt [127.0.0.1]) (amavisd-new, port 10025) with LMTP id 3mQoymyUtbok for ; Tue, 8 Feb 2011 23:43:02 +0000 (WET) Received: from mail2.ist.utl.pt (mail.ist.utl.pt [IPv6:2001:690:2100:1::8]) by smtp1.ist.utl.pt (Postfix) with ESMTP id E3F377000428 for ; Tue, 8 Feb 2011 23:43:02 +0000 (WET) Received: from damnation (damnation-air.dulce.lo.geleia.net [IPv6:2001:470:94a2:2:dc38:b9de:61a9:b30]) (Authenticated sender: ist155741) by mail2.ist.utl.pt (Postfix) with ESMTPSA id 615692007982 for ; Tue, 8 Feb 2011 23:43:02 +0000 (WET) Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes To: internals@lists.php.net References: <843E1DDB7AB24D9FA8F05801FE45202A@pc> Date: Tue, 08 Feb 2011 23:43:00 -0000 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Organization: =?utf-8?Q?N=C3=BAcleo_de_Eng=2E_Biom=C3=A9di?= =?utf-8?Q?ca_do_I=2ES=2ET=2E?= Message-ID: In-Reply-To: User-Agent: Opera Mail/11.01 (Linux) Subject: Re: [PHP-DEV] Change default serialize precision from 100 to 17 From: glopes@nebm.ist.utl.pt ("Gustavo Lopes") On Tue, 08 Feb 2011 20:05:05 -0000, Nicolas Grekas wrote: >> ini_set('precision', 17); > > After some testings, here is what I get : > > > ini_set('precision', 14); > echo 0.1; // 0.1 > echo 0.2; // 0.2 > echo 0.3; // 0.3 > > ini_set('precision', 17); > echo 0.2; // 0.10000000000000001 > echo 0.2; // 0.20000000000000001 > echo 0.3; // 0.29999999999999999 > > > The default precision of 14 (or 12) must have been chosen to address > this overlong string representation of many simple floats ? > While I agree with you that any data loss must be forbidden, couldn't > this also break existing code ? Yes, I think it's dangerous to change the default display precision lest we have a ton of applications that currently show 0.2 showing 0.20000000000000001. > Would it be possible to "displays a value based on the shortest > decimal fraction that rounds correctly back to the true binary value", > like python 2.7 and 3.1 do ? > (http://docs.python.org/tutorial/floatingpoint.html) > This may be a good idea for trunk, but I don't think it's feasible for 5.3 for the same reason. Showing "shortest decimal fraction that rounds correctly back to the true binary value" works fine for numbers that are directly input, where the only error is the normal rounding error (i.e., total uncertainty for x is x*2^-53). Once you start making calculations with the numbers the errors start being propagated, so in these scenarios you would still end up with a lot more "ugly" string representations that you have today with the default display precision. I agree that the information loss in e.g. PDO must be fixed, but it seems more appropriate to fix those problems by forcing another precision only in those cases. -- Gustavo Lopes