]> granicus.if.org Git - php/commitdiff
Simply use ndigit for flag for zend_dtoa mode
authorYasuo Ohgaki <yohgaki@ohgaki.net>
Sun, 30 Aug 2015 08:13:24 +0000 (17:13 +0900)
committerJakub Zelenka <bukka@php.net>
Sun, 26 Jun 2016 12:26:43 +0000 (13:26 +0100)
ext/json/json_encoder.c
ext/standard/var.c
main/snprintf.c

index cf9d9adaa2cc28ebd79ecf91a8062b188e2031d1..b797e7da3d639575abbbfadc8eda19007048b09a 100644 (file)
@@ -104,11 +104,8 @@ static inline void php_json_encode_double(smart_str *buf, double d, int options)
 {
        size_t len;
        char num[PHP_JSON_DOUBLE_MAX_LENGTH];
-       if (JSON_G(precision) == -1) {
-               php_0cvt(d, 17, '.', 'e', num);
-       } else {
-               php_gcvt(d, JSON_G(precision), '.', 'e', num);
-       }
+
+       php_gcvt(d, JSON_G(precision), '.', 'e', num);
        len = strlen(num);
        if (options & PHP_JSON_PRESERVE_ZERO_FRACTION && strchr(num, '.') == NULL && len < PHP_JSON_DOUBLE_MAX_LENGTH - 2) {
                num[len++] = '.';
index e197198557601349ccd6b0e97223dc767beb0968..59404b8bc2953ae42a65ed043caf95c2d2362e69 100644 (file)
@@ -471,11 +471,7 @@ again:
                        }
                        efree(tmp_str);
                        */
-                       if (PG(serialize_precision < 0)) {
-                               php_0cvt(Z_DVAL_P(struc), 17, '.', 'E', tmp_str);
-                       } else {
-                               php_gcvt(Z_DVAL_P(struc), (int)PG(serialize_precision), '.', 'E', 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:
@@ -853,11 +849,7 @@ again:
                case IS_DOUBLE: {
                        char tmp_str[2048]; /* Use the same magic number of spprintf.c NUM_BUF_SIZE */
                        smart_str_appendl(buf, "d:", 2);
-                       if (PG(serialize_precision < 0)) {
-                               php_0cvt(Z_DVAL_P(struc), 17, '.', 'E', tmp_str);
-                       } else {
-                               php_gcvt(Z_DVAL_P(struc), (int)PG(serialize_precision), '.', 'E', tmp_str);
-                       }
+                       php_gcvt(Z_DVAL_P(struc), (int)PG(serialize_precision), '.', 'E', tmp_str);
                        smart_str_appends(buf, tmp_str);
                        smart_str_appendc(buf, ';');
                        return;
index a69ebb3e31045d9431c1f7227f79a6ae4bb2bc44..80a5c6e249b11aef30745dc8f9dc1271f16a5f90 100644 (file)
@@ -139,11 +139,15 @@ static inline char *php_fcvt(double value, int ndigit, int *decpt, int *sign) /*
 }
 /* }}} */
 
-static inline char *_php_cvt(double value, int ndigit, char dec_point, char exponent, char *buf, int mode) /* {{{ */
+PHPAPI char *php_gcvt(double value, int ndigit, char dec_point, char exponent, char *buf) /* {{{ */
 {
        char *digits, *dst, *src;
        int i, decpt, sign;
+       int mode = ndigit > 0 ? 2 : 0;
 
+       if (mode == 0) {
+               ndigit = 17;
+       }
        digits = zend_dtoa(value, mode, ndigit, &decpt, &sign, NULL);
        if (decpt == 9999) {
                /*
@@ -234,18 +238,6 @@ static inline char *_php_cvt(double value, int ndigit, char dec_point, char expo
 }
 /* }}} */
 
-PHPAPI char *php_gcvt(double value, int ndigit, char dec_point, char exponent, char *buf) /* {{{ */
-{
-       return _php_cvt(value, ndigit, dec_point, exponent, buf, 2);
-}
-/* }}} */
-
-PHPAPI char *php_0cvt(double value, int ndigit, char dec_point, char exponent, char *buf) /* {{{ */
-{
-       return _php_cvt(value, ndigit, dec_point, exponent, buf, 0);
-}
-/* }}} */
-
 
 
 /* {{{ Apache license */