Shocking limit when modulo 64 bit integers in PHP

Viewed 81

quick, yet exciting question about PHP mathematical behaviour.

Why do I get an error

<b>Fatal error</b>: Uncaught DivisionByZeroError: Modulo by zero in [...][...]:2

while executing the following

pow(2, 80) % (pow(2, 64) - 1024)

but not this one

pow(2, 80) % (pow(2, 64) - 1025)

It looks like PHP limits modulo operations, by using last 10 bits of the number for something else, while reaching 64 bit limit.

Anyone can explain please?

Note

This problem does not appear when using modulo with binary number, as

pow(2, 80) % 0b100000000000000000000000000000000000000000000000000000000000000000

(don't count, its 2^65)

0 Answers
Related