Skip to content

Commit

Permalink
fix(lcm): Also added fix for BigUInt
Browse files Browse the repository at this point in the history
Same as previous commit, but applies the change to BigUInt as well.
  • Loading branch information
TheLetterTheta committed Aug 23, 2019
1 parent 500d250 commit e247980
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/biguint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1320,7 +1320,11 @@ impl Integer for BigUint {
/// Calculates the Lowest Common Multiple (LCM) of the number and `other`.
#[inline]
fn lcm(&self, other: &BigUint) -> BigUint {
self / self.gcd(other) * other
if self.is_zero() && other.is_zero() {
Self::zero()
} else {
self / self.gcd(other) * other
}
}

/// Deprecated, use `is_multiple_of` instead.
Expand Down
1 change: 1 addition & 0 deletions tests/biguint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,7 @@ fn test_lcm() {
assert_eq!(big_a.lcm(&big_b), big_c);
}

check(0, 0, 0);
check(1, 0, 0);
check(0, 1, 0);
check(1, 1, 1);
Expand Down

0 comments on commit e247980

Please sign in to comment.