Use correct formula
This commit is contained in:
parent
07df43b034
commit
40cbe1ff20
|
@ -668,11 +668,8 @@ impl_integer_for_usize!(usize, test_integer_usize);
|
||||||
/// Calculate r * a / b, avoiding overflows and fractions.
|
/// Calculate r * a / b, avoiding overflows and fractions.
|
||||||
fn multiply_and_divide<T: Integer + Clone>(r: T, a: T, b: T) -> T {
|
fn multiply_and_divide<T: Integer + Clone>(r: T, a: T, b: T) -> T {
|
||||||
// See http://blog.plover.com/math/choose-2.html for the idea.
|
// See http://blog.plover.com/math/choose-2.html for the idea.
|
||||||
//
|
|
||||||
// This depends on the fact that `b` must evenly divide `r*a`, as that's
|
|
||||||
// what lets you know that `b/gcd(r, b)` divides `a` evenly.
|
|
||||||
let g = gcd(r.clone(), b.clone());
|
let g = gcd(r.clone(), b.clone());
|
||||||
(r/g.clone()) * (a / (b/g))
|
(r/g.clone() * a) / (b/g)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Calculate the binomial coefficient.
|
/// Calculate the binomial coefficient.
|
||||||
|
|
Loading…
Reference in New Issue