php.net |  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
 [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.

Patches

Pull Requests

History

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] jeroen@php.net
float % int could lead to rounding difficulties, which is not a bug.
 [2001-08-07 12:47 UTC] jmcastagnetto@php.net
See Bug #12623 for a more complete explanation on modulus
( http://www.php.net/bugs.php?id=12623 )
 [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-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 31 23:01:28 2024 UTC