Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:87640 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 58292 invoked from network); 5 Aug 2015 08:38:07 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Aug 2015 08:38:07 -0000 Authentication-Results: pb1.pair.com smtp.mail=yohgaki@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=yohgaki@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.160.176 as permitted sender) X-PHP-List-Original-Sender: yohgaki@gmail.com X-Host-Fingerprint: 209.85.160.176 mail-yk0-f176.google.com Received: from [209.85.160.176] ([209.85.160.176:35214] helo=mail-yk0-f176.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 6C/FA-11835-D6BC1C55 for ; Wed, 05 Aug 2015 04:38:06 -0400 Received: by ykcq64 with SMTP id q64so24754339ykc.2 for ; Wed, 05 Aug 2015 01:38:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=hyjKSC+MGhbTxXfhxJQboTtQNu79bbKo4aZpc4Mk11Y=; b=htWW5EAOXkzWZeuKSmxVJ5uKJ89rGOlxp9pYe9SUkDBB80SqvrwNWNgCDfuS2PQx2K W3zVVRtalyBpb52Zim0y5ATK8qICxczY3/i+bFQ4Ud5ukw0eDI7/xyCUPFQ7Ps0PfyhF 0Da08p3uYogtMS9+8d4iJp1uyjQxHSH6snKb2JturNjWIUbcgNKdH6rTshtXuG0ElZkU ymv4tzI3EoNp++7eC7Sl0sVucyV5ZV1h7L3xyxNFsf4E6+RMvCP9iRUeerXOt+yicNou ooTnS8o7w1GUcps6TlJoApHgk2kutjyIYppYMoxSXzaoVJdKT9RbmMkhENoE/NPFM+d8 5zaA== X-Received: by 10.170.77.5 with SMTP id t5mr8314726ykt.58.1438763882531; Wed, 05 Aug 2015 01:38:02 -0700 (PDT) MIME-Version: 1.0 Sender: yohgaki@gmail.com Received: by 10.129.40.77 with HTTP; Wed, 5 Aug 2015 01:37:23 -0700 (PDT) In-Reply-To: References: Date: Wed, 5 Aug 2015 17:37:23 +0900 X-Google-Sender-Auth: UsiMT_JaLssyBqr56Q8fr_ji1IE Message-ID: To: Nikita Popov Cc: Jakub Zelenka , Anthony Ferrara , "internals@lists.php.net" Content-Type: multipart/alternative; boundary=001a1139449a22538f051c8c5279 Subject: Re: [PHP-DEV] json_decode/encode should return full precision values by default From: yohgaki@ohgaki.net (Yasuo Ohgaki) --001a1139449a22538f051c8c5279 Content-Type: text/plain; charset=UTF-8 Hi all, On Fri, Jul 31, 2015 at 4:44 PM, Yasuo Ohgaki wrote: > On Thu, Jul 30, 2015 at 6:06 PM, Nikita Popov > wrote: > >> On Thu, Jul 30, 2015 at 1:25 AM, Yasuo Ohgaki wrote: >> >>> Hi all, >>> >>> On Thu, Jul 30, 2015 at 7:44 AM, Yasuo Ohgaki >>> wrote: >>> >>>> On Thu, Jul 30, 2015 at 1:13 AM, Nikita Popov >>>> wrote: >>>> >>>>> Instead of continuing to use serialize_precision, which will produce >>>>> unnecessarily long outputs for many values, why don't we just switch to >>>>> using the 0 mode of zend_dtoa, i.e. to return the shortest output that is >>>>> still accurate if interpreted in round-to-nearest. I think this is what >>>>> everybody else is using when they convert floating point numbers to >>>>> strings. I guess we may not be able to change normal floating point >>>>> printing to use this, but this seems like the best mode for anything using >>>>> serialize_precision now and everything that should be using it (like JSON, >>>>> and queries, etc). >>>> >>>> >>>> I prefer your proposal! >>>> Your proposal is a lot better than now. >>>> Anyone has opinion for this? >>>> >>>> I'm writing the RFC and I would like to make this the first option. i.e. >>>> serialize_precision=0 uses "zend_dtoa 0 mode" for all data exchange >>>> functions (json/serialize/var_exrport. Anyone care about WDDX/XML_RPC?) >>>> >>> >>> I wrote draft RFC. >>> >>> https://wiki.php.net/rfc/precise_float_value >>> >>> Please comment. I would like to start RFC discussion shortly. >>> Thank you. >>> >> >> Nice idea about using a special serialize_precision value for this. This >> allows to keep BC for those that have tests for particular serialize output >> or similar things. >> >> I would suggest to default serialize_precision to -1 in PHP 7 -- if >> people want the previous behavior they can still have it, but I think -1 is >> the more reasonable default as it matches what one would naturally expect. >> >> I don't see the need for having a separate setting for JSON. Having a >> dozen different float precision settings will not help anyone. >> > > Thank you for your feedback. > I agree it's better if PHP7 uses 0 mode by default. I'll update the RFC. > I have things to do on this weekend. I'll try to write patch this weekend > hopefully. > I sent work in progress PR for this and updated the RFC. https://github.com/php/php-src/pull/1455 TODO: Add/modify tests. Add 0 mode support for PG(precision). Add WDDX/XMLRPC PG(serialize_precision) support. https://wiki.php.net/rfc/precise_float_value Old behavior MacBook-Pro:github-php-src yohgaki$ php -r '$a=["v"=>123450000000000000000000000000.1234567890123]; var_dump(json_encode($a), serialize($a), var_export($a, true));'; string(16) "{"v":1.2345e+29}" string(39) "a:1:{s:1:"v";d:1.2344999999999999E+29;}" string(42) "array ( 'v' => 1.2344999999999999E+29, )" New behavior MacBook-Pro:github-php-src yohgaki$ ./php-bin -r '$a=["v"=>123450000000000000000000000000.1234567890123]; var_dump(json_encode($a), serialize($a), var_export($a, true));'; string(16) "{"v":1.2345e+29}" string(27) "a:1:{s:1:"v";d:1.2345E+29;}" string(30) "array ( 'v' => 1.2345E+29, )" Before I start working on PG(precision) 0 mode support, I would like to hear comments for this change if any. The default (PG(precision)=14) will not be changed and there will be no BC. I think it's more consistent if both PG(precision) and PG(serialize_precision) support 0 mode. Any comments for adding PG(precision) 0 mode support? Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net --001a1139449a22538f051c8c5279--