cvs: php-src(PHP_4_4) / NEWS /ext/standard math.c /ext/standard/tests/strings bug29538.phpt

From: Date: Sun, 16 Jul 2006 10:53:56 +0000
Subject: cvs: php-src(PHP_4_4) / NEWS /ext/standard math.c /ext/standard/tests/strings bug29538.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-39263@lists.php.net to get a copy of this message
helly Sun Jul 16 10:53:56 2006 UTC Added files: (Branch: PHP_4_4) /php-src/ext/standard/tests/strings bug29538.phpt Modified files: /php-src/ext/standard math.c /php-src NEWS Log: - MFH Fixed Bug #29538 number_format and problem with 0 http://cvs.php.net/viewvc.cgi/php-src/ext/standard/math.c?r1=1.97.2.13.2.3&r2=1.97.2.13.2.4&diff_format=u Index: php-src/ext/standard/math.c diff -u php-src/ext/standard/math.c:1.97.2.13.2.3 php-src/ext/standard/math.c:1.97.2.13.2.4 --- php-src/ext/standard/math.c:1.97.2.13.2.3 Sun Jan 1 13:46:57 2006 +++ php-src/ext/standard/math.c Sun Jul 16 10:53:55 2006 @@ -19,7 +19,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: math.c,v 1.97.2.13.2.3 2006/01/01 13:46:57 sniper Exp $ */ +/* $Id: math.c,v 1.97.2.13.2.4 2006/07/16 10:53:55 helly Exp $ */ #include "php.h" #include "php_math.h" @@ -1015,13 +1015,8 @@ is_negative = 1; d = -d; } - if (!dec_point && dec > 0) { - d *= pow(10, dec); - dec = 0; - } else { - dec = MAX(0, dec); - } + dec = MAX(0, dec); PHP_ROUND_WITH_FUZZ(d, dec); tmplen = spprintf(&tmpbuf, 0, "%.*f", dec, d); @@ -1030,8 +1025,10 @@ return tmpbuf; } + /* find decimal point, if expected */ + dp = dec ? strchr(tmpbuf, '.') : NULL; + /* calculate the length of the return buffer */ - dp = strchr(tmpbuf, '.'); if (dp) { integral = dp - tmpbuf; } else { @@ -1047,7 +1044,11 @@ reslen = integral; if (dec) { - reslen += 1 + dec; + reslen += dec; + + if (dec_point) { + reslen++; + } } /* add a byte for minus sign */ @@ -1064,29 +1065,29 @@ * Take care, as the sprintf implementation may return less places than * we requested due to internal buffer limitations */ if (dec) { - int declen = dp ? strlen(dp+1) : 0; - int topad = declen > 0 ? dec - declen : 0; + int declen = dp ? s - dp : 0; + int topad = dec > declen ? dec - declen : 0; /* pad with '0's */ - while (topad--) { *t-- = '0'; } if (dp) { - /* now copy the chars after the point */ - memcpy(t - declen + 1, dp + 1, declen); - + s -= declen + 1; /* +1 to skip the point */ t -= declen; - s -= declen; + + /* now copy the chars after the point */ + memcpy(t + 1, dp + 1, declen); } /* add decimal point */ - *t-- = dec_point; - s--; + if (dec_point) { + *t-- = dec_point; + } } - /* copy the numbers before the decimal place, adding thousand + /* copy the numbers before the decimal point, adding thousand * separator every three digits */ while(s >= tmpbuf) { *t-- = *s--; http://cvs.php.net/viewvc.cgi/php-src/NEWS?r1=1.1247.2.920.2.140&r2=1.1247.2.920.2.141&diff_format=u Index: php-src/NEWS diff -u php-src/NEWS:1.1247.2.920.2.140 php-src/NEWS:1.1247.2.920.2.141 --- php-src/NEWS:1.1247.2.920.2.140 Tue Jul 4 16:40:23 2006 +++ php-src/NEWS Sun Jul 16 10:53:55 2006 @@ -9,6 +9,7 @@ - Fixed bug #37720 (merge_php_config scrambles values). (Mike, pumuckel at metropolis dot de) - Fixed bug #37569 (WDDX incorrectly encodes high-ascii characters). (Ilia) +- Fixed bug #29538 (number_format and problem with 0). (Matthew Wilmas) 21 May 2006, Version 4.4.3RC1 - Added control character checks for cURL extension's open_basedir/safe_mode http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/bug29538.phpt?view=markup&rev=1.1 Index: php-src/ext/standard/tests/strings/bug29538.phpt +++ php-src/ext/standard/tests/strings/bug29538.phpt --TEST-- Bug #29538 (number_format and problem with 0) --FILE-- <?php echo number_format(0.25, 2, '', ''), "\n"; echo number_format(1234, 2, '', ','); ?> --EXPECT-- 025 1,23400

« previous php.cvs (#39263) next »