#20365 [Fbk->Opn]: the modulo operator % doesn't work with negative integers!
| From: | Ernest at Beinrohr dot sk | Date: | Mon, 11 Nov 2002 17:09:48 +0000 |
| Subject: | #20365 [Fbk->Opn]: the modulo operator % doesn't work with negative integers! | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-24600@lists.php.net to get a copy of this message | ||
ID: 20365
User updated by: Ernest@Beinrohr.sk
Reported By: Ernest@Beinrohr.sk
-Status: Feedback
+Status: Open
Bug Type: Math related
Operating System: linux
PHP Version: 4.2.2
New Comment:
Yes, you are right, the output is not NULL, it's -4.
BUT, it should be 6.
PS: but bc gives -4 too, now I do not understand. I suppose, BC is
wrong too. It should be 6. [ -4=6 (mod 10) ]
Previous Comments:
------------------------------------------------------------------------
[2002-11-11 09:53:41] sniper@php.net
Please try using this CVS snapshot:
http://snaps.php.net/php4-latest.tar.gz
For Windows:
http://snaps.php.net/win32/php4-win32-latest.zip
works fine here too..(with 4.3.0-dev) so try the snapshot.
------------------------------------------------------------------------
[2002-11-11 09:51:16] derick@php.net
Works fine (it should output -4):
[derick@kossu derick]$ php
<?php
$a = -4 % 10;
var_dump($a);
?>
int(-4)
Please provide a short script that reproduces this problem.
Derick
------------------------------------------------------------------------
[2002-11-11 09:40:40] Ernest@Beinrohr.sk
PHP's modulo operator cannot work with negative numbers. The positive
ones work fine, but modulo is defined also on negatives ;-)
ex: 10%3 = 1 [php gives 1]
-4%10 = 6 [php gives NULL]
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=20365&edit=1