ID:               41567
 Updated by:       [EMAIL PROTECTED]
 Reported By:      lucas at facebook dot com
-Status:           Assigned
+Status:           Closed
 Bug Type:         JSON related
 Operating System: linux, osx
 PHP Version:      5CVS-2007-06-02 (CVS)
 Assigned To:      iliaa
 New Comment:

This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.




Previous Comments:
------------------------------------------------------------------------

[2007-06-02 03:44:34] lucas at facebook dot com

Description:
------------
json_encode is ignoring PHP integer precision and losing precision on
large doubles. The patch below changes json_enode double to match the
same conversion done internally in _convert_to_string.

This is related to http://bugs.php.net/bug.php?id=40503 and reverts the
patch applied there. Tested against these use cases as well.

Reproduce code:
---------------
json_encode(123456789.12345)

Expected result:
----------------
123456789.12345 = 123456789.12345

Actual result:
--------------
123456789.12345 = 123456789



Index: json.c
===================================================================
RCS file: /repository/php-src/ext/json/json.c,v
retrieving revision 1.9.2.15
diff -u -r1.9.2.15 json.c
--- json.c      25 May 2007 13:24:50 -0000      1.9.2.15
+++ json.c      2 Jun 2007 03:41:47 -0000
@@ -354,15 +354,11 @@
                 double dbl = Z_DVAL_P(val);
 
                 if (!zend_isinf(dbl) && !zend_isnan(dbl)) {
-                       len = spprintf(&d, 0, "%.9g", dbl);
-                       if (d) {
-                               if (dbl > LONG_MAX && !memchr(d, '.',
len)) {
-                                       smart_str_append_unsigned(buf,
(unsigned long)Z_DVAL_P(val));
-                               } else {
-                                       smart_str_appendl(buf, d,
len);
-                               }
-                               efree(d);
-                       }
+                    len = spprintf(&d, 0, "%.*G", (int) EG(precision),
dbl);
+                    if (d) {
+                        smart_str_appendl(buf, d, len);
+                        efree(d);
+                    }


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=41567&edit=1

Reply via email to