Skip to content

Commit

Permalink
Use div_ceil(), addressing clippy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
OTheDev committed Dec 3, 2024
1 parent cd67401 commit ac7a307
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions arbi/src/builtin_int_methods/from_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl Arbi {
return Arbi::zero();
}
let mut num =
Arbi::with_capacity((bytes.len() + DIGIT_BYTES - 1) / DIGIT_BYTES);
Arbi::with_capacity(usize::div_ceil(bytes.len(), DIGIT_BYTES));
let mut digit = 0;
for (i, &byte) in bytes.iter().enumerate() {
digit |= (byte as Digit) << ((i % DIGIT_BYTES) * 8);
Expand Down Expand Up @@ -74,7 +74,7 @@ impl Arbi {
return Arbi::zero();
}
let mut num =
Arbi::with_capacity((bytes.len() + DIGIT_BYTES - 1) / DIGIT_BYTES);
Arbi::with_capacity(usize::div_ceil(bytes.len(), DIGIT_BYTES));
let mut digit = 0;
for (i, &byte) in bytes.iter().rev().enumerate() {
digit |= (byte as Digit) << ((i % DIGIT_BYTES) * 8);
Expand Down
10 changes: 10 additions & 0 deletions arbi/src/uints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,16 @@ impl UnsignedUtilities for $t {
}
}

/// Calculates the quotient of `self` and `rhs`, rounding the result towards
/// positive infinity.
///
/// # Panics
/// This function will panic if `rhs` is zero.
///
/// # Examples
/// ```
/// assert_eq!(u64::div_ceil(9, 5), 2);
/// ```
fn div_ceil_(x: Self, y: Self) -> Self {
if x == 0 {
0
Expand Down

0 comments on commit ac7a307

Please sign in to comment.