Skip to content

Commit

Permalink
Merge #219
Browse files Browse the repository at this point in the history
219: rust: use explicitily Integer::div_ceil r=cuviper a=catenacyber

Fixes #218

cf rust-lang/rust#88581

Co-authored-by: Philippe Antoine <contact@catenacyber.fr>
Co-authored-by: Josh Stone <cuviper@gmail.com>
  • Loading branch information
3 people authored Sep 3, 2021
2 parents c73cffc + 1469ed6 commit 8ee0b9a
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ categories = [ "algorithms", "data-structures", "science" ]
license = "MIT OR Apache-2.0"
name = "num-bigint"
repository = "https://github.com/rust-num/num-bigint"
version = "0.4.1"
version = "0.4.2"
readme = "README.md"
build = "build.rs"
exclude = ["/bors.toml", "/ci/*", "/.github/*"]
Expand Down
8 changes: 8 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# Release 0.4.2 (2021-09-03)

- [Use explicit `Integer::div_ceil` to avoid the new unstable method.][219]

**Contributors**: @catenacyber, @cuviper

[219]: https://github.com/rust-num/num-bigint/pull/219

# Release 0.4.1 (2021-08-27)

- [Fixed scalar divide-by-zero panics.][200]
Expand Down
2 changes: 1 addition & 1 deletion src/bigrand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl<R: Rng + ?Sized> RandBigInt for R {
let len = (digits + (rem > 0) as u64)
.to_usize()
.expect("capacity overflow");
let native_digits = bit_size.div_ceil(&64);
let native_digits = Integer::div_ceil(&bit_size, &64);
let native_len = native_digits.to_usize().expect("capacity overflow");
let mut data = vec![0u64; native_len];
unsafe {
Expand Down
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
13 changes: 4 additions & 9 deletions src/biguint/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,8 @@ fn from_inexact_bitwise_digits_le(v: &[u8], bits: u8) -> BigUint {
debug_assert!(!v.is_empty() && bits <= 8 && big_digit::BITS % bits != 0);
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())
let total_bits = (v.len() as u64).saturating_mul(bits.into());
let big_digits = Integer::div_ceil(&total_bits, &big_digit::BITS.into())
.to_usize()
.unwrap_or(core::usize::MAX);
let mut data = Vec::with_capacity(big_digits);
Expand Down Expand Up @@ -580,9 +579,7 @@ pub(super) fn to_bitwise_digits_le(u: &BigUint, bits: u8) -> Vec<u8> {
let last_i = u.data.len() - 1;
let mask: BigDigit = (1 << bits) - 1;
let digits_per_big_digit = big_digit::BITS / bits;
let digits = u
.bits()
.div_ceil(&u64::from(bits))
let digits = Integer::div_ceil(&u.bits(), &u64::from(bits))
.to_usize()
.unwrap_or(core::usize::MAX);
let mut res = Vec::with_capacity(digits);
Expand All @@ -608,9 +605,7 @@ fn to_inexact_bitwise_digits_le(u: &BigUint, bits: u8) -> Vec<u8> {
debug_assert!(!u.is_zero() && bits <= 8 && big_digit::BITS % bits != 0);

let mask: BigDigit = (1 << bits) - 1;
let digits = u
.bits()
.div_ceil(&u64::from(bits))
let digits = Integer::div_ceil(&u.bits(), &u64::from(bits))
.to_usize()
.unwrap_or(core::usize::MAX);
let mut res = Vec::with_capacity(digits);
Expand Down
2 changes: 1 addition & 1 deletion src/biguint/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl<'de> Visitor<'de> for U32Visitor {
use num_integer::Integer;

let u32_len = seq.size_hint().unwrap_or(0);
let len = u32_len.div_ceil(&2);
let len = Integer::div_ceil(&u32_len, &2);
let mut data = Vec::with_capacity(len);

while let Some(lo) = seq.next_element::<u32>()? {
Expand Down

0 comments on commit 8ee0b9a

Please sign in to comment.