|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2004-08-18 14:47 UTC] derick@php.net
[2004-08-21 17:06 UTC] robinmessag at hotmail dot com
[2004-08-22 11:44 UTC] vrana@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 16 11:00:02 2025 UTC |
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