Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:51434 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 82731 invoked from network); 8 Feb 2011 13:41:18 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Feb 2011 13:41:18 -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:47027] helo=mail-ew0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id EE/E3-64215-CF7415D4 for ; Tue, 08 Feb 2011 08:41:18 -0500 Received: by ewy1 with SMTP id 1so2729441ewy.29 for ; Tue, 08 Feb 2011 05:41:13 -0800 (PST) Received: by 10.14.136.17 with SMTP id v17mr6905974eei.29.1297172473332; Tue, 08 Feb 2011 05:41:13 -0800 (PST) Received: from pc ([83.228.56.37]) by mx.google.com with ESMTPS id t50sm4013790eeh.0.2011.02.08.05.41.11 (version=SSLv3 cipher=RC4-MD5); Tue, 08 Feb 2011 05:41:12 -0800 (PST) Message-ID: <843E1DDB7AB24D9FA8F05801FE45202A@pc> To: , "Gustavo Lopes" References: Date: Tue, 8 Feb 2011 15:40:56 +0200 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="UTF-8"; reply-type=response 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") > The default serialize precision is currently [1] set at 100. A little code > inspection shows precision, in this case, takes the usual meaning of > number of significant digits. > > Given that the implicit precision of a (normal) IEEE 754 double precision > number is slightly less than 16 digits [2], this is a serious overkill. > Put another way, while the mantissa is composed of 52 bits plus 1 implicit > bit, 100 decimal digits can carry up to 100*log2(10) =~ 332 bits of > information, around 6 times more. > > Given this, I propose changing the default precision to 17 (while the > precision is slightly less than 16, a 17th digit is necessary because the > first decimal digit carries little information when it is low). > > From my tests, this makes serialization and unserialization of doubles > around 3 times faster (counting the function calls to > serialize/unserialize, plus a loop variable increment and stop condition > check). It also makes the serialization data. > > Crucially, from my tests, the condition that the variable stays the same > before and after serialization+unserialization still holds. The test > include, for little endian machines, verifies this. > > If no one objects, I'll change the default precision to 17. > I've always done this, and the default of 100 has been puzzling. We have another problem. The counterpart of serialize precision, the display "precision" INI setting is currently lower than 17 on most PHP installs, and it this leads to actual data loss in places where people expect least. All database drivers/APIs I've tested have escape/quote routines which are affected by this supposedly "display only" precision. The below test is performed on a 32-bit system (integers over 2^31 become floats): $x = new PDO('mysql:localhost', '...', '...'); ini_set('precision', 12); // typical for many PHP installs echo $x->quote(pow(2,50)); // (string) '1.12589990684E+15' ini_set('precision', 17); echo $x->quote(pow(2,50)); // (string) '1125899906842624' In the first example, the E notation, the API sends this to the database: 112589990684000, and was supposed to be 1125899906842624. It's off by -2624. The immediate fix for this is to keep *both* precisions to 17, and in the long term, they should switch to serialize.precision and not use the display precision. Stan Vass