ID: 30199 Updated by: [EMAIL PROTECTED] Reported By: sdibb at myway dot com -Status: Open +Status: Bogus Bug Type: Math related Operating System: Linux PHP Version: 5.0.1 New Comment:
Floating point values have a limited precision. Hence a value might not have the same string representation after any processing. That also includes writing a floating point value in your script and directly printing it without any mathematical operations. Thank you for your interest in PHP. Previous Comments: ------------------------------------------------------------------------ [2004-09-22 20:31:31] sdibb at myway dot com Description: ------------ array_sum AND adding numbers seems to be returning the wrong total, where all the values are floats. It seems to be in every case that it's the last value that throws off the grand total. Tested with both v4.3.8 and v5.0.1 on different linux machines. Looks like a dupe of http://bugs.php.net/bug.php?id=6034 but not sure, since this doesn't use very large values for the numbers. Reproduce code: --------------- long example: http://wonkabar.org/array_sum.phps short example: php -r "print array_sum(array(149.96, 49.99, -20.00, -149.96, 0, -20.00, -9.99));" Expected result: ---------------- the correct calculated totals. Actual result: -------------- short example: 8.881784197E-15 # php -m [PHP Modules] bz2 ctype gmp mysql overload pcre pgsql posix session sqlite standard tokenizer xml zip zlib [Zend Modules] ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=30199&edit=1