Skip to content

Commit

Permalink
Add decimal point in double serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
bukka committed Jun 26, 2016
1 parent 75b86a2 commit 71774c2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
13 changes: 4 additions & 9 deletions ext/standard/var.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,22 +468,17 @@ PHPAPI void php_var_export_ex(zval *struc, int level, smart_str *buf) /* {{{ */
smart_str_append_long(buf, Z_LVAL_P(struc));
break;
case IS_DOUBLE:
/* TODO: check INF, -INF and NAN in the new logic
tmp_len = spprintf(&tmp_str, 0,"%.*H", PG(serialize_precision), Z_DVAL_P(struc));
smart_str_appendl(buf, tmp_str, tmp_len);
* Without a decimal point, PHP treats a number literal as an int.
php_gcvt(Z_DVAL_P(struc), (int)PG(serialize_precision), '.', 'E', tmp_str);
smart_str_appends(buf, tmp_str);
/* Without a decimal point, PHP treats a number literal as an int.
* This check even works for scientific notation, because the
* mantissa always contains a decimal point.
* We need to check for finiteness, because INF, -INF and NAN
* must not have a decimal point added.
*
*/
if (zend_finite(Z_DVAL_P(struc)) && NULL == strchr(tmp_str, '.')) {
smart_str_appendl(buf, ".0", 2);
}
efree(tmp_str);
*/
php_gcvt(Z_DVAL_P(struc), (int)PG(serialize_precision), '.', 'E', tmp_str);
smart_str_appends(buf, tmp_str);
break;
case IS_STRING:
ztmp = php_addcslashes(Z_STR_P(struc), 0, "'\\", 2);
Expand Down
2 changes: 1 addition & 1 deletion tests/basic/precision.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ OUTPUTS
123456789 3.33333333 9.87E+102 10.0000001
string(72) "a:4:{i:0;d:123456789;i:1;d:3.33333333;i:2;d:9.87E+102;i:3;d:10.0000001;}"
array (
0 => 123456789,
0 => 123456789.0,
1 => 3.33333333,
2 => 9.87E+102,
3 => 10.0000001,
Expand Down

0 comments on commit 71774c2

Please sign in to comment.