Re: json_decode/encode should return full precision values by default

From: Date: Fri, 31 Jul 2015 07:44:51 +0000
Subject: Re: json_decode/encode should return full precision values by default
References: 1 2 3 4 5 6 7 8 9 10 11 12 13 14  Groups: php.internals 
Request: Send a blank email to internals+get-87426@lists.php.net to get a copy of this message
Hi Nikita, On Thu, Jul 30, 2015 at 6:06 PM, Nikita Popov <nikita.ppv@gmail.com> wrote: > On Thu, Jul 30, 2015 at 1:25 AM, Yasuo Ohgaki <yohgaki@ohgaki.net> wrote: > >> Hi all, >> >> On Thu, Jul 30, 2015 at 7:44 AM, Yasuo Ohgaki <yohgaki@ohgaki.net> wrote: >> >>> On Thu, Jul 30, 2015 at 1:13 AM, Nikita Popov <nikita.ppv@gmail.com> >>> 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. Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net

« previous php.internals (#87426) next »