thelia / math-tools

Number management library
GNU Lesser General Public License v3.0
0 stars 2 forks source link

GCD does not work properly on big integers (> PHP_INT_MAX) #2

Open roadster31 opened 9 years ago

roadster31 commented 9 years ago

GCG::getGCD() uses is_int() to check if a number is an integer, but this function returns false if this number is greater than PHP_INT_MAX.

roadster31 commented 6 years ago

I'm reopening this issue, as the modulo (%) operator is casting its operands to integers, which may cause overflow if operands are > PHP_INT_MAX.

Example on a 32 bit machine, where PHP_INT_MAX = 2147483647 :

16748050000 % 1148700 =-1056684 ! (the proper result is 4000)

Using fmod() (floating point modulo) is not a proper solution, as floating point may cause a lost of precision on large numbers.