Merge #43
43: Merge num-bigint-0.1.x and update pending release notes r=cuviper a=cuviper Co-authored-by: Josh Stone <cuviper@gmail.com> Co-authored-by: bors[bot] <bors[bot]@users.noreply.github.com>
This commit is contained in:
commit
79e5aa9dd7
@ -15,6 +15,9 @@ readme = "README.md"
|
||||
[[bench]]
|
||||
name = "bigint"
|
||||
|
||||
[[bench]]
|
||||
name = "factorial"
|
||||
|
||||
[[bench]]
|
||||
name = "gcd"
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
[](https://crates.io/crates/num-bigint)
|
||||
[](https://docs.rs/num-bigint)
|
||||

|
||||

|
||||
[](https://travis-ci.org/rust-num/num-bigint)
|
||||
|
||||
Big integer types for Rust, `BigInt` and `BigUint`.
|
||||
@ -13,7 +13,7 @@ Add this to your `Cargo.toml`:
|
||||
|
||||
```toml
|
||||
[dependencies]
|
||||
num-bigint = "0.1"
|
||||
num-bigint = "0.2"
|
||||
```
|
||||
|
||||
and this to your crate root:
|
||||
@ -28,7 +28,7 @@ Release notes are available in [RELEASES.md](RELEASES.md).
|
||||
|
||||
## Compatibility
|
||||
|
||||
The `num-bigint` crate is tested for rustc 1.8 and greater.
|
||||
The `num-bigint` crate is tested for rustc 1.15 and greater.
|
||||
|
||||
## Alternatives
|
||||
|
||||
@ -38,7 +38,7 @@ table offers a brief comparison to a few alternatives.
|
||||
|
||||
| Crate | License | Min rustc | Implementation |
|
||||
| :--------------- | :------------- | :-------- | :------------- |
|
||||
| **`num-bigint`** | MIT/Apache-2.0 | 1.8 | pure rust |
|
||||
| **`num-bigint`** | MIT/Apache-2.0 | 1.15 | pure rust |
|
||||
| [`ramp`] | Apache-2.0 | nightly | rust and inline assembly |
|
||||
| [`rug`] | LGPL-3.0+ | 1.18 | bundles [GMP] via [`gmp-mpfr-sys`] |
|
||||
| [`rust-gmp`] | MIT | stable? | links to [GMP] |
|
||||
|
38
RELEASES.md
38
RELEASES.md
@ -1,14 +1,48 @@
|
||||
# Release 0.2.0 (pending)
|
||||
|
||||
- :warning: [num-bigint now requires rustc 1.15 or greater][23].
|
||||
- :warning: [`num-bigint` now requires rustc 1.15 or greater][23].
|
||||
- :warning: [The `rand` and `serde` dependencies have been updated to 0.4 and 1.0][24]
|
||||
respectively, and neither are enabled by default. The `rustc-serialize`
|
||||
crate is no longer supported by `num-bigint`.
|
||||
- :warning: [`Shr for BigInt` now rounds down][8] rather than toward zero,
|
||||
matching the behavior of the primitive integers for negative values.
|
||||
- :warning: [`ParseBigIntError` is now an opaque type][37].
|
||||
- :warning: [The `big_digit` module is no longer public][38], nor are the
|
||||
`BigDigit` and `DoubleBigDigit` types and `ZERO_BIG_DIGIT` constant that
|
||||
were re-exported in the crate root. Public APIs which deal in digits, like
|
||||
`BigUint::from_slice`, will now always be base-`u32`.
|
||||
- [`BigInt` and `BigUint` now implement `Product` and `Sum`][22] for iterators
|
||||
of any item that we can `Mul` and `Add`, respectively. For example, a
|
||||
factorial can now be simply: `let f: BigUint = (1u32..1000).product();`
|
||||
- [`BigInt` now supports two's-complement logic operations][26], namely
|
||||
`BitAnd`, `BitOr`, `BitXor`, and `Not`. These act conceptually as if each
|
||||
number had an infinite prefix of `0` or `1` bits for positive or negative.
|
||||
- [`BigInt` now supports assignment operators][41] like `AddAssign`.
|
||||
- The release also includes other miscellaneous improvements to performance.
|
||||
|
||||
**Contributors**: @cuviper
|
||||
:warning: indicates a **breaking change**.
|
||||
|
||||
**Contributors**: @clarcharr, @cuviper, @dodomorandi, @tspiteri
|
||||
|
||||
[8]: https://github.com/rust-num/num-bigint/pull/8
|
||||
[22]: https://github.com/rust-num/num-bigint/pull/22
|
||||
[23]: https://github.com/rust-num/num-bigint/pull/23
|
||||
[24]: https://github.com/rust-num/num-bigint/pull/24
|
||||
[26]: https://github.com/rust-num/num-bigint/pull/26
|
||||
[37]: https://github.com/rust-num/num-bigint/pull/37
|
||||
[38]: https://github.com/rust-num/num-bigint/pull/38
|
||||
[41]: https://github.com/rust-num/num-bigint/pull/41
|
||||
|
||||
# Release 0.1.44
|
||||
|
||||
- [Division with single-digit divisors is now much faster.][42]
|
||||
- The README now compares [`ramp`, `rug`, `rust-gmp`][20], and [`apint`][21].
|
||||
|
||||
**Contributors**: @cuviper, @Robbepop
|
||||
|
||||
[20]: https://github.com/rust-num/num-bigint/pull/20
|
||||
[21]: https://github.com/rust-num/num-bigint/pull/21
|
||||
[42]: https://github.com/rust-num/num-bigint/pull/42
|
||||
|
||||
# Release 0.1.43
|
||||
|
||||
|
35
benches/factorial.rs
Executable file
35
benches/factorial.rs
Executable file
@ -0,0 +1,35 @@
|
||||
#![feature(test)]
|
||||
|
||||
extern crate num_bigint;
|
||||
extern crate num_traits;
|
||||
extern crate test;
|
||||
|
||||
use num_bigint::BigUint;
|
||||
use num_traits::One;
|
||||
use std::ops::{Div, Mul};
|
||||
use test::Bencher;
|
||||
|
||||
#[bench]
|
||||
fn factorial_mul_biguint(b: &mut Bencher) {
|
||||
b.iter(|| (1u32..1000).map(BigUint::from).fold(BigUint::one(), Mul::mul));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn factorial_mul_u32(b: &mut Bencher) {
|
||||
b.iter(|| (1u32..1000).fold(BigUint::one(), Mul::mul));
|
||||
}
|
||||
|
||||
// The division test is inspired by this blog comparison:
|
||||
// <https://tiehuis.github.io/big-integers-in-zig#division-test-single-limb>
|
||||
|
||||
#[bench]
|
||||
fn factorial_div_biguint(b: &mut Bencher) {
|
||||
let n: BigUint = (1u32..1000).fold(BigUint::one(), Mul::mul);
|
||||
b.iter(|| (1u32..1000).rev().map(BigUint::from).fold(n.clone(), Div::div));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn factorial_div_u32(b: &mut Bencher) {
|
||||
let n: BigUint = (1u32..1000).fold(BigUint::one(), Mul::mul);
|
||||
b.iter(|| (1u32..1000).rev().fold(n.clone(), Div::div));
|
||||
}
|
@ -424,9 +424,13 @@ pub fn div_rem(u: &BigUint, d: &BigUint) -> (BigUint, BigUint) {
|
||||
if u.is_zero() {
|
||||
return (Zero::zero(), Zero::zero());
|
||||
}
|
||||
if *d == One::one() {
|
||||
if d.data == [1] {
|
||||
return (u.clone(), Zero::zero());
|
||||
}
|
||||
if d.data.len() == 1 {
|
||||
let (div, rem) = div_rem_digit(u.clone(), d.data[0]);
|
||||
return (div, rem.into());
|
||||
}
|
||||
|
||||
// Required or the q_len calculation below can underflow:
|
||||
match u.cmp(d) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user