Why does PHP think that 600851475143 % 3 equals 0?

Why is it that when I run this script

die("600851475143 mod 3 = " . 600851475143 % 3);

it returns this output

600851475143 mod 3 = 0
and when I perform the math operator 600851475143 / 3 on my Windows calculator I’m given the answer

Obviously there IS a remainder. So why does PHP not see it?

PS - Is it just me?

The number is too large.

2^32        ->   4,294,967,296
Your number -> 600,851,475,143

You may have to use http://www.php.net/manual/en/book.gmp.php


Although PHP generally handles data types for you, in this case - you can’t do standard math because the number is too large.

There’s a function for that™, you can use bc_____ functions to do the math.

Thanks for the responses. I feel less crazy already.

[edit] bcmod worked great, thx :slight_smile: