ID: 35275 User updated by: uwe dot voelker at vline dot de Reported By: uwe dot voelker at vline dot de Status: Bogus Bug Type: Math related Operating System: Win XP PHP Version: 5.0.5 New Comment:
OK, after reading ten pages about float i take the ROUND function, it works now. if ( (-56.33) != Round((-14.13) + (-42.20),2) ) { print "<HR> First Example: Why is -56.33 not -56.33 ??? <HR>"; } else { print "<HR> First Example: OK <HR>"; } Previous Comments: ------------------------------------------------------------------------ [2005-11-18 14:59:52] [EMAIL PROTECTED] 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. If you would like to know more about "floats" and what IEEE 754 is read this: http://docs.sun.com/source/806-3568/ncg_goldberg.html Thank you for your interest in PHP. . ------------------------------------------------------------------------ [2005-11-18 14:13:33] uwe dot voelker at vline dot de Description: ------------ Addition of some negative floats fails ! Reproduce code: --------------- <?php // PHP 5.05 // First example shows the bug if ( (-56.33) != ((-14.13) + (-42.20)) ) { print "<HR> First Example: Why is -56.33 not -56.33 ??? <HR>"; } else { print "<HR> First Example: OK <HR>"; } // Second example with modified values but same result is ok if ( (-56.33) != ((-14.12) + (-42.21)) ) { print "<HR> Second Example: Why is -56.33 not -56.33 ??? <HR>"; } else { print "<HR> Second Example: OK <HR>"; } ?> Expected result: ---------------- First example: true, but must be false. Second example: false, it is OK. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=35275&edit=1