From: nonsqtr at hotmail dot com Operating system: Linux 2.6.18-164.6.1.el5 #1 SMP PHP version: 5.2.12 PHP Bug Type: Math related Bug description: Remainder operator (%) FAILS with two specific numbers
Description: ------------ This line of code $tag = $amount % 100 gives an incorrect result when "amount" is set to one of two specific numbers: 3330 and 6660 Any other number seems to work fine - for example, 60, 660, 66660, 666660, .... work fine. Only 6660 fails, it gives the incorrect result 59. And, 3330 gives the incorrect result 29. It doesn't matter if you typecast amount before calculating. And it doesn't matter if it's a string or an int being passed in, the result is still 29 or 59. I ran a whole series of numbers against this, and 3330 and 6660 are the only ones that fail (at least, that I found). I'm on a hosted system, so I can't tell you how PHP was compiled. But I've reproduced this on three hosted systems so far, with different PHP versions, going all the way back to 5.2.5, so it looks like it's just a hidden bug that's been lurking around for a while. Once again, casting does not resolve this problem, and using the round() function doesn't resolve it either. The operator % is what's failing here. Reproduce code: --------------- --- >From manual page: http://www.php.net/function.round#Description --- $tag = $amount % 100 When $amount is an int, a string, or a float Expected result: ---------------- When $amount is set to 6660, I expect to see a 60 come back Actual result: -------------- I get a 59 instead of a 60 -- Edit bug report at http://bugs.php.net/?id=51108&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=51108&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=51108&r=trysnapshot53 Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=51108&r=trysnapshot60 Fixed in SVN: http://bugs.php.net/fix.php?id=51108&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=51108&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=51108&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=51108&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=51108&r=needscript Try newer version: http://bugs.php.net/fix.php?id=51108&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=51108&r=support Expected behavior: http://bugs.php.net/fix.php?id=51108&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=51108&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=51108&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=51108&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=51108&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=51108&r=dst IIS Stability: http://bugs.php.net/fix.php?id=51108&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=51108&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=51108&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=51108&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=51108&r=mysqlcfg