Skip to content

Commit 355707b

Browse files
bors[bot]kpcyrdcuviper
authored
Merge #110
110: Bump dependencies r=cuviper a=kpcyrd This bumps rand and quickcheck to the latest version. We're about to ship num-bigint with this patch applied. Co-authored-by: kpcyrd <[email protected]> Co-authored-by: Josh Stone <[email protected]>
2 parents 480a4da + e7cdb53 commit 355707b

22 files changed

+219
-263
lines changed

.travis.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
language: rust
22
sudo: false
33
rust:
4-
- 1.15.0
5-
- 1.22.0 # rand
6-
- 1.26.0 # has_i128
74
- 1.31.0 # 2018!
5+
- 1.32.0 # rand
6+
- 1.34.0 # quickcheck
87
- 1.36.0 # alloc
98
- stable
109
- beta
@@ -27,7 +26,7 @@ matrix:
2726
before_script:
2827
- rustup target add $TARGET
2928
script:
30-
- cargo build --verbose --target $TARGET --no-default-features --features "i128 serde"
29+
- cargo build --verbose --target $TARGET --no-default-features --features "serde rand"
3130
- name: "rustfmt"
3231
rust: 1.31.0
3332
before_script:

Cargo.toml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,17 @@ name = "shootout-pidigits"
3737
[dependencies.num-integer]
3838
version = "0.1.42"
3939
default-features = false
40+
features = ["i128"]
4041

4142
[dependencies.num-traits]
4243
version = "0.2.11"
4344
default-features = false
45+
features = ["i128"]
4446

4547
[dependencies.rand]
4648
optional = true
47-
version = "0.5"
49+
version = "0.7"
4850
default-features = false
49-
features = ["std"]
5051

5152
[dependencies.serde]
5253
optional = true
@@ -55,17 +56,11 @@ default-features = false
5556

5657
[dependencies.quickcheck]
5758
optional = true
58-
version = "0.8"
59-
default-features = false
60-
61-
[dependencies.quickcheck_macros]
62-
optional = true
63-
version = "0.8"
59+
version = "0.9"
6460
default-features = false
6561

6662
[features]
6763
default = ["std"]
68-
i128 = ["num-integer/i128", "num-traits/i128"]
6964
std = ["num-integer/std", "num-traits/std"]
7065

7166
[build-dependencies]

README.md

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![crate](https://img.shields.io/crates/v/num-bigint.svg)](https://crates.io/crates/num-bigint)
44
[![documentation](https://docs.rs/num-bigint/badge.svg)](https://docs.rs/num-bigint)
5-
![minimum rustc 1.15](https://img.shields.io/badge/rustc-1.15+-red.svg)
5+
![minimum rustc 1.31](https://img.shields.io/badge/rustc-1.31+-red.svg)
66
[![Travis status](https://travis-ci.org/rust-num/num-bigint.svg?branch=master)](https://travis-ci.org/rust-num/num-bigint)
77

88
Big integer types for Rust, `BigInt` and `BigUint`.
@@ -13,7 +13,7 @@ Add this to your `Cargo.toml`:
1313

1414
```toml
1515
[dependencies]
16-
num-bigint = "0.2"
16+
num-bigint = "0.3"
1717
```
1818

1919
and this to your crate root:
@@ -29,30 +29,26 @@ The `std` crate feature is enabled by default, and is mandatory before Rust
2929
`default-features = false`, you must manually enable the `std` feature yourself
3030
if your compiler is not new enough.
3131

32-
Implementations for `i128` and `u128` are only available with Rust 1.26 and
33-
later. The build script automatically detects this, but you can make it
34-
mandatory by enabling the `i128` crate feature.
35-
3632
### Random Generation
3733

3834
`num-bigint` supports the generation of random big integers when the `rand`
3935
feature is enabled. To enable it include rand as
4036

4137
```toml
42-
rand = "0.5"
43-
num-bigint = { version = "0.2", features = ["rand"] }
38+
rand = "0.7"
39+
num-bigint = { version = "0.3", features = ["rand"] }
4440
```
4541

4642
Note that you must use the version of `rand` that `num-bigint` is compatible
47-
with: `0.5`.
43+
with: `0.7`.
4844

4945
## Releases
5046

5147
Release notes are available in [RELEASES.md](RELEASES.md).
5248

5349
## Compatibility
5450

55-
The `num-bigint` crate is tested for rustc 1.15 and greater.
51+
The `num-bigint` crate is tested for rustc 1.31 and greater.
5652

5753
## Alternatives
5854

@@ -62,7 +58,7 @@ table offers a brief comparison to a few alternatives.
6258

6359
| Crate | License | Min rustc | Implementation |
6460
| :--------------- | :------------- | :-------- | :------------- |
65-
| **`num-bigint`** | MIT/Apache-2.0 | 1.15 | pure rust |
61+
| **`num-bigint`** | MIT/Apache-2.0 | 1.31 | pure rust |
6662
| [`ramp`] | Apache-2.0 | nightly | rust and inline assembly |
6763
| [`rug`] | LGPL-3.0+ | 1.31 | bundles [GMP] via [`gmp-mpfr-sys`] |
6864
| [`rust-gmp`] | MIT | stable? | links to [GMP] |

benches/bigint.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ extern crate test;
99

1010
use num_bigint::{BigInt, BigUint, RandBigInt};
1111
use num_traits::{FromPrimitive, Num, One, Pow, Zero};
12-
use rand::{SeedableRng, StdRng};
12+
use rand::rngs::StdRng;
13+
use rand::SeedableRng;
1314
use std::mem::replace;
1415
use test::Bencher;
1516

benches/gcd.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ extern crate test;
1010
use num_bigint::{BigUint, RandBigInt};
1111
use num_integer::Integer;
1212
use num_traits::Zero;
13-
use rand::{SeedableRng, StdRng};
13+
use rand::rngs::StdRng;
14+
use rand::SeedableRng;
1415
use test::Bencher;
1516

1617
fn get_rng() -> StdRng {

benches/roots.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ extern crate test;
88

99
use num_bigint::{BigUint, RandBigInt};
1010
use num_traits::Pow;
11-
use rand::{SeedableRng, StdRng};
11+
use rand::rngs::StdRng;
12+
use rand::SeedableRng;
1213
use test::Bencher;
1314

1415
// The `big64` cases demonstrate the speed of cases where the value

build.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,9 @@ use std::io::Write;
77
use std::path::Path;
88

99
fn main() {
10-
let ac = autocfg::new();
11-
12-
if ac.probe_type("i128") {
13-
autocfg::emit("has_i128");
14-
15-
let pointer_width = env::var("CARGO_CFG_TARGET_POINTER_WIDTH");
16-
if pointer_width.as_ref().map(String::as_str) == Ok("64") {
17-
autocfg::emit("u64_digit");
18-
}
19-
} else if env::var_os("CARGO_FEATURE_I128").is_some() {
20-
panic!("i128 support was not detected!");
10+
let pointer_width = env::var("CARGO_CFG_TARGET_POINTER_WIDTH");
11+
if pointer_width.as_ref().map(String::as_str) == Ok("64") {
12+
autocfg::emit("u64_digit");
2113
}
2214

2315
autocfg::rerun_path("build.rs");

ci/big_quickcheck/Cargo.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[package]
2+
name = "big_quickcheck"
3+
version = "0.1.0"
4+
authors = ["Josh Stone <[email protected]>"]
5+
6+
[dependencies]
7+
num-integer = "0.1.42"
8+
num-traits = "0.2.11"
9+
quickcheck = "0.9"
10+
quickcheck_macros = "0.9"
11+
12+
[dependencies.num-bigint]
13+
features = ["quickcheck"]
14+
path = "../.."

tests/quickcheck.rs renamed to ci/big_quickcheck/src/lib.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
#![cfg(feature = "quickcheck")]
2-
#![cfg(feature = "quickcheck_macros")]
1+
//! Quickcheck of `BigUint` and `BigInt`
2+
//!
3+
//! This test is in a completely separate crate so we can use `quickcheck_macros` only when
4+
//! `quickcheck` is active. The main crate can't have optional dev-dependencies, and it's
5+
//! better not to expose it as a "feature" optional dependency.
6+
7+
#![cfg(test)]
38

49
extern crate num_bigint;
510
extern crate num_integer;

ci/big_rand/Cargo.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[package]
2+
name = "big_rand"
3+
version = "0.1.0"
4+
authors = ["Josh Stone <[email protected]>"]
5+
6+
[dependencies]
7+
num-traits = "0.2.11"
8+
rand_chacha = "0.2"
9+
rand_isaac = "0.2"
10+
rand_xorshift = "0.2"
11+
12+
[dependencies.num-bigint]
13+
features = ["rand"]
14+
path = "../.."
15+
16+
[dependencies.rand]
17+
features = ["small_rng"]
18+
version = "0.7"

tests/rand.rs renamed to ci/big_rand/src/lib.rs

Lines changed: 75 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
1-
#![cfg(feature = "rand")]
1+
//! Test randomization of `BigUint` and `BigInt`
2+
//!
3+
//! This test is in a completely separate crate so `rand::thread_rng()`
4+
//! can be available without "infecting" the rest of the build with
5+
//! `rand`'s default features, especially not `rand/std`.
6+
7+
#![cfg(test)]
28

39
extern crate num_bigint;
410
extern crate num_traits;
511
extern crate rand;
12+
extern crate rand_chacha;
13+
extern crate rand_isaac;
14+
extern crate rand_xorshift;
15+
16+
mod torture;
617

718
mod biguint {
819
use num_bigint::{BigUint, RandBigInt, RandomBits};
9-
use num_traits::Zero;
20+
use num_traits::{Pow, Zero};
1021
use rand::distributions::Uniform;
1122
use rand::thread_rng;
1223
use rand::{Rng, SeedableRng};
@@ -118,7 +129,7 @@ mod biguint {
118129
"57401636903146945411652549098818446911814352529449356393690984105383482703074355\
119130
67088360974672291353736011718191813678720755501317478656550386324355699624671",
120131
];
121-
use rand::prng::ChaChaRng;
132+
use rand_chacha::ChaChaRng;
122133
seeded_value_stability::<ChaChaRng>(EXPECTED);
123134
}
124135

@@ -137,7 +148,7 @@ mod biguint {
137148
"37805949268912387809989378008822038725134260145886913321084097194957861133272558\
138149
43458183365174899239251448892645546322463253898288141861183340823194379722556",
139150
];
140-
use rand::prng::IsaacRng;
151+
use rand_isaac::IsaacRng;
141152
seeded_value_stability::<IsaacRng>(EXPECTED);
142153
}
143154

@@ -156,9 +167,47 @@ mod biguint {
156167
"53041498719137109355568081064978196049094604705283682101683207799515709404788873\
157168
53417136457745727045473194367732849819278740266658219147356315674940229288531",
158169
];
159-
use rand::prng::XorShiftRng;
170+
use rand_xorshift::XorShiftRng;
160171
seeded_value_stability::<XorShiftRng>(EXPECTED);
161172
}
173+
174+
#[test]
175+
fn test_roots_rand() {
176+
fn check<T: Into<BigUint>>(x: T, n: u32) {
177+
let x: BigUint = x.into();
178+
let root = x.nth_root(n);
179+
println!("check {}.nth_root({}) = {}", x, n, root);
180+
181+
if n == 2 {
182+
assert_eq!(root, x.sqrt())
183+
} else if n == 3 {
184+
assert_eq!(root, x.cbrt())
185+
}
186+
187+
let lo = root.pow(n);
188+
assert!(lo <= x);
189+
assert_eq!(lo.nth_root(n), root);
190+
if !lo.is_zero() {
191+
assert_eq!((&lo - 1u32).nth_root(n), &root - 1u32);
192+
}
193+
194+
let hi = (&root + 1u32).pow(n);
195+
assert!(hi > x);
196+
assert_eq!(hi.nth_root(n), &root + 1u32);
197+
assert_eq!((&hi - 1u32).nth_root(n), root);
198+
}
199+
200+
let mut rng = thread_rng();
201+
let bit_range = Uniform::new(0, 2048);
202+
let sample_bits: Vec<_> = rng.sample_iter(&bit_range).take(100).collect();
203+
for bits in sample_bits {
204+
let x = rng.gen_biguint(bits);
205+
for n in 2..11 {
206+
check(x.clone(), n);
207+
}
208+
check(x.clone(), 100);
209+
}
210+
}
162211
}
163212

164213
mod bigint {
@@ -280,7 +329,7 @@ mod bigint {
280329
"501454570554170484799723603981439288209930393334472085317977614690773821680884844\
281330
8530978478667288338327570972869032358120588620346111979053742269317702532328",
282331
];
283-
use rand::prng::ChaChaRng;
332+
use rand_chacha::ChaChaRng;
284333
seeded_value_stability::<ChaChaRng>(EXPECTED);
285334
}
286335

@@ -299,7 +348,7 @@ mod bigint {
299348
"-14563174552421101848999036239003801073335703811160945137332228646111920972691151\
300349
88341090358094331641182310792892459091016794928947242043358702692294695845817",
301350
];
302-
use rand::prng::IsaacRng;
351+
use rand_isaac::IsaacRng;
303352
seeded_value_stability::<IsaacRng>(EXPECTED);
304353
}
305354

@@ -318,7 +367,25 @@ mod bigint {
318367
"49920038676141573457451407325930326489996232208489690499754573826911037849083623\
319368
24546142615325187412887314466195222441945661833644117700809693098722026764846",
320369
];
321-
use rand::prng::XorShiftRng;
370+
use rand_xorshift::XorShiftRng;
322371
seeded_value_stability::<XorShiftRng>(EXPECTED);
323372
}
373+
374+
#[test]
375+
fn test_random_shr() {
376+
use rand::distributions::Standard;
377+
use rand::Rng;
378+
let rng = rand::thread_rng();
379+
380+
for p in rng.sample_iter::<i64, _>(&Standard).take(1000) {
381+
let big = BigInt::from(p);
382+
let bigger = &big << 1000;
383+
assert_eq!(&bigger >> 1000, big);
384+
for i in 0..64 {
385+
let answer = BigInt::from(p >> i);
386+
assert_eq!(&big >> i, answer);
387+
assert_eq!(&bigger >> (1000 + i), answer);
388+
}
389+
}
390+
}
324391
}

tests/torture.rs renamed to ci/big_rand/src/torture.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
#![cfg(feature = "rand")]
2-
3-
extern crate num_bigint;
4-
extern crate num_traits;
5-
extern crate rand;
6-
71
use num_bigint::RandBigInt;
82
use num_traits::Zero;
93
use rand::prelude::*;
4+
use rand::rngs::SmallRng;
105

116
fn get_rng() -> SmallRng {
127
let seed = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];

ci/rustup.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
set -ex
66

77
export TRAVIS_RUST_VERSION
8-
for TRAVIS_RUST_VERSION in 1.15.0 1.22.0 1.26.0 1.31.0 1.36.0 stable beta nightly; do
8+
for TRAVIS_RUST_VERSION in 1.31.0 1.32.0 1.34.0 1.36.0 stable beta nightly; do
99
run="rustup run $TRAVIS_RUST_VERSION"
1010
$run cargo build --verbose
1111
$run $PWD/ci/test_full.sh

0 commit comments

Comments
 (0)