Skip to content

Commit

Permalink
Leverage div_ceil (#688)
Browse files Browse the repository at this point in the history
Fixes clippy warnings about `div_ceil` which are appearing on recent
nightlies
  • Loading branch information
tarcieri authored Oct 8, 2024
1 parent d5f8569 commit 8f3f9f2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#[macro_export]
macro_rules! nlimbs {
($bits:expr) => {
(($bits + $crate::Limb::BITS - 1) / $crate::Limb::BITS) as usize
u32::div_ceil($bits, $crate::Limb::BITS) as usize
};
}

Expand Down
6 changes: 3 additions & 3 deletions src/uint/div.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl<const LIMBS: usize> Uint<LIMBS> {

let dbits = rhs.0.bits();
assert!(dbits > 0, "zero divisor");
let dwords = (dbits + Limb::BITS - 1) / Limb::BITS;
let dwords = dbits.div_ceil(Limb::BITS);
let lshift = (Limb::BITS - (dbits % Limb::BITS)) % Limb::BITS;

// Shift entire divisor such that the high bit is set
Expand Down Expand Up @@ -198,7 +198,7 @@ impl<const LIMBS: usize> Uint<LIMBS> {
// Further explanation at https://janmr.com/blog/2014/04/basic-multiple-precision-long-division/

let dbits = rhs.0.bits_vartime();
let yc = ((dbits + Limb::BITS - 1) / Limb::BITS) as usize;
let yc = dbits.div_ceil(Limb::BITS) as usize;

// Short circuit for small or extra large divisors
if yc == 1 {
Expand Down Expand Up @@ -319,7 +319,7 @@ impl<const LIMBS: usize> Uint<LIMBS> {
/// to `self`.
pub const fn rem_wide_vartime(lower_upper: (Self, Self), rhs: &NonZero<Self>) -> Self {
let dbits = rhs.0.bits_vartime();
let yc = ((dbits + Limb::BITS - 1) / Limb::BITS) as usize;
let yc = dbits.div_ceil(Limb::BITS) as usize;

// If the divisor is a single limb, use limb division
if yc == 1 {
Expand Down
4 changes: 2 additions & 2 deletions src/uint/rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub(crate) fn random_bits_core(
let buffer: Word = 0;
let mut buffer = buffer.to_be_bytes();

let nonzero_limbs = ((bit_length + Limb::BITS - 1) / Limb::BITS) as usize;
let nonzero_limbs = bit_length.div_ceil(Limb::BITS) as usize;
let partial_limb = bit_length % Limb::BITS;
let mask = Word::MAX >> ((Word::BITS - partial_limb) % Word::BITS);

Expand Down Expand Up @@ -111,7 +111,7 @@ pub(super) fn random_mod_core<T>(
T: AsMut<[Limb]> + ConstantTimeLess + Zero,
{
let n_bytes = ((n_bits + 7) / 8) as usize;
let n_limbs = ((n_bits + Limb::BITS - 1) / Limb::BITS) as usize;
let n_limbs = n_bits.div_ceil(Limb::BITS) as usize;
let hi_bytes = n_bytes - (n_limbs - 1) * Limb::BYTES;

let mut bytes = Limb::ZERO.to_le_bytes();
Expand Down

0 comments on commit 8f3f9f2

Please sign in to comment.