Forum Moderators: coopster
As of right now, the interval:
[2147483649,4294967295] produces negative remainders. Anything less than the first number (2147483649) and greater than the larger number (4294967295) all have positive moduli. For example:
echo (2147483649 % 2); #echos -1
#
echo (2147483647 % 2); #echos 1
From tests this seems to only happen within this interval. I've checked the documentation and it seems that one of the user-contributed notes addresses the issue somewhat:
Note that operator % (modulus) works just with integers (between -214748348 and 2147483647) while fmod() works with short and large numbers.
Now, this is the best explanation that I can think of that can possibly be correct:
Integers greater than 2147483647 are considered as type float in PHP. Apparently the modulus operator has problems with dealing with floats? So now the problem I have with this explanation is that there is an upper limit to this behavior, 4294967295. Integers greater than this work normally which doesn't work with my reasoning. Does anyone have a reasonable explanation for this?
It kind of bugs me ;)
Thanks!
2147483647 = 01111111111111111111111111111111
2147483649 = 10000000000000000000000000000001
4294967295 = 11111111111111111111111111111111
4294967295 looks like the max for an unsigned 32 bit integer, I wonder if php assumes that any 32 bit integer with a 1 in the first column is a signed int, therefore a negative number?
-sned
Is a whole number [webmasterworld.com]
testing post variables to be an integer [webmasterworld.com]
getenv("REMOTE_ADDR") [webmasterworld.com]
Thanks again :)