To use modular exponentiation as you would require when using the Fermat Primality Test with large numbers (100,000+), it calls for some very large calculations.
When I multiply two large numbers (eg: 62574 and 62574) PHP seems to cast the result to a float. Getting the modulus value of that returns strange values.
$x = 62574 * 62574;
var_dump($x); // float(3915505476) ... correct
var_dump($x % 104659); // int(-72945) ... wtf.
Is there any way to make PHP perform these calculations properly? Alternatively, is there another method for finding modulus values that would work for large numbers?
%
uses a wrapper for integers. – Greedvar_dump($x)
they get an int, not a float. However, if they try doing$x = PHP_INT_MAX + 1
instead of$x = 62574 * 62574;
, they will be able to reproduce the rest of the madness successfully. – Cymose