Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
prestwich authored Sep 11, 2023
2 parents ccfc6f9 + da9f1a4 commit 13ed910
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
25 changes: 25 additions & 0 deletions src/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,28 @@ impl<const BITS: usize, const LIMBS: usize> PartialOrd for Uint<BITS, LIMBS> {
Some(self.cmp(other))
}
}

impl<const BITS: usize, const LIMBS: usize> Uint<BITS, LIMBS> {
/// 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());
}
}

0 comments on commit 13ed910

Please sign in to comment.