Skip to content

Commit

Permalink
rust: use explicitily Integer::div_ceil
Browse files Browse the repository at this point in the history
  • Loading branch information
catenacyber committed Sep 3, 2021
1 parent c73cffc commit ead4a06
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/biguint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ impl Roots for BigUint {
// Try to guess by scaling down such that it does fit in `f64`.
// With some (x * 2ⁿᵏ), its nth root ≈ (ⁿ√x * 2ᵏ)
let extra_bits = bits - (core::f64::MAX_EXP as u64 - 1);
let root_scale = extra_bits.div_ceil(&n64);
let root_scale = Integer::div_ceil(&extra_bits, &n64);
let scale = root_scale * n64;
if scale < bits && bits - scale > n64 {
(self >> scale).nth_root(n) << root_scale
Expand Down
12 changes: 6 additions & 6 deletions src/biguint/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ fn from_inexact_bitwise_digits_le(v: &[u8], bits: u8) -> BigUint {
debug_assert!(v.iter().all(|&c| BigDigit::from(c) < (1 << bits)));

let big_digits = (v.len() as u64)
.saturating_mul(bits.into())
.div_ceil(&big_digit::BITS.into())
.saturating_mul(bits.into());
let big_digits = Integer::div_ceil(&big_digits, &big_digit::BITS.into())
.to_usize()
.unwrap_or(core::usize::MAX);
let mut data = Vec::with_capacity(big_digits);
Expand Down Expand Up @@ -581,8 +581,8 @@ pub(super) fn to_bitwise_digits_le(u: &BigUint, bits: u8) -> Vec<u8> {
let mask: BigDigit = (1 << bits) - 1;
let digits_per_big_digit = big_digit::BITS / bits;
let digits = u
.bits()
.div_ceil(&u64::from(bits))
.bits();
let digits = Integer::div_ceil(&digits, &u64::from(bits))
.to_usize()
.unwrap_or(core::usize::MAX);
let mut res = Vec::with_capacity(digits);
Expand All @@ -609,8 +609,8 @@ fn to_inexact_bitwise_digits_le(u: &BigUint, bits: u8) -> Vec<u8> {

let mask: BigDigit = (1 << bits) - 1;
let digits = u
.bits()
.div_ceil(&u64::from(bits))
.bits();
let digits = Integer::div_ceil(&digits, &u64::from(bits))
.to_usize()
.unwrap_or(core::usize::MAX);
let mut res = Vec::with_capacity(digits);
Expand Down

0 comments on commit ead4a06

Please sign in to comment.