ID: 34179 Comment by: yaXay at gmx dot net Reported By: pww8 at cornell dot edu Status: Open Bug Type: Feature/Change Request Operating System: Linux 2.4.9 PHP Version: 5.0.4 New Comment:
As far as I know 1/0 is undefined (lim x->0 (1/x) is inf.), as well as 1.0e300*1.0e300 simply produces an overflow. Of course that is just a technicality, but still.. Regarding devide by zero and overflows, I would go even further and throw an exception, because that is what they are: exceptions. Nobody divides by zero or generates overflows on purpose. They usually occur on erroneous user input. Throwing exceptions would of course force the programmer to be more aware of this issue, since exceptions have a habit of stopping execution when they are not caught. Howerver I find it good to force the programmer to produce clean code, I mean, what is the downside?? Sincerely, Benjamin Schulz Previous Comments: ------------------------------------------------------------------------ [2005-08-18 00:44:16] pww8 at cornell dot edu Description: ------------ It appears floating-point infinity (INF) is not returned from divide by zero (in PHP 5.0.0). Instead a warning is given and Boolean FALSE is returned. This is no doubt well-known behavior to most users, probably would be confusing to change the default. But it would be useful for me to throw a switch or set an .ini file variable to some non-default state, and get the correct answer instead of FALSE. Note that you can get INF from multiply, e.g. 1.0e300*1.0e300 [Linux on Intel]. Might also be nice to get INF when it is the correct answer! Reproduce code: --------------- // Expected result would be after I set some non-default // floating point handling mode above... $varxx = 1.0 / 0.0; $if (isset($varxx)) { boolean = is_bool($varxx) ? "Boolean" : "Not Boolean" ; print "\nSET $varxx $boolean"; } else { print "\nNOT SET"; } print "\nanother test, exp of very large number is : " . exp(1.0e300); print "\ntry for infinity using * : " . 1.0e300*1.0e300; Expected result: ---------------- SET INF Not Boolean another test, exp of very large number is : INF try for infinity using * : INF Actual result: -------------- SET Boolean another test, exp of very large number is : INF try for infinity using * : INF ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=34179&edit=1