-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
fix gcd & lcm sign and optimize gcdx and invmod #4811
Conversation
…arguments, use GMP for BigInt invmod
So my take on this is that we should cherry-pick the rational constructor fix for 0.2 and wait on the rest. |
You should also document the behaviour of |
I'd prefer to merge this whole PR. In any case, |
Another omission is that we don't seem to have any test coverage for gcdx etc. Should there be a new test/intfuncs.jl file or would this go into one of the existing test files? |
I guess we could merge this, although I worry that someone else may already be depending on the old sign behavior of |
I'm adding a test case to test/numbers.jl, and found another bug: |
@StefanKarpinski, since the old sign behavior was undocumented, it's not unreasonable to treat it as a bug and to say that people who relied on it are on their own. (In practice, most people doing gcd-like things are probably working with nonnegative integers, though.) |
Hmm, another inconsistency: Looks like this can be fixed simply by using |
More problems with |
The issue is that GMP defines |
@JeffBezanson, yes I noticed. The right thing is to just change the sign in the Another bug: the |
I'm going to merge this and then fix these |
fix gcd & lcm sign and optimize gcdx and invmod
I have a patch to fix the |
Merging this has broken Travis. Here's the test failure log, looks like a test of
|
This must be due to a GMP version difference. For |
A further problem is that since our |
Inverses still exist. e.g. |
In that case we are just up against GMP's incompatible definition of |
Looks like this was fixed by c92e98d. Thanks Jeff! |
The attached patch fixes several bugs (including #4810):
-1
as meaning that the inverse did not exist.Rational
construction was broken for BigInt because of the gcd sign inconsistency.gcdx
was not type-stable (it promoted a result toInt
in one case).I also rewrote
gcdx
non-recursively to make it about 20x faster on my machine, and use the GMPinvmod
function directly forBigInt
.