Skip to content

Commit 8ee0b9a

Browse files
bors[bot]catenacybercuviper
authored
Merge #219
219: rust: use explicitily Integer::div_ceil r=cuviper a=catenacyber Fixes #218 cf rust-lang/rust#88581 Co-authored-by: Philippe Antoine <[email protected]> Co-authored-by: Josh Stone <[email protected]>
2 parents c73cffc + 1469ed6 commit 8ee0b9a

File tree

6 files changed

+16
-13
lines changed

6 files changed

+16
-13
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ categories = [ "algorithms", "data-structures", "science" ]
88
license = "MIT OR Apache-2.0"
99
name = "num-bigint"
1010
repository = "https://github.com/rust-num/num-bigint"
11-
version = "0.4.1"
11+
version = "0.4.2"
1212
readme = "README.md"
1313
build = "build.rs"
1414
exclude = ["/bors.toml", "/ci/*", "/.github/*"]

RELEASES.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# Release 0.4.2 (2021-09-03)
2+
3+
- [Use explicit `Integer::div_ceil` to avoid the new unstable method.][219]
4+
5+
**Contributors**: @catenacyber, @cuviper
6+
7+
[219]: https://github.com/rust-num/num-bigint/pull/219
8+
19
# Release 0.4.1 (2021-08-27)
210

311
- [Fixed scalar divide-by-zero panics.][200]

src/bigrand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl<R: Rng + ?Sized> RandBigInt for R {
6666
let len = (digits + (rem > 0) as u64)
6767
.to_usize()
6868
.expect("capacity overflow");
69-
let native_digits = bit_size.div_ceil(&64);
69+
let native_digits = Integer::div_ceil(&bit_size, &64);
7070
let native_len = native_digits.to_usize().expect("capacity overflow");
7171
let mut data = vec![0u64; native_len];
7272
unsafe {

src/biguint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ impl Roots for BigUint {
395395
// Try to guess by scaling down such that it does fit in `f64`.
396396
// With some (x * 2ⁿᵏ), its nth root ≈ (ⁿ√x * 2ᵏ)
397397
let extra_bits = bits - (core::f64::MAX_EXP as u64 - 1);
398-
let root_scale = extra_bits.div_ceil(&n64);
398+
let root_scale = Integer::div_ceil(&extra_bits, &n64);
399399
let scale = root_scale * n64;
400400
if scale < bits && bits - scale > n64 {
401401
(self >> scale).nth_root(n) << root_scale

src/biguint/convert.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,8 @@ fn from_inexact_bitwise_digits_le(v: &[u8], bits: u8) -> BigUint {
6565
debug_assert!(!v.is_empty() && bits <= 8 && big_digit::BITS % bits != 0);
6666
debug_assert!(v.iter().all(|&c| BigDigit::from(c) < (1 << bits)));
6767

68-
let big_digits = (v.len() as u64)
69-
.saturating_mul(bits.into())
70-
.div_ceil(&big_digit::BITS.into())
68+
let total_bits = (v.len() as u64).saturating_mul(bits.into());
69+
let big_digits = Integer::div_ceil(&total_bits, &big_digit::BITS.into())
7170
.to_usize()
7271
.unwrap_or(core::usize::MAX);
7372
let mut data = Vec::with_capacity(big_digits);
@@ -580,9 +579,7 @@ pub(super) fn to_bitwise_digits_le(u: &BigUint, bits: u8) -> Vec<u8> {
580579
let last_i = u.data.len() - 1;
581580
let mask: BigDigit = (1 << bits) - 1;
582581
let digits_per_big_digit = big_digit::BITS / bits;
583-
let digits = u
584-
.bits()
585-
.div_ceil(&u64::from(bits))
582+
let digits = Integer::div_ceil(&u.bits(), &u64::from(bits))
586583
.to_usize()
587584
.unwrap_or(core::usize::MAX);
588585
let mut res = Vec::with_capacity(digits);
@@ -608,9 +605,7 @@ fn to_inexact_bitwise_digits_le(u: &BigUint, bits: u8) -> Vec<u8> {
608605
debug_assert!(!u.is_zero() && bits <= 8 && big_digit::BITS % bits != 0);
609606

610607
let mask: BigDigit = (1 << bits) - 1;
611-
let digits = u
612-
.bits()
613-
.div_ceil(&u64::from(bits))
608+
let digits = Integer::div_ceil(&u.bits(), &u64::from(bits))
614609
.to_usize()
615610
.unwrap_or(core::usize::MAX);
616611
let mut res = Vec::with_capacity(digits);

src/biguint/serde.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl<'de> Visitor<'de> for U32Visitor {
8989
use num_integer::Integer;
9090

9191
let u32_len = seq.size_hint().unwrap_or(0);
92-
let len = u32_len.div_ceil(&2);
92+
let len = Integer::div_ceil(&u32_len, &2);
9393
let mut data = Vec::with_capacity(len);
9494

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

0 commit comments

Comments
 (0)