Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use is_zero more #379

Merged
merged 2 commits into from
Jun 15, 2024
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
6 changes: 3 additions & 3 deletions src/div.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ impl<const BITS: usize, const LIMBS: usize> Uint<BITS, LIMBS> {
#[must_use]
#[allow(clippy::missing_const_for_fn)] // False positive
pub fn checked_div(self, rhs: Self) -> Option<Self> {
if rhs == Self::ZERO {
if rhs.is_zero() {
return None;
}
Some(self.div(rhs))
Expand All @@ -18,7 +18,7 @@ impl<const BITS: usize, const LIMBS: usize> Uint<BITS, LIMBS> {
#[must_use]
#[allow(clippy::missing_const_for_fn)] // False positive
pub fn checked_rem(self, rhs: Self) -> Option<Self> {
if rhs == Self::ZERO {
if rhs.is_zero() {
return None;
}
Some(self.rem(rhs))
Expand All @@ -35,7 +35,7 @@ impl<const BITS: usize, const LIMBS: usize> Uint<BITS, LIMBS> {
pub fn div_ceil(self, rhs: Self) -> Self {
assert!(rhs != Self::ZERO, "Division by zero");
let (q, r) = self.div_rem(rhs);
if r == Self::ZERO {
if r.is_zero() {
q
} else {
q + Self::from(1)
Expand Down
2 changes: 1 addition & 1 deletion src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ impl<const BITS: usize, const LIMBS: usize> Uint<BITS, LIMBS> {
#[inline]
#[must_use]
pub fn checked_log(self, base: Self) -> Option<usize> {
if base < Self::from(2) || self == Self::ZERO {
if base < Self::from(2) || self.is_zero() {
return None;
}
Some(self.log(base))
Expand Down
6 changes: 3 additions & 3 deletions src/modular.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl<const BITS: usize, const LIMBS: usize> Uint<BITS, LIMBS> {
#[inline]
#[must_use]
pub fn reduce_mod(mut self, modulus: Self) -> Self {
if modulus == Self::ZERO {
if modulus.is_zero() {
return Self::ZERO;
}
if self >= modulus {
Expand Down Expand Up @@ -53,7 +53,7 @@ impl<const BITS: usize, const LIMBS: usize> Uint<BITS, LIMBS> {
#[inline]
#[must_use]
pub fn mul_mod(self, rhs: Self, mut modulus: Self) -> Self {
if modulus == Self::ZERO {
if modulus.is_zero() {
return Self::ZERO;
}

Expand Down Expand Up @@ -84,7 +84,7 @@ impl<const BITS: usize, const LIMBS: usize> Uint<BITS, LIMBS> {
#[inline]
#[must_use]
pub fn pow_mod(mut self, mut exp: Self, modulus: Self) -> Self {
if modulus == Self::ZERO || modulus <= Self::from(1) {
if modulus.is_zero() || modulus <= Self::from(1) {
// Also covers Self::BITS == 0
return Self::ZERO;
}
Expand Down
2 changes: 1 addition & 1 deletion src/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl<const BITS: usize, const LIMBS: usize> Uint<BITS, LIMBS> {
assert!(degree > 0, "degree must be greater than zero");

// Handle zero case (including BITS == 0).
if self == Self::ZERO {
if self.is_zero() {
return Self::ZERO;
}

Expand Down
4 changes: 2 additions & 2 deletions src/special.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ impl<const BITS: usize, const LIMBS: usize> Uint<BITS, LIMBS> {
#[inline]
#[must_use]
pub fn checked_next_multiple_of(self, rhs: Self) -> Option<Self> {
if rhs == Self::ZERO {
if rhs.is_zero() {
return None;
}
let (q, r) = self.div_rem(rhs);
if r == Self::ZERO {
if r.is_zero() {
return Some(self);
}
let q = q.checked_add(Self::from(1))?;
Expand Down
Loading