Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ categories = ["algorithms", "science", "no-std"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/rust-num/num-integer"
name = "num-integer"
version = "0.1.44"
version = "0.1.45"
readme = "README.md"
build = "build.rs"
exclude = ["/bors.toml", "/ci/*", "/.github/*"]
Expand Down
9 changes: 9 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# Release 0.1.45 (2022-04-29)

- [`Integer::is_multiple_of` now handles a 0 argument without panicking][47]
for primitive integers.

**Contributors**: @cuviper, @WizardOfMenlo

[47]: https://github.com/rust-num/num-integer/pull/47

# Release 0.1.44 (2020-10-29)

- [The "i128" feature now bypasses compiler probing][35]. The build script
Expand Down
11 changes: 11 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,9 @@ macro_rules! impl_integer_for_isize {
/// Returns `true` if the number is a multiple of `other`.
#[inline]
fn is_multiple_of(&self, other: &Self) -> bool {
if other.is_zero() {
return self.is_zero();
}
*self % *other == 0
}

Expand Down Expand Up @@ -885,6 +888,9 @@ macro_rules! impl_integer_for_usize {
/// Returns `true` if the number is a multiple of `other`.
#[inline]
fn is_multiple_of(&self, other: &Self) -> bool {
if other.is_zero() {
return self.is_zero();
}
*self % *other == 0
}

Expand Down Expand Up @@ -981,9 +987,14 @@ macro_rules! impl_integer_for_usize {

#[test]
fn test_is_multiple_of() {
assert!((0 as $T).is_multiple_of(&(0 as $T)));
assert!((6 as $T).is_multiple_of(&(6 as $T)));
assert!((6 as $T).is_multiple_of(&(3 as $T)));
assert!((6 as $T).is_multiple_of(&(1 as $T)));

assert!(!(42 as $T).is_multiple_of(&(5 as $T)));
assert!(!(5 as $T).is_multiple_of(&(3 as $T)));
assert!(!(42 as $T).is_multiple_of(&(0 as $T)));
}

#[test]
Expand Down