Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump dependencies #110

Merged
merged 9 commits into from
Jan 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
language: rust
sudo: false
rust:
- 1.15.0
- 1.22.0 # rand
- 1.26.0 # has_i128
- 1.31.0 # 2018!
- 1.32.0 # rand
- 1.34.0 # quickcheck
- 1.36.0 # alloc
- stable
- beta
Expand All @@ -27,7 +26,7 @@ matrix:
before_script:
- rustup target add $TARGET
script:
- cargo build --verbose --target $TARGET --no-default-features --features "i128 serde"
- cargo build --verbose --target $TARGET --no-default-features --features "serde rand"
- name: "rustfmt"
rust: 1.31.0
before_script:
Expand Down
13 changes: 4 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,17 @@ name = "shootout-pidigits"
[dependencies.num-integer]
version = "0.1.42"
default-features = false
features = ["i128"]

[dependencies.num-traits]
version = "0.2.11"
default-features = false
features = ["i128"]

[dependencies.rand]
optional = true
version = "0.5"
version = "0.7"
default-features = false
features = ["std"]

[dependencies.serde]
optional = true
Expand All @@ -55,17 +56,11 @@ default-features = false

[dependencies.quickcheck]
optional = true
version = "0.8"
default-features = false

[dependencies.quickcheck_macros]
optional = true
version = "0.8"
version = "0.9"
default-features = false

[features]
default = ["std"]
i128 = ["num-integer/i128", "num-traits/i128"]
std = ["num-integer/std", "num-traits/std"]

[build-dependencies]
Expand Down
18 changes: 7 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

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

```toml
[dependencies]
num-bigint = "0.2"
num-bigint = "0.3"
```

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

Implementations for `i128` and `u128` are only available with Rust 1.26 and
later. The build script automatically detects this, but you can make it
mandatory by enabling the `i128` crate feature.

### Random Generation

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

```toml
rand = "0.5"
num-bigint = { version = "0.2", features = ["rand"] }
rand = "0.7"
num-bigint = { version = "0.3", features = ["rand"] }
```

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

## Releases

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

## Compatibility

The `num-bigint` crate is tested for rustc 1.15 and greater.
The `num-bigint` crate is tested for rustc 1.31 and greater.

## Alternatives

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

| Crate | License | Min rustc | Implementation |
| :--------------- | :------------- | :-------- | :------------- |
| **`num-bigint`** | MIT/Apache-2.0 | 1.15 | pure rust |
| **`num-bigint`** | MIT/Apache-2.0 | 1.31 | pure rust |
| [`ramp`] | Apache-2.0 | nightly | rust and inline assembly |
| [`rug`] | LGPL-3.0+ | 1.31 | bundles [GMP] via [`gmp-mpfr-sys`] |
| [`rust-gmp`] | MIT | stable? | links to [GMP] |
Expand Down
3 changes: 2 additions & 1 deletion benches/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ extern crate test;

use num_bigint::{BigInt, BigUint, RandBigInt};
use num_traits::{FromPrimitive, Num, One, Pow, Zero};
use rand::{SeedableRng, StdRng};
use rand::rngs::StdRng;
use rand::SeedableRng;
use std::mem::replace;
use test::Bencher;

Expand Down
3 changes: 2 additions & 1 deletion benches/gcd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ extern crate test;
use num_bigint::{BigUint, RandBigInt};
use num_integer::Integer;
use num_traits::Zero;
use rand::{SeedableRng, StdRng};
use rand::rngs::StdRng;
use rand::SeedableRng;
use test::Bencher;

fn get_rng() -> StdRng {
Expand Down
3 changes: 2 additions & 1 deletion benches/roots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ extern crate test;

use num_bigint::{BigUint, RandBigInt};
use num_traits::Pow;
use rand::{SeedableRng, StdRng};
use rand::rngs::StdRng;
use rand::SeedableRng;
use test::Bencher;

// The `big64` cases demonstrate the speed of cases where the value
Expand Down
14 changes: 3 additions & 11 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,9 @@ use std::io::Write;
use std::path::Path;

fn main() {
let ac = autocfg::new();

if ac.probe_type("i128") {
autocfg::emit("has_i128");

let pointer_width = env::var("CARGO_CFG_TARGET_POINTER_WIDTH");
if pointer_width.as_ref().map(String::as_str) == Ok("64") {
autocfg::emit("u64_digit");
}
} else if env::var_os("CARGO_FEATURE_I128").is_some() {
panic!("i128 support was not detected!");
let pointer_width = env::var("CARGO_CFG_TARGET_POINTER_WIDTH");
if pointer_width.as_ref().map(String::as_str) == Ok("64") {
autocfg::emit("u64_digit");
}

autocfg::rerun_path("build.rs");
Expand Down
14 changes: 14 additions & 0 deletions ci/big_quickcheck/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "big_quickcheck"
version = "0.1.0"
authors = ["Josh Stone <cuviper@gmail.com>"]

[dependencies]
num-integer = "0.1.42"
num-traits = "0.2.11"
quickcheck = "0.9"
quickcheck_macros = "0.9"

[dependencies.num-bigint]
features = ["quickcheck"]
path = "../.."
9 changes: 7 additions & 2 deletions tests/quickcheck.rs → ci/big_quickcheck/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#![cfg(feature = "quickcheck")]
#![cfg(feature = "quickcheck_macros")]
//! Quickcheck of `BigUint` and `BigInt`
//!
//! This test is in a completely separate crate so we can use `quickcheck_macros` only when
//! `quickcheck` is active. The main crate can't have optional dev-dependencies, and it's
//! better not to expose it as a "feature" optional dependency.
#![cfg(test)]

extern crate num_bigint;
extern crate num_integer;
Expand Down
18 changes: 18 additions & 0 deletions ci/big_rand/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "big_rand"
version = "0.1.0"
authors = ["Josh Stone <cuviper@gmail.com>"]

[dependencies]
num-traits = "0.2.11"
rand_chacha = "0.2"
rand_isaac = "0.2"
rand_xorshift = "0.2"

[dependencies.num-bigint]
features = ["rand"]
path = "../.."

[dependencies.rand]
features = ["small_rng"]
version = "0.7"
83 changes: 75 additions & 8 deletions tests/rand.rs → ci/big_rand/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
#![cfg(feature = "rand")]
//! Test randomization of `BigUint` and `BigInt`
//!
//! This test is in a completely separate crate so `rand::thread_rng()`
//! can be available without "infecting" the rest of the build with
//! `rand`'s default features, especially not `rand/std`.
#![cfg(test)]

extern crate num_bigint;
extern crate num_traits;
extern crate rand;
extern crate rand_chacha;
extern crate rand_isaac;
extern crate rand_xorshift;

mod torture;

mod biguint {
use num_bigint::{BigUint, RandBigInt, RandomBits};
use num_traits::Zero;
use num_traits::{Pow, Zero};
use rand::distributions::Uniform;
use rand::thread_rng;
use rand::{Rng, SeedableRng};
Expand Down Expand Up @@ -118,7 +129,7 @@ mod biguint {
"57401636903146945411652549098818446911814352529449356393690984105383482703074355\
67088360974672291353736011718191813678720755501317478656550386324355699624671",
];
use rand::prng::ChaChaRng;
use rand_chacha::ChaChaRng;
seeded_value_stability::<ChaChaRng>(EXPECTED);
}

Expand All @@ -137,7 +148,7 @@ mod biguint {
"37805949268912387809989378008822038725134260145886913321084097194957861133272558\
43458183365174899239251448892645546322463253898288141861183340823194379722556",
];
use rand::prng::IsaacRng;
use rand_isaac::IsaacRng;
seeded_value_stability::<IsaacRng>(EXPECTED);
}

Expand All @@ -156,9 +167,47 @@ mod biguint {
"53041498719137109355568081064978196049094604705283682101683207799515709404788873\
53417136457745727045473194367732849819278740266658219147356315674940229288531",
];
use rand::prng::XorShiftRng;
use rand_xorshift::XorShiftRng;
seeded_value_stability::<XorShiftRng>(EXPECTED);
}

#[test]
fn test_roots_rand() {
fn check<T: Into<BigUint>>(x: T, n: u32) {
let x: BigUint = x.into();
let root = x.nth_root(n);
println!("check {}.nth_root({}) = {}", x, n, root);

if n == 2 {
assert_eq!(root, x.sqrt())
} else if n == 3 {
assert_eq!(root, x.cbrt())
}

let lo = root.pow(n);
assert!(lo <= x);
assert_eq!(lo.nth_root(n), root);
if !lo.is_zero() {
assert_eq!((&lo - 1u32).nth_root(n), &root - 1u32);
}

let hi = (&root + 1u32).pow(n);
assert!(hi > x);
assert_eq!(hi.nth_root(n), &root + 1u32);
assert_eq!((&hi - 1u32).nth_root(n), root);
}

let mut rng = thread_rng();
let bit_range = Uniform::new(0, 2048);
let sample_bits: Vec<_> = rng.sample_iter(&bit_range).take(100).collect();
for bits in sample_bits {
let x = rng.gen_biguint(bits);
for n in 2..11 {
check(x.clone(), n);
}
check(x.clone(), 100);
}
}
}

mod bigint {
Expand Down Expand Up @@ -280,7 +329,7 @@ mod bigint {
"501454570554170484799723603981439288209930393334472085317977614690773821680884844\
8530978478667288338327570972869032358120588620346111979053742269317702532328",
];
use rand::prng::ChaChaRng;
use rand_chacha::ChaChaRng;
seeded_value_stability::<ChaChaRng>(EXPECTED);
}

Expand All @@ -299,7 +348,7 @@ mod bigint {
"-14563174552421101848999036239003801073335703811160945137332228646111920972691151\
88341090358094331641182310792892459091016794928947242043358702692294695845817",
];
use rand::prng::IsaacRng;
use rand_isaac::IsaacRng;
seeded_value_stability::<IsaacRng>(EXPECTED);
}

Expand All @@ -318,7 +367,25 @@ mod bigint {
"49920038676141573457451407325930326489996232208489690499754573826911037849083623\
24546142615325187412887314466195222441945661833644117700809693098722026764846",
];
use rand::prng::XorShiftRng;
use rand_xorshift::XorShiftRng;
seeded_value_stability::<XorShiftRng>(EXPECTED);
}

#[test]
fn test_random_shr() {
use rand::distributions::Standard;
use rand::Rng;
let rng = rand::thread_rng();

for p in rng.sample_iter::<i64, _>(&Standard).take(1000) {
let big = BigInt::from(p);
let bigger = &big << 1000;
assert_eq!(&bigger >> 1000, big);
for i in 0..64 {
let answer = BigInt::from(p >> i);
assert_eq!(&big >> i, answer);
assert_eq!(&bigger >> (1000 + i), answer);
}
}
}
}
7 changes: 1 addition & 6 deletions tests/torture.rs → ci/big_rand/src/torture.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
#![cfg(feature = "rand")]

extern crate num_bigint;
extern crate num_traits;
extern crate rand;

use num_bigint::RandBigInt;
use num_traits::Zero;
use rand::prelude::*;
use rand::rngs::SmallRng;

fn get_rng() -> SmallRng {
let seed = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];
Expand Down
2 changes: 1 addition & 1 deletion ci/rustup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
set -ex

export TRAVIS_RUST_VERSION
for TRAVIS_RUST_VERSION in 1.15.0 1.22.0 1.26.0 1.31.0 1.36.0 stable beta nightly; do
for TRAVIS_RUST_VERSION in 1.31.0 1.32.0 1.34.0 1.36.0 stable beta nightly; do
run="rustup run $TRAVIS_RUST_VERSION"
$run cargo build --verbose
$run $PWD/ci/test_full.sh
Expand Down
Loading