Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:51437 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 81475 invoked from network); 8 Feb 2011 23:10:29 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Feb 2011 23:10:29 -0000 Authentication-Results: pb1.pair.com header.from=sv_forums@fmethod.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=sv_forums@fmethod.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain fmethod.com from 209.85.215.42 cause and error) X-PHP-List-Original-Sender: sv_forums@fmethod.com X-Host-Fingerprint: 209.85.215.42 mail-ew0-f42.google.com Received: from [209.85.215.42] ([209.85.215.42:45934] helo=mail-ew0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D1/3B-18268-36DC15D4 for ; Tue, 08 Feb 2011 18:10:28 -0500 Received: by ewy1 with SMTP id 1so3155875ewy.29 for ; Tue, 08 Feb 2011 15:10:24 -0800 (PST) Received: by 10.14.10.141 with SMTP id 13mr6590665eev.45.1297206624457; Tue, 08 Feb 2011 15:10:24 -0800 (PST) Received: from pc ([83.228.56.37]) by mx.google.com with ESMTPS id t5sm4376139eeh.20.2011.02.08.15.10.22 (version=SSLv3 cipher=RC4-MD5); Tue, 08 Feb 2011 15:10:23 -0800 (PST) Message-ID: <1FAB53AD31BF4EBCB83E3AD92046DE13@pc> To: "Nicolas Grekas" , References: <843E1DDB7AB24D9FA8F05801FE45202A@pc> Date: Wed, 9 Feb 2011 01:10:18 +0200 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.5931 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5994 Subject: Re: [PHP-DEV] Change default serialize precision from 100 to 17 From: sv_forums@fmethod.com ("Stan Vass") >> 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 ? > 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) > > Just my 2cts :) > > Nicolas As I've shown in the previous post, "looks better" doesn't mean "is more accurate". It's true that precision has been set to 12 or 14 in order to look better with some small decimal fractions, but that can't be the only concern when that same precision is used also for serialization during database escaping. It's hard to imagine when the display precision of an echoed float being longer or less aesthetically pleasing to a human eye may break code, but when real precision is lost, and this is sent to the database like that, this is a much more tangible problem. In terms of formatting of floats for humans, we still have printf() and number_format(), which allow control independent of the ini setting (which people use when they need that explicit control). Stan Vass