|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #12155 modulus %
Submitted: 2001-07-13 18:29 UTC Modified: 2001-08-07 14:23 UTC
From: yaragn at hotmail dot com Assigned:
Status: Not a bug Package: Math related
PHP Version: 4.0.5 OS: linux 2.4.3
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: yaragn at hotmail dot com
New email:
PHP Version: OS:


 [2001-07-13 18:29 UTC] yaragn at hotmail dot com
Appears to be broken on large(r) integers. Is this a limitation on the type used? (I am coding working ip2long/long2ip).

$temp = 3194548456;
print "correct: " . ($temp - 255*floor($temp/255));
print "php: " . $temp % 255 . "<br>";

as defined in maths, the % is equiv to MOD(n, d) = n - d*INT(n/d)
where n is the number, d is the divisor.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2001-07-13 20:34 UTC] yaragn at hotmail dot com
Integer limited to 2047000000 so there.
 [2001-08-06 19:57 UTC]
float % int could lead to rounding difficulties, which is not a bug.
 [2001-08-07 12:47 UTC]
See Bug #12623 for a more complete explanation on modulus
( )
 [2002-06-01 16:47 UTC] phil dot cavazos at salemhospital dot org
The modulus operator seems to also fail with negative integers.
The operation -1%7 should return 6 but instead returns -1
on negative numbers it simply returns the divisor
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sun Oct 01 00:01:25 2023 UTC