From 41480951c5e1d0cf104b5642ba11b181900b3df2 Mon Sep 17 00:00:00 2001 From: Giacomo Fenzi Date: Wed, 9 Feb 2022 18:54:24 +0100 Subject: [PATCH 1/4] Fixed is multiple of --- src/lib.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 9d55722..d06a531 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 } @@ -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 } @@ -981,6 +987,7 @@ 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))); From 1656a2fd143a25312f3386b0ec0946e50a9406d0 Mon Sep 17 00:00:00 2001 From: Giacomo Fenzi Date: Tue, 22 Mar 2022 09:50:28 +0100 Subject: [PATCH 2/4] Added a fex negative tests --- src/lib.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index d06a531..2ba32c1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -991,6 +991,11 @@ macro_rules! impl_integer_for_usize { 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] From 4ebb39d28f13f7c2ec5cc4990c19f403ce370c86 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Fri, 29 Apr 2022 16:05:44 -0700 Subject: [PATCH 3/4] cargo fmt --- src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 2ba32c1..8c19e22 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -992,7 +992,6 @@ macro_rules! impl_integer_for_usize { 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))); From dee9a82166ecada5d54857bf92f4e0ecd40d277a Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Fri, 29 Apr 2022 16:15:26 -0700 Subject: [PATCH 4/4] Release 0.1.45 --- Cargo.toml | 2 +- RELEASES.md | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 4ff8291..f5aac54 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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/*"] diff --git a/RELEASES.md b/RELEASES.md index 05be073..4054433 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -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