Skip to content

Commit 4148095

Browse files
committed
Fixed is multiple of
1 parent d5267dc commit 4148095

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,9 @@ macro_rules! impl_integer_for_isize {
543543
/// Returns `true` if the number is a multiple of `other`.
544544
#[inline]
545545
fn is_multiple_of(&self, other: &Self) -> bool {
546+
if other.is_zero() {
547+
return self.is_zero();
548+
}
546549
*self % *other == 0
547550
}
548551

@@ -885,6 +888,9 @@ macro_rules! impl_integer_for_usize {
885888
/// Returns `true` if the number is a multiple of `other`.
886889
#[inline]
887890
fn is_multiple_of(&self, other: &Self) -> bool {
891+
if other.is_zero() {
892+
return self.is_zero();
893+
}
888894
*self % *other == 0
889895
}
890896

@@ -981,6 +987,7 @@ macro_rules! impl_integer_for_usize {
981987

982988
#[test]
983989
fn test_is_multiple_of() {
990+
assert!((0 as $T).is_multiple_of(&(0 as $T)));
984991
assert!((6 as $T).is_multiple_of(&(6 as $T)));
985992
assert!((6 as $T).is_multiple_of(&(3 as $T)));
986993
assert!((6 as $T).is_multiple_of(&(1 as $T)));

0 commit comments

Comments
 (0)