Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
roadster31 opened this issue Oct 27, 2015 · 1 comment
Open

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

roadster31 opened this issue Oct 27, 2015 · 1 comment

Comments

@roadster31
Copy link
Contributor

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
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants