ID: 33576 User updated by: rick at ninjafoo dot com Reported By: rick at ninjafoo dot com -Status: Bogus +Status: Open Bug Type: Math related Operating System: Gentoo Linux PHP Version: 4.3.11 New Comment:
Yes, I understand that. My bug report was not to point out the joys of floating point math. My bug report was to illustrate a problem with php's internal casting. 19.6*100 != 1960 19.6*100 != (int)1960 19.6*100 != (float)1960 19.6*100 != (string)1960 echo gettype(19.6*100) returns 'double', However ..... 19.6*100 != (double)1960 19.6*100 cannot be compaired to anything without manually casting it as something else first. (string)(19.6*100) == (string)1960 Previous Comments: ------------------------------------------------------------------------ [2005-07-05 20:13:07] [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-07-05 20:11:18] rick at ninjafoo dot com Description: ------------ 100* certain values is not the same as 10*10* the same value. The following code should produce no output. I see output. Reproduce code: --------------- <?php $value1 = 19.6*100; $value2 = 19.6*10*10; if ($value1 != $value2) { echo 'funny, i thaught 100x was exactly the same as 10x10x....<br>'; echo 'value1='.$value1.', value2='.$value2.','; } ?> Expected result: ---------------- I expect nothing to happen. Actual result: -------------- funny, i thaught 100x was exactly the same as 10x10x.... value1=1960, value2=1960, ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=33576&edit=1
