From: jaypedhskr at aol dot com
Operating system: Unix
PHP version: 4.2.3
PHP Bug Type: Math related
Bug description: Modulus returned negative value
Hi,
I had the following result from a PHP script, as seen from printing output
variables:
-27 % 7 == -6
My understanding of the modulus function is that it returns the remainder
from division, and that the remainder can never be negative.
I believe that is the standard mathematical definition.
So I think what should have been returned is 1 instead of -6.
That is
-27 = 7*(-4) + 1
instead of
-27 = 7*(-3) -6
I got around this by adding the the modulus value if the result was less
than zero. But I think a result of less than zero shouldn't occur.
Code snippet that ran into this:
$T5 = $D + $T1 + $Y + $T2 + $T3 - $T4;
$weekday = $T5 % 7;
Added code to handle this:
if ($weekday < 0) {
$weekday += 7; // -27 % 7 = -6 case
}
Specific problem case:
$T5 = 3 + 2 + 3 + 5 + 0 - 40; // -27
$weekday = %T5 % 7; // -27 % 7 = -6
Thanks!
-Jay Pedersen
--
Edit bug report at http://bugs.php.net/?id=22527&edit=1
--
Try a CVS snapshot: http://bugs.php.net/fix.php?id=22527&r=trysnapshot
Fixed in CVS: http://bugs.php.net/fix.php?id=22527&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=22527&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=22527&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=22527&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=22527&r=support
Expected behavior: http://bugs.php.net/fix.php?id=22527&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=22527&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=22527&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=22527&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=22527&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=22527&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=22527&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=22527&r=gnused