version 1.1.1.2, 2012/05/29 12:34:43
|
version 1.1.1.3, 2013/07/22 01:32:05
|
Line 2
|
Line 2
|
+----------------------------------------------------------------------+ |
+----------------------------------------------------------------------+ |
| PHP Version 5 | |
| PHP Version 5 | |
+----------------------------------------------------------------------+ |
+----------------------------------------------------------------------+ |
| Copyright (c) 1997-2012 The PHP Group | | | Copyright (c) 1997-2013 The PHP Group | |
+----------------------------------------------------------------------+ |
+----------------------------------------------------------------------+ |
| This source file is subject to version 3.01 of the PHP license, | |
| This source file is subject to version 3.01 of the PHP license, | |
| that is bundled with this package in the file LICENSE, and is | |
| that is bundled with this package in the file LICENSE, and is | |
Line 37 static inline int php_intlog10abs(double value) {
|
Line 37 static inline int php_intlog10abs(double value) {
|
int result; |
int result; |
value = fabs(value); |
value = fabs(value); |
|
|
if (value < 1e-8 || value > 1e23) { | if (value < 1e-8 || value > 1e22) { |
result = (int)floor(log10(value)); |
result = (int)floor(log10(value)); |
} else { |
} else { |
static const double values[] = { |
static const double values[] = { |
Line 46 static inline int php_intlog10abs(double value) {
|
Line 46 static inline int php_intlog10abs(double value) {
|
1e8, 1e9, 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, |
1e8, 1e9, 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, |
1e16, 1e17, 1e18, 1e19, 1e20, 1e21, 1e22}; |
1e16, 1e17, 1e18, 1e19, 1e20, 1e21, 1e22}; |
/* Do a binary search with 5 steps */ |
/* Do a binary search with 5 steps */ |
result = 16; | result = 15; |
if (value < values[result]) { |
if (value < values[result]) { |
result -= 8; |
result -= 8; |
} else { |
} else { |
Line 1097 PHPAPI char *_php_math_number_format(double d, int dec
|
Line 1097 PHPAPI char *_php_math_number_format(double d, int dec
|
return _php_math_number_format_ex(d, dec, &dec_point, 1, &thousand_sep, 1); |
return _php_math_number_format_ex(d, dec, &dec_point, 1, &thousand_sep, 1); |
} |
} |
|
|
PHPAPI char *_php_math_number_format_ex(double d, int dec, char *dec_point, size_t dec_point_len, char *thousand_sep, size_t thousand_sep_len) | static char *_php_math_number_format_ex_len(double d, int dec, char *dec_point, |
| size_t dec_point_len, char *thousand_sep, size_t thousand_sep_len, |
| int *result_len) |
{ |
{ |
char *tmpbuf = NULL, *resbuf; |
char *tmpbuf = NULL, *resbuf; |
char *s, *t; /* source, target */ |
char *s, *t; /* source, target */ |
Line 1118 PHPAPI char *_php_math_number_format_ex(double d, int
|
Line 1120 PHPAPI char *_php_math_number_format_ex(double d, int
|
tmplen = spprintf(&tmpbuf, 0, "%.*F", dec, d); |
tmplen = spprintf(&tmpbuf, 0, "%.*F", dec, d); |
|
|
if (tmpbuf == NULL || !isdigit((int)tmpbuf[0])) { |
if (tmpbuf == NULL || !isdigit((int)tmpbuf[0])) { |
|
if (result_len) { |
|
*result_len = tmplen; |
|
} |
|
|
return tmpbuf; |
return tmpbuf; |
} |
} |
|
|
Line 1205 PHPAPI char *_php_math_number_format_ex(double d, int
|
Line 1211 PHPAPI char *_php_math_number_format_ex(double d, int
|
|
|
efree(tmpbuf); |
efree(tmpbuf); |
|
|
|
if (result_len) { |
|
*result_len = reslen; |
|
} |
|
|
return resbuf; |
return resbuf; |
} |
} |
|
|
|
PHPAPI char *_php_math_number_format_ex(double d, int dec, char *dec_point, |
|
size_t dec_point_len, char *thousand_sep, size_t thousand_sep_len) |
|
{ |
|
return _php_math_number_format_ex_len(d, dec, dec_point, dec_point_len, |
|
thousand_sep, thousand_sep_len, NULL); |
|
} |
/* }}} */ |
/* }}} */ |
|
|
/* {{{ proto string number_format(float number [, int num_decimal_places [, string dec_seperator, string thousands_seperator]]) |
/* {{{ proto string number_format(float number [, int num_decimal_places [, string dec_seperator, string thousands_seperator]]) |
Line 1241 PHP_FUNCTION(number_format)
|
Line 1258 PHP_FUNCTION(number_format)
|
thousand_sep_len = 1; |
thousand_sep_len = 1; |
} |
} |
|
|
RETURN_STRING(_php_math_number_format_ex(num, dec, dec_point, dec_point_len, thousand_sep, thousand_sep_len), 0); | Z_TYPE_P(return_value) = IS_STRING; |
| Z_STRVAL_P(return_value) = _php_math_number_format_ex_len(num, dec, |
| dec_point, dec_point_len, thousand_sep, thousand_sep_len, |
| &Z_STRLEN_P(return_value)); |
break; |
break; |
default: |
default: |
WRONG_PARAM_COUNT; |
WRONG_PARAM_COUNT; |