diff --git a/CHANGELOG.md b/CHANGELOG.md index 61763f27..36547ac5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - `bytemuck` feature ([#292]) +- `Uint::is_zero() -> bool` ([#296]) - `num-traits` features ([#298]) [#292]: https://github.com/recmo/uint/pulls/292 diff --git a/Cargo.toml b/Cargo.toml index 1b5127ef..173c1e66 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -79,6 +79,11 @@ ark-bn254-03 = { version = "0.3.0", package = "ark-bn254" } ark-bn254-04 = { version = "0.4.0", package = "ark-bn254" } criterion = "0.5" +# clap and clap_lex, referred by criterion, have higher a MSRV (clap@4.4.0, clap_lex@0.5.1), +# but are only used by dev-dependencies so we can just pin them +clap = "~4.3" +clap_lex = "<=0.5.0" + rand = "0.8" approx = "0.5" diff --git a/src/cmp.rs b/src/cmp.rs index dec8f3cd..d4575691 100644 --- a/src/cmp.rs +++ b/src/cmp.rs @@ -23,3 +23,28 @@ impl PartialOrd for Uint { Some(self.cmp(other)) } } + +impl Uint { + /// Check if this uint is zero + #[must_use] + pub fn is_zero(&self) -> bool { + self == &Self::ZERO + } +} + +#[cfg(test)] +mod tests { + use crate::Uint; + + #[test] + fn test_is_zero() { + assert!(Uint::<0, 0>::ZERO.is_zero()); + assert!(Uint::<1, 1>::ZERO.is_zero()); + assert!(Uint::<7, 1>::ZERO.is_zero()); + assert!(Uint::<64, 1>::ZERO.is_zero()); + + assert!(!Uint::<1, 1>::from_limbs([1]).is_zero()); + assert!(!Uint::<7, 1>::from_limbs([1]).is_zero()); + assert!(!Uint::<64, 1>::from_limbs([1]).is_zero()); + } +}