| version 1.1.1.1, 2012/02/21 23:48:02 | version 1.1.1.2, 2012/05/29 12:34:43 | 
| Line 620  PHP_FUNCTION(pow) | Line 620  PHP_FUNCTION(pow) | 
 |  |  | 
 | /* calculate pow(long,long) in O(log exp) operations, bail if overflow */ | /* calculate pow(long,long) in O(log exp) operations, bail if overflow */ | 
 | while (i >= 1) { | while (i >= 1) { | 
| int overflow; | long overflow; | 
 | double dval = 0.0; | double dval = 0.0; | 
 |  |  | 
 | if (i % 2) { | if (i % 2) { | 
| Line 1094  PHP_FUNCTION(base_convert) | Line 1094  PHP_FUNCTION(base_convert) | 
 | */ | */ | 
 | PHPAPI char *_php_math_number_format(double d, int dec, char dec_point, char thousand_sep) | PHPAPI char *_php_math_number_format(double d, int dec, char dec_point, char thousand_sep) | 
 | { | { | 
 |  | 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) | 
 |  | { | 
 | char *tmpbuf = NULL, *resbuf; | char *tmpbuf = NULL, *resbuf; | 
 | char *s, *t;  /* source, target */ | char *s, *t;  /* source, target */ | 
 | char *dp; | char *dp; | 
| Line 1133  PHPAPI char *_php_math_number_format(double d, int dec | Line 1138  PHPAPI char *_php_math_number_format(double d, int dec | 
 |  |  | 
 | /* allow for thousand separators */ | /* allow for thousand separators */ | 
 | if (thousand_sep) { | if (thousand_sep) { | 
| integral += (integral-1) / 3; | integral += thousand_sep_len * ((integral-1) / 3); | 
 | } | } | 
 |  |  | 
 | reslen = integral; | reslen = integral; | 
| Line 1142  PHPAPI char *_php_math_number_format(double d, int dec | Line 1147  PHPAPI char *_php_math_number_format(double d, int dec | 
 | reslen += dec; | reslen += dec; | 
 |  |  | 
 | if (dec_point) { | if (dec_point) { | 
| reslen++; | reslen += dec_point_len; | 
 | } | } | 
 | } | } | 
 |  |  | 
| Line 1178  PHPAPI char *_php_math_number_format(double d, int dec | Line 1183  PHPAPI char *_php_math_number_format(double d, int dec | 
 |  |  | 
 | /* add decimal point */ | /* add decimal point */ | 
 | if (dec_point) { | if (dec_point) { | 
| *t-- = dec_point; | t -= dec_point_len; | 
|  | memcpy(t + 1, dec_point, dec_point_len); | 
 | } | } | 
 | } | } | 
 |  |  | 
| Line 1187  PHPAPI char *_php_math_number_format(double d, int dec | Line 1193  PHPAPI char *_php_math_number_format(double d, int dec | 
 | while(s >= tmpbuf) { | while(s >= tmpbuf) { | 
 | *t-- = *s--; | *t-- = *s--; | 
 | if (thousand_sep && (++count%3)==0 && s>=tmpbuf) { | if (thousand_sep && (++count%3)==0 && s>=tmpbuf) { | 
| *t-- = thousand_sep; | t -= thousand_sep_len; | 
|  | memcpy(t + 1, thousand_sep, thousand_sep_len); | 
 | } | } | 
 | } | } | 
 |  |  | 
| Line 1224  PHP_FUNCTION(number_format) | Line 1231  PHP_FUNCTION(number_format) | 
 | RETURN_STRING(_php_math_number_format(num, dec, dec_point_chr, thousand_sep_chr), 0); | RETURN_STRING(_php_math_number_format(num, dec, dec_point_chr, thousand_sep_chr), 0); | 
 | break; | break; | 
 | case 4: | case 4: | 
| if (dec_point != NULL) { | if (dec_point == NULL) { | 
| if (dec_point_len) { | dec_point = &dec_point_chr; | 
| dec_point_chr = dec_point[0]; | dec_point_len = 1; | 
| } else { |  | 
| dec_point_chr = 0; |  | 
| } |  | 
 | } | } | 
| if (thousand_sep != NULL) { |  | 
| if (thousand_sep_len) { | if (thousand_sep == NULL) { | 
| thousand_sep_chr = thousand_sep[0]; | thousand_sep = &thousand_sep_chr; | 
| } else { | thousand_sep_len = 1; | 
| thousand_sep_chr = 0; |  | 
| } |  | 
 | } | } | 
| RETURN_STRING(_php_math_number_format(num, dec, dec_point_chr, thousand_sep_chr), 0); |  | 
|  | RETURN_STRING(_php_math_number_format_ex(num, dec, dec_point, dec_point_len, thousand_sep, thousand_sep_len), 0); | 
 | break; | break; | 
 | default: | default: | 
 | WRONG_PARAM_COUNT; | WRONG_PARAM_COUNT; |