Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:85796 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 8231 invoked from network); 14 Apr 2015 04:31:27 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Apr 2015 04:31:27 -0000 Authentication-Results: pb1.pair.com smtp.mail=indeyets@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=indeyets@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.213.177 as permitted sender) X-PHP-List-Original-Sender: indeyets@gmail.com X-Host-Fingerprint: 209.85.213.177 mail-ig0-f177.google.com Received: from [209.85.213.177] ([209.85.213.177:35084] helo=mail-ig0-f177.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 6F/90-32769-D189C255 for ; Tue, 14 Apr 2015 00:31:26 -0400 Received: by igbyr2 with SMTP id yr2so28739745igb.0 for ; Mon, 13 Apr 2015 21:31:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=WJ6kt5lvhLSnRC32f6BWno46EGCJ7QRbxqh9njap0bc=; b=Z5sL7yrc5o1/tkjcUR5LCWSuUpA2u+h7M3uM05yCYdHF3e6+oml1SV5tN2VVHwmrru R9spDcuanNGL9LhVU8/4k6o3eCPiC45UC3Pea85qhgzLt9gJQcEfa9ln1xhc8y349YKx ANcvW4MlEnDXXQWCSyU84IoQ4TlO35xRJ4ivT/UVK9w1N3xhF7ozUiwxt7QR9nDUhdzA aW/K3Lo1E9ggZ5I7h8zjtEvoy20yeza1HFPUnQYZvXH+zuKkxrS5CHxqCWSQdWxQ9apn HVCEFynU1VR/ZqUtqZES/PPJy9ioUvsqH1e8VoXPW5ajrC59XF4HQn0l54Jbzo5gWlaX wkGQ== X-Received: by 10.50.61.239 with SMTP id t15mr21535926igr.7.1428985883161; Mon, 13 Apr 2015 21:31:23 -0700 (PDT) Received: from [10.0.1.8] ([91.219.26.208]) by mx.google.com with ESMTPSA id ig15sm577928igb.10.2015.04.13.21.31.20 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 13 Apr 2015 21:31:21 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2098\)) In-Reply-To: Date: Tue, 14 Apr 2015 07:31:17 +0300 Cc: PHP internals list Content-Transfer-Encoding: quoted-printable Message-ID: References: To: Jakub Zelenka X-Mailer: Apple Mail (2.2098) Subject: Re: [PHP-DEV] JSON float number as string From: indeyets@gmail.com (Alexey Zakhlestin) > On 29 Mar 2015, at 22:33, Jakub Zelenka wrote: >=20 > I would like to add a new option to JSON for dealing with large = floats. The > use case is mainly for decoder but can be used for encoder as well. >=20 > JSON_FLOAT_AS_STRING > decode: all float values will be decoded as string > - It's often an issue for very large float values with many fractional > digits that are coming from platforms that support larger float > representation than double. In that case the conversion is lost and = there > is no way how to get it back (see http://bugs.php.net/68456 [pls = ignore my > initial dump comments when I didn't get the issue :)] and an example = of the > lost precision here http://3v4l.org/80iCh ). Converting the value to = string > keep the precision and resolves the problem. >=20 > encode: all float values will be encoded as string > - re-using the constant for encoder makes sense if PHP creates JSON = for > platform that support lower float type (e.g. C float) and the = precision > loss is not acceptable >=20 >=20 > I think that this is more a bugfix as the precision is lost without = any way > how to get it back (except pre-processing json string with regular > expression). I would like to add it to 5.6.x if there are no = objections? Feels a bit hackish I think it is possible to introduce an overall better solution We can expose result of json-tokenizing as a tree of objects: JSON\Object JSON\Array JSON\String JSON\Number JSON\False JSON\True JSON\Null then, it would be possible to introduce any number of experimental = userland implementations like the one proposed here --=20 Alexey Zakhlestin https://github.com/indeyets PGP key: http://indeyets.ru/alexey.zakhlestin.pgp.asc