-
Notifications
You must be signed in to change notification settings - Fork 49
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
Define extended GCD, combined GCD+LCM #19
Conversation
6accdbc
to
f6f06f8
Compare
Rebased, PTAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/lib.rs
Outdated
#[cfg_attr(array_clone, derive(Clone))] | ||
pub struct ExtendedGcd<A> { | ||
pub gcd: A, | ||
pub coeffs: [A; 2], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use separate x
and y
, so we can document it something like this:
Bézout's identity — Let a and b be integers with greatest common divisor d. Then, there exist integers x and y such that ax + by = d.
Then we also don't have to worry about array_clone
.
src/lib.rs
Outdated
let q = r.1.clone() / r.0.clone(); | ||
let f = |r: &mut (Self, Self)| { | ||
mem::swap(&mut r.0, &mut r.1); | ||
r.0 -= q.clone() * r.1.clone(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, it's a little annoying to have SubAssign
in the API just for this, and AFAICT it's only needed because you're working through &mut
. If the closure used values instead, or if you just flattened these three calls, then you could move and then reassign r.0
just fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should require Signed
though -- I believe it's useless for unsigned integers, since one of the coefficients must be negative, except the degenerate case with zeros.
@cuviper All done, PTAL |
Thanks! bors r+ |
Build failed |
Sorry, that was my fault. bors r+ |
Build succeeded |
No description provided.