Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:87331 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 50093 invoked from network); 27 Jul 2015 22:11:36 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Jul 2015 22:11:36 -0000 Authentication-Results: pb1.pair.com header.from=yohgaki@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=yohgaki@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.160.177 as permitted sender) X-PHP-List-Original-Sender: yohgaki@gmail.com X-Host-Fingerprint: 209.85.160.177 mail-yk0-f177.google.com Received: from [209.85.160.177] ([209.85.160.177:32869] helo=mail-yk0-f177.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E6/01-33169-69CA6B55 for ; Mon, 27 Jul 2015 18:11:35 -0400 Received: by ykfw194 with SMTP id w194so81162016ykf.0 for ; Mon, 27 Jul 2015 15:11:32 -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=DgbUKmOTzg3ZWAGZcTdQTjEPj8scuvmK+3RiFRbHGY0=; b=PhwQL/pYimDabf+wtqtXn+GeGI4D6EgLG82ufKmxBCzCTzrgz7KbGRs7iSKCZp+uqz MJ65+4wGJ7LrhsgNroKG/6CeqVtr2fPK21r/UGo8TbCz+DCrkUag0ATcNmhvDn3D+P/I mx9Yx4WtLKvAscB5zGbVuMdCy1Dsn/Ku0eWjBLzG4gNHxu17joISE9OrDIRjFhFJr/6U UZIGPqfmhYPQW6+OmGUus/K6LrCvHKJuIPXXKMpGcR/Znp98GXyPRewhXZgPzmi6qn7c iH9SECWjY0hIf8LO9UTT0RaZMDI89uUS01ca+MUWMFcWUsF3swMMG825Cr0JXAfnrSzN hEow== X-Received: by 10.170.215.69 with SMTP id h66mr32275696ykf.74.1438035092233; Mon, 27 Jul 2015 15:11:32 -0700 (PDT) MIME-Version: 1.0 Sender: yohgaki@gmail.com Received: by 10.129.40.77 with HTTP; Mon, 27 Jul 2015 15:10:50 -0700 (PDT) In-Reply-To: References: Date: Tue, 28 Jul 2015 07:10:50 +0900 X-Google-Sender-Auth: jbU9lsCngnqTgRBOLsTNeKmam6U Message-ID: To: Anthony Ferrara Cc: Jakub Zelenka , "internals@lists.php.net" Content-Type: multipart/alternative; boundary=001a113bcfa0d8e5ad051be2a226 Subject: Re: [PHP-DEV] json_decode/encode should return full precision values by default From: yohgaki@ohgaki.net (Yasuo Ohgaki) --001a113bcfa0d8e5ad051be2a226 Content-Type: text/plain; charset=UTF-8 Hi Anthony, On Tue, Jul 28, 2015 at 6:54 AM, Anthony Ferrara wrote: > On Sun, Jul 26, 2015 at 4:20 PM, Yasuo Ohgaki wrote: > > Hi Jakub, > > > > On Mon, Jul 27, 2015 at 3:32 AM, Jakub Zelenka wrote: > > > >> I don't think that this is a bug. Your example is also completely > >> unrelated to json because the place when the value is rounded is > var_dump > >> where it's based on ini precision. You would get the same values with > >> json_encode but it's only because it uses the same ini ( precision ). > >> Basically it has nothing to do with json_decode. > >> > > > > OK. Better example. > > > > [yohgaki@dev PHP-master]$ ./php-bin > > > $j = '{ "v": 0.1234567890123456789 }'; > > var_dump(json_encode(json_decode($j))); > > ini_set('precision', 20); > > var_dump(json_encode(json_decode($j))); > > ?> > > > > > > string(22) "{"v":0.12345678901235}" > > string(28) "{"v":0.12345678901234567737}" > > I think you missed the point. Parsing isn't dependent upon precision > setting. Only dumping: http://3v4l.org/48VSt > > $j = '{ "v": 0.1234567890123456789 }'; > $d1 = json_decode($j); > > ini_set('precision', 20); > > $d2 = json_decode($j); > > var_dump($d1, $d2); > > //object(stdClass)#1 (1) { ["v"]=> float(0.12345678901234567737) } > //object(stdClass)#2 (1) { ["v"]=> float(0.12345678901234567737) } > > Meaning that it's parsed correctly. > > There is no bug here. I understands PHP uses pure IEEE data and arithmetic and I disagree that this is not a bug. What I'm pointing it out is "simple JSON operation truncates _valid/precise_ value". IEEE double can store 17 digit fraction part precisely, but PHP truncates it. > $j = '{ "v": 0.1234567890123456789 }'; > var_dump(json_encode(json_decode($j))); > ini_set('precision', 20); > var_dump(json_encode(json_decode($j))); > ?> > > > string(22) "{"v":0.12345678901235}" > string(28) "{"v":0.12345678901234567737}" The same problem in serialize/unserialize was fixed as a bug. Encode/decode should be as precise as possible by _default_. IMO. What's the point of truncation and having broken value? Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net --001a113bcfa0d8e5ad051be2a226--