From: robinmessag at hotmail dot com Operating system: Windows 98SE PHP version: Irrelevant PHP Bug Type: Feature/Change Request Bug description: Mod operator(%) doesn't work with negative integers
Description: ------------ When doing the modulus of a negative number, PHP returns a bogus value. However, it is clearly doing the modulus, simply returning a negative answer. In order to work around, one can add the modulus and mod again, but this is not a satisfactory solution IMHO. This bug has been reported before and dismissed, however, modulus on negative numbers is correct and useful and this should be fixed or at least documented. Reproduce code: --------------- $hour=4; $timedifference1=-6; $timedifference2=-30; $realtime=($hour+$timedifference1)%24; $realtime2=($hour+$timedifference2)%24; $realtime3=($hour+$timedifference2)%24; $realtime3=(24+$realtime3)%24; echo("The time is:$realtime or maybe $realtime2<BR>"); echo("The correct time is:$realtime3<BR>"); Expected result: ---------------- The time is:22 or maybe 22 The correct time is:22 Actual result: -------------- The time is:-2 or maybe -2 The correct time is:22 -- Edit bug report at http://bugs.php.net/?id=29732&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=29732&r=trysnapshot4 Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=29732&r=trysnapshot5 Fixed in CVS: http://bugs.php.net/fix.php?id=29732&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=29732&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=29732&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=29732&r=needscript Try newer version: http://bugs.php.net/fix.php?id=29732&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=29732&r=support Expected behavior: http://bugs.php.net/fix.php?id=29732&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=29732&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=29732&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=29732&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=29732&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=29732&r=dst IIS Stability: http://bugs.php.net/fix.php?id=29732&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=29732&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=29732&r=float