Skip to content

Commit

Permalink
Merge pull request #379 from DaniPopes/is-zero
Browse files Browse the repository at this point in the history
chore: use is_zero more
  • Loading branch information
prestwich committed Jun 15, 2024
2 parents 345af9e + d3822f8 commit e9044fb
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
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

0 comments on commit e9044fb

Please sign in to comment.