|  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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
48 + 2 = ?
Subscribe to this entry?

 [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-2022 The PHP Group
All rights reserved.
Last updated: Fri Dec 02 16:05:54 2022 UTC