Skip to content

Commit 9cf4da1

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 + 22940ca commit 9cf4da1

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
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/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);

0 commit comments

Comments
 (0)