Diff for /embedaddon/php/ext/standard/math.c between versions 1.1 and 1.1.1.3

version 1.1, 2012/02/21 23:48:02 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 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);
   }
   
   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 */
         char *dp;          char *dp;
Line 1113  PHPAPI char *_php_math_number_format(double d, int dec Line 1120  PHPAPI char *_php_math_number_format(double d, int dec
         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 1133  PHPAPI char *_php_math_number_format(double d, int dec Line 1144  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 1153  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 1189  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 1199  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 1198  PHPAPI char *_php_math_number_format(double d, int dec Line 1211  PHPAPI char *_php_math_number_format(double d, int dec
   
         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 1224  PHP_FUNCTION(number_format) Line 1248  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);
                 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;

Removed from v.1.1  
changed lines
  Added in v.1.1.1.3


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>