Skip to content

Commit

Permalink
Merge #240
Browse files Browse the repository at this point in the history
240: Fix is_multiple_of with a 0 arg r=cuviper a=cuviper

See also: rust-num/num-integer#47

Co-authored-by: Josh Stone <cuviper@gmail.com>
  • Loading branch information
bors[bot] and cuviper committed Feb 11, 2023
2 parents 51eb448 + 016c04a commit 34f48d1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/biguint.rs
Expand Up @@ -283,6 +283,9 @@ impl Integer for BigUint {
/// Returns `true` if the number is a multiple of `other`.
#[inline]
fn is_multiple_of(&self, other: &BigUint) -> bool {
if other.is_zero() {
return self.is_zero();
}
(self % other).is_zero()
}

Expand Down
12 changes: 12 additions & 0 deletions tests/bigint.rs
Expand Up @@ -1036,6 +1036,18 @@ fn test_lcm() {
check(11, 5, 55);
}

#[test]
fn test_is_multiple_of() {
assert!(BigInt::from(0).is_multiple_of(&BigInt::from(0)));
assert!(BigInt::from(6).is_multiple_of(&BigInt::from(6)));
assert!(BigInt::from(6).is_multiple_of(&BigInt::from(3)));
assert!(BigInt::from(6).is_multiple_of(&BigInt::from(1)));

assert!(!BigInt::from(42).is_multiple_of(&BigInt::from(5)));
assert!(!BigInt::from(5).is_multiple_of(&BigInt::from(3)));
assert!(!BigInt::from(42).is_multiple_of(&BigInt::from(0)));
}

#[test]
fn test_next_multiple_of() {
assert_eq!(
Expand Down
12 changes: 12 additions & 0 deletions tests/biguint.rs
Expand Up @@ -1085,6 +1085,18 @@ fn test_lcm() {
check(99, 17, 1683);
}

#[test]
fn test_is_multiple_of() {
assert!(BigUint::from(0u32).is_multiple_of(&BigUint::from(0u32)));
assert!(BigUint::from(6u32).is_multiple_of(&BigUint::from(6u32)));
assert!(BigUint::from(6u32).is_multiple_of(&BigUint::from(3u32)));
assert!(BigUint::from(6u32).is_multiple_of(&BigUint::from(1u32)));

assert!(!BigUint::from(42u32).is_multiple_of(&BigUint::from(5u32)));
assert!(!BigUint::from(5u32).is_multiple_of(&BigUint::from(3u32)));
assert!(!BigUint::from(42u32).is_multiple_of(&BigUint::from(0u32)));
}

#[test]
fn test_next_multiple_of() {
assert_eq!(
Expand Down

0 comments on commit 34f48d1

Please sign in to comment.