diff --git a/.travis.yml b/.travis.yml index 78d97d46..b77d9c8e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 @@ -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: diff --git a/Cargo.toml b/Cargo.toml index bf0b3b59..d55fb71f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 @@ -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] diff --git a/README.md b/README.md index 22633d63..731a12ae 100644 --- a/README.md +++ b/README.md @@ -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`. @@ -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: @@ -29,22 +29,18 @@ 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 @@ -52,7 +48,7 @@ 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 @@ -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] | diff --git a/benches/bigint.rs b/benches/bigint.rs index 90a7e856..54741851 100644 --- a/benches/bigint.rs +++ b/benches/bigint.rs @@ -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; diff --git a/benches/gcd.rs b/benches/gcd.rs index 5fe5260d..a2b177a0 100644 --- a/benches/gcd.rs +++ b/benches/gcd.rs @@ -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 { diff --git a/benches/roots.rs b/benches/roots.rs index 51e67d9f..b5c0aad6 100644 --- a/benches/roots.rs +++ b/benches/roots.rs @@ -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 diff --git a/build.rs b/build.rs index 1f55eb95..72e90b7f 100644 --- a/build.rs +++ b/build.rs @@ -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"); diff --git a/ci/big_quickcheck/Cargo.toml b/ci/big_quickcheck/Cargo.toml new file mode 100644 index 00000000..a39c266d --- /dev/null +++ b/ci/big_quickcheck/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "big_quickcheck" +version = "0.1.0" +authors = ["Josh Stone "] + +[dependencies] +num-integer = "0.1.42" +num-traits = "0.2.11" +quickcheck = "0.9" +quickcheck_macros = "0.9" + +[dependencies.num-bigint] +features = ["quickcheck"] +path = "../.." diff --git a/tests/quickcheck.rs b/ci/big_quickcheck/src/lib.rs similarity index 97% rename from tests/quickcheck.rs rename to ci/big_quickcheck/src/lib.rs index a9e7b04b..8eacd1a5 100644 --- a/tests/quickcheck.rs +++ b/ci/big_quickcheck/src/lib.rs @@ -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; diff --git a/ci/big_rand/Cargo.toml b/ci/big_rand/Cargo.toml new file mode 100644 index 00000000..99b57c9b --- /dev/null +++ b/ci/big_rand/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "big_rand" +version = "0.1.0" +authors = ["Josh Stone "] + +[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" diff --git a/tests/rand.rs b/ci/big_rand/src/lib.rs similarity index 81% rename from tests/rand.rs rename to ci/big_rand/src/lib.rs index 666b764d..9dc6f367 100644 --- a/tests/rand.rs +++ b/ci/big_rand/src/lib.rs @@ -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}; @@ -118,7 +129,7 @@ mod biguint { "57401636903146945411652549098818446911814352529449356393690984105383482703074355\ 67088360974672291353736011718191813678720755501317478656550386324355699624671", ]; - use rand::prng::ChaChaRng; + use rand_chacha::ChaChaRng; seeded_value_stability::(EXPECTED); } @@ -137,7 +148,7 @@ mod biguint { "37805949268912387809989378008822038725134260145886913321084097194957861133272558\ 43458183365174899239251448892645546322463253898288141861183340823194379722556", ]; - use rand::prng::IsaacRng; + use rand_isaac::IsaacRng; seeded_value_stability::(EXPECTED); } @@ -156,9 +167,47 @@ mod biguint { "53041498719137109355568081064978196049094604705283682101683207799515709404788873\ 53417136457745727045473194367732849819278740266658219147356315674940229288531", ]; - use rand::prng::XorShiftRng; + use rand_xorshift::XorShiftRng; seeded_value_stability::(EXPECTED); } + + #[test] + fn test_roots_rand() { + fn check>(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 { @@ -280,7 +329,7 @@ mod bigint { "501454570554170484799723603981439288209930393334472085317977614690773821680884844\ 8530978478667288338327570972869032358120588620346111979053742269317702532328", ]; - use rand::prng::ChaChaRng; + use rand_chacha::ChaChaRng; seeded_value_stability::(EXPECTED); } @@ -299,7 +348,7 @@ mod bigint { "-14563174552421101848999036239003801073335703811160945137332228646111920972691151\ 88341090358094331641182310792892459091016794928947242043358702692294695845817", ]; - use rand::prng::IsaacRng; + use rand_isaac::IsaacRng; seeded_value_stability::(EXPECTED); } @@ -318,7 +367,25 @@ mod bigint { "49920038676141573457451407325930326489996232208489690499754573826911037849083623\ 24546142615325187412887314466195222441945661833644117700809693098722026764846", ]; - use rand::prng::XorShiftRng; + use rand_xorshift::XorShiftRng; seeded_value_stability::(EXPECTED); } + + #[test] + fn test_random_shr() { + use rand::distributions::Standard; + use rand::Rng; + let rng = rand::thread_rng(); + + for p in rng.sample_iter::(&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); + } + } + } } diff --git a/tests/torture.rs b/ci/big_rand/src/torture.rs similarity index 94% rename from tests/torture.rs rename to ci/big_rand/src/torture.rs index 3c72db8a..746128de 100644 --- a/tests/torture.rs +++ b/ci/big_rand/src/torture.rs @@ -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]; diff --git a/ci/rustup.sh b/ci/rustup.sh index 5134459f..3c3e18a6 100755 --- a/ci/rustup.sh +++ b/ci/rustup.sh @@ -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 diff --git a/ci/test_full.sh b/ci/test_full.sh index c257bd89..43e989bf 100755 --- a/ci/test_full.sh +++ b/ci/test_full.sh @@ -5,15 +5,14 @@ set -ex echo Testing num-bigint on rustc ${TRAVIS_RUST_VERSION} case "$TRAVIS_RUST_VERSION" in - 1.1[5-9].* | 1.2[0-1].*) STD_FEATURES="serde" ;; - 1.2[2-5].*) STD_FEATURES="serde rand" ;; - 1.2[6-9].* | 1.30.*) STD_FEATURES="serde rand i128" ;; - *) STD_FEATURES="serde rand i128 quickcheck quickcheck_macros" ;; + 1.31.*) STD_FEATURES="serde" ;; + 1.3[23].*) STD_FEATURES="serde rand" ;; + *) STD_FEATURES="serde rand quickcheck" ;; esac case "$TRAVIS_RUST_VERSION" in - 1.1[5-9].* | 1.2[0-9].* | 1.3[0-5].*) ;; - *) NO_STD_FEATURES="i128 serde" ;; + 1.3[1-5].*) ;; + *) NO_STD_FEATURES="serde rand" ;; esac # num-bigint should build and test everywhere. @@ -50,11 +49,13 @@ if test -n "${NO_STD_FEATURES:+true}"; then cargo test --no-default-features --features="$NO_STD_FEATURES" fi -# make sure benchmarks can be built +# make sure benchmarks can be built and sanity-tested if [[ "$TRAVIS_RUST_VERSION" == "nightly" ]]; then - cargo bench --all-features --no-run + cargo test --benches --all-features fi case "$STD_FEATURES" in - *serde*) cargo test --manifest-path ci/big_serde/Cargo.toml + *serde*) cargo test --manifest-path ci/big_serde/Cargo.toml ;;& + *rand*) cargo test --manifest-path ci/big_rand/Cargo.toml ;;& + *quickcheck*) cargo test --manifest-path ci/big_quickcheck/Cargo.toml ;;& esac diff --git a/src/bigint.rs b/src/bigint.rs index 0a020637..53c00da1 100644 --- a/src/bigint.rs +++ b/src/bigint.rs @@ -8,12 +8,8 @@ use core::ops::{ Mul, MulAssign, Neg, Not, Rem, RemAssign, Shl, ShlAssign, Shr, ShrAssign, Sub, SubAssign, }; use core::str::{self, FromStr}; -#[cfg(has_i128)] use core::{i128, u128}; use core::{i64, u64}; -#[cfg(feature = "std")] -#[allow(deprecated, unused_imports)] -use std::ascii::AsciiExt; #[cfg(feature = "quickcheck")] use std_alloc::Box; use std_alloc::{String, Vec}; @@ -912,7 +908,6 @@ pow_impl!(u16); pow_impl!(u32); pow_impl!(u64); pow_impl!(usize); -#[cfg(has_i128)] pow_impl!(u128); pow_impl!(BigUint); @@ -937,7 +932,6 @@ fn i64_abs_as_u64(a: i64) -> u64 { } // A convenience method for getting the absolute value of an i128 in a u128. -#[cfg(has_i128)] #[inline] fn i128_abs_as_u128(a: i128) -> u128 { if a == i128::min_value() { @@ -1023,7 +1017,6 @@ promote_all_scalars!(impl Add for BigInt, add); promote_all_scalars_assign!(impl AddAssign for BigInt, add_assign); forward_all_scalar_binop_to_val_val_commutative!(impl Add for BigInt, add); forward_all_scalar_binop_to_val_val_commutative!(impl Add for BigInt, add); -#[cfg(has_i128)] forward_all_scalar_binop_to_val_val_commutative!(impl Add for BigInt, add); impl Add for BigInt { @@ -1076,7 +1069,6 @@ impl AddAssign for BigInt { } } -#[cfg(has_i128)] impl Add for BigInt { type Output = BigInt; @@ -1093,7 +1085,6 @@ impl Add for BigInt { } } } -#[cfg(has_i128)] impl AddAssign for BigInt { #[inline] fn add_assign(&mut self, other: u128) { @@ -1104,7 +1095,6 @@ impl AddAssign for BigInt { forward_all_scalar_binop_to_val_val_commutative!(impl Add for BigInt, add); forward_all_scalar_binop_to_val_val_commutative!(impl Add for BigInt, add); -#[cfg(has_i128)] forward_all_scalar_binop_to_val_val_commutative!(impl Add for BigInt, add); impl Add for BigInt { @@ -1153,7 +1143,6 @@ impl AddAssign for BigInt { } } -#[cfg(has_i128)] impl Add for BigInt { type Output = BigInt; @@ -1166,7 +1155,6 @@ impl Add for BigInt { } } } -#[cfg(has_i128)] impl AddAssign for BigInt { #[inline] fn add_assign(&mut self, other: i128) { @@ -1254,7 +1242,6 @@ promote_all_scalars!(impl Sub for BigInt, sub); promote_all_scalars_assign!(impl SubAssign for BigInt, sub_assign); forward_all_scalar_binop_to_val_val!(impl Sub for BigInt, sub); forward_all_scalar_binop_to_val_val!(impl Sub for BigInt, sub); -#[cfg(has_i128)] forward_all_scalar_binop_to_val_val!(impl Sub for BigInt, sub); impl Sub for BigInt { @@ -1298,7 +1285,7 @@ impl Sub for u64 { -(other - self) } } -#[cfg(has_i128)] + impl Sub for u128 { type Output = BigInt; @@ -1324,6 +1311,7 @@ impl Sub for BigInt { } } } + impl SubAssign for BigInt { #[inline] fn sub_assign(&mut self, other: u64) { @@ -1332,7 +1320,6 @@ impl SubAssign for BigInt { } } -#[cfg(has_i128)] impl Sub for BigInt { type Output = BigInt; @@ -1349,7 +1336,7 @@ impl Sub for BigInt { } } } -#[cfg(has_i128)] + impl SubAssign for BigInt { #[inline] fn sub_assign(&mut self, other: u128) { @@ -1360,7 +1347,6 @@ impl SubAssign for BigInt { forward_all_scalar_binop_to_val_val!(impl Sub for BigInt, sub); forward_all_scalar_binop_to_val_val!(impl Sub for BigInt, sub); -#[cfg(has_i128)] forward_all_scalar_binop_to_val_val!(impl Sub for BigInt, sub); impl Sub for BigInt { @@ -1435,7 +1421,6 @@ impl Sub for i64 { } } -#[cfg(has_i128)] impl Sub for BigInt { type Output = BigInt; @@ -1448,7 +1433,7 @@ impl Sub for BigInt { } } } -#[cfg(has_i128)] + impl SubAssign for BigInt { #[inline] fn sub_assign(&mut self, other: i128) { @@ -1459,7 +1444,7 @@ impl SubAssign for BigInt { } } } -#[cfg(has_i128)] + impl Sub for i128 { type Output = BigInt; @@ -1496,7 +1481,6 @@ promote_all_scalars!(impl Mul for BigInt, mul); promote_all_scalars_assign!(impl MulAssign for BigInt, mul_assign); forward_all_scalar_binop_to_val_val_commutative!(impl Mul for BigInt, mul); forward_all_scalar_binop_to_val_val_commutative!(impl Mul for BigInt, mul); -#[cfg(has_i128)] forward_all_scalar_binop_to_val_val_commutative!(impl Mul for BigInt, mul); impl Mul for BigInt { @@ -1536,7 +1520,7 @@ impl MulAssign for BigInt { } } } -#[cfg(has_i128)] + impl Mul for BigInt { type Output = BigInt; @@ -1545,7 +1529,7 @@ impl Mul for BigInt { BigInt::from_biguint(self.sign, self.data * other) } } -#[cfg(has_i128)] + impl MulAssign for BigInt { #[inline] fn mul_assign(&mut self, other: u128) { @@ -1558,7 +1542,6 @@ impl MulAssign for BigInt { forward_all_scalar_binop_to_val_val_commutative!(impl Mul for BigInt, mul); forward_all_scalar_binop_to_val_val_commutative!(impl Mul for BigInt, mul); -#[cfg(has_i128)] forward_all_scalar_binop_to_val_val_commutative!(impl Mul for BigInt, mul); impl Mul for BigInt { @@ -1610,7 +1593,7 @@ impl MulAssign for BigInt { } } } -#[cfg(has_i128)] + impl Mul for BigInt { type Output = BigInt; @@ -1623,7 +1606,7 @@ impl Mul for BigInt { } } } -#[cfg(has_i128)] + impl MulAssign for BigInt { #[inline] fn mul_assign(&mut self, other: i128) { @@ -1660,7 +1643,6 @@ promote_all_scalars!(impl Div for BigInt, div); promote_all_scalars_assign!(impl DivAssign for BigInt, div_assign); forward_all_scalar_binop_to_val_val!(impl Div for BigInt, div); forward_all_scalar_binop_to_val_val!(impl Div for BigInt, div); -#[cfg(has_i128)] forward_all_scalar_binop_to_val_val!(impl Div for BigInt, div); impl Div for BigInt { @@ -1719,7 +1701,6 @@ impl Div for u64 { } } -#[cfg(has_i128)] impl Div for BigInt { type Output = BigInt; @@ -1729,7 +1710,6 @@ impl Div for BigInt { } } -#[cfg(has_i128)] impl DivAssign for BigInt { #[inline] fn div_assign(&mut self, other: u128) { @@ -1740,7 +1720,6 @@ impl DivAssign for BigInt { } } -#[cfg(has_i128)] impl Div for u128 { type Output = BigInt; @@ -1752,7 +1731,6 @@ impl Div for u128 { forward_all_scalar_binop_to_val_val!(impl Div for BigInt, div); forward_all_scalar_binop_to_val_val!(impl Div for BigInt, div); -#[cfg(has_i128)] forward_all_scalar_binop_to_val_val!(impl Div for BigInt, div); impl Div for BigInt { @@ -1831,7 +1809,6 @@ impl Div for i64 { } } -#[cfg(has_i128)] impl Div for BigInt { type Output = BigInt; @@ -1845,7 +1822,6 @@ impl Div for BigInt { } } -#[cfg(has_i128)] impl DivAssign for BigInt { #[inline] fn div_assign(&mut self, other: i128) { @@ -1858,7 +1834,6 @@ impl DivAssign for BigInt { } } -#[cfg(has_i128)] impl Div for i128 { type Output = BigInt; @@ -1902,7 +1877,6 @@ promote_all_scalars!(impl Rem for BigInt, rem); promote_all_scalars_assign!(impl RemAssign for BigInt, rem_assign); forward_all_scalar_binop_to_val_val!(impl Rem for BigInt, rem); forward_all_scalar_binop_to_val_val!(impl Rem for BigInt, rem); -#[cfg(has_i128)] forward_all_scalar_binop_to_val_val!(impl Rem for BigInt, rem); impl Rem for BigInt { @@ -1961,7 +1935,6 @@ impl Rem for u64 { } } -#[cfg(has_i128)] impl Rem for BigInt { type Output = BigInt; @@ -1971,7 +1944,6 @@ impl Rem for BigInt { } } -#[cfg(has_i128)] impl RemAssign for BigInt { #[inline] fn rem_assign(&mut self, other: u128) { @@ -1982,7 +1954,6 @@ impl RemAssign for BigInt { } } -#[cfg(has_i128)] impl Rem for u128 { type Output = BigInt; @@ -1994,7 +1965,6 @@ impl Rem for u128 { forward_all_scalar_binop_to_val_val!(impl Rem for BigInt, rem); forward_all_scalar_binop_to_val_val!(impl Rem for BigInt, rem); -#[cfg(has_i128)] forward_all_scalar_binop_to_val_val!(impl Rem for BigInt, rem); impl Rem for BigInt { @@ -2071,7 +2041,6 @@ impl Rem for i64 { } } -#[cfg(has_i128)] impl Rem for BigInt { type Output = BigInt; @@ -2084,7 +2053,7 @@ impl Rem for BigInt { } } } -#[cfg(has_i128)] + impl RemAssign for BigInt { #[inline] fn rem_assign(&mut self, other: i128) { @@ -2095,7 +2064,7 @@ impl RemAssign for BigInt { } } } -#[cfg(has_i128)] + impl Rem for i128 { type Output = BigInt; @@ -2293,7 +2262,6 @@ impl ToPrimitive for BigInt { } #[inline] - #[cfg(has_i128)] fn to_i128(&self) -> Option { match self.sign { Plus => self.data.to_i128(), @@ -2321,7 +2289,6 @@ impl ToPrimitive for BigInt { } #[inline] - #[cfg(has_i128)] fn to_u128(&self) -> Option { match self.sign { Plus => self.data.to_u128(), @@ -2352,7 +2319,6 @@ impl FromPrimitive for BigInt { } #[inline] - #[cfg(has_i128)] fn from_i128(n: i128) -> Option { Some(BigInt::from(n)) } @@ -2363,7 +2329,6 @@ impl FromPrimitive for BigInt { } #[inline] - #[cfg(has_i128)] fn from_u128(n: u128) -> Option { Some(BigInt::from(n)) } @@ -2393,7 +2358,6 @@ impl From for BigInt { } } -#[cfg(has_i128)] impl From for BigInt { #[inline] fn from(n: i128) -> Self { @@ -2439,7 +2403,6 @@ impl From for BigInt { } } -#[cfg(has_i128)] impl From for BigInt { #[inline] fn from(n: u128) -> Self { @@ -2589,7 +2552,6 @@ impl_to_bigint!(i8, FromPrimitive::from_i8); impl_to_bigint!(i16, FromPrimitive::from_i16); impl_to_bigint!(i32, FromPrimitive::from_i32); impl_to_bigint!(i64, FromPrimitive::from_i64); -#[cfg(has_i128)] impl_to_bigint!(i128, FromPrimitive::from_i128); impl_to_bigint!(usize, FromPrimitive::from_usize); @@ -2597,7 +2559,6 @@ impl_to_bigint!(u8, FromPrimitive::from_u8); impl_to_bigint!(u16, FromPrimitive::from_u16); impl_to_bigint!(u32, FromPrimitive::from_u32); impl_to_bigint!(u64, FromPrimitive::from_u64); -#[cfg(has_i128)] impl_to_bigint!(u128, FromPrimitive::from_u128); impl_to_bigint!(f32, FromPrimitive::from_f32); diff --git a/src/bigrand.rs b/src/bigrand.rs index 6bc01787..194af967 100644 --- a/src/bigrand.rs +++ b/src/bigrand.rs @@ -1,6 +1,6 @@ //! Randomization of big integers -use rand::distributions::uniform::{SampleUniform, UniformSampler}; +use rand::distributions::uniform::{SampleBorrow, SampleUniform, UniformSampler}; use rand::prelude::*; use BigInt; @@ -147,16 +147,28 @@ impl UniformSampler for UniformBigUint { type X = BigUint; #[inline] - fn new(low: Self::X, high: Self::X) -> Self { + fn new(low_b: B1, high_b: B2) -> Self + where + B1: SampleBorrow + Sized, + B2: SampleBorrow + Sized, + { + let low = low_b.borrow(); + let high = high_b.borrow(); assert!(low < high); UniformBigUint { - len: high - &low, - base: low, + len: high - low, + base: low.clone(), } } #[inline] - fn new_inclusive(low: Self::X, high: Self::X) -> Self { + fn new_inclusive(low_b: B1, high_b: B2) -> Self + where + B1: SampleBorrow + Sized, + B2: SampleBorrow + Sized, + { + let low = low_b.borrow(); + let high = high_b.borrow(); assert!(low <= high); Self::new(low, high + 1u32) } @@ -167,8 +179,12 @@ impl UniformSampler for UniformBigUint { } #[inline] - fn sample_single(low: Self::X, high: Self::X, rng: &mut R) -> Self::X { - rng.gen_biguint_range(&low, &high) + fn sample_single(low: B1, high: B2, rng: &mut R) -> Self::X + where + B1: SampleBorrow + Sized, + B2: SampleBorrow + Sized, + { + rng.gen_biguint_range(low.borrow(), high.borrow()) } } @@ -187,16 +203,28 @@ impl UniformSampler for UniformBigInt { type X = BigInt; #[inline] - fn new(low: Self::X, high: Self::X) -> Self { + fn new(low_b: B1, high_b: B2) -> Self + where + B1: SampleBorrow + Sized, + B2: SampleBorrow + Sized, + { + let low = low_b.borrow(); + let high = high_b.borrow(); assert!(low < high); UniformBigInt { - len: into_magnitude(high - &low), - base: low, + len: into_magnitude(high - low), + base: low.clone(), } } #[inline] - fn new_inclusive(low: Self::X, high: Self::X) -> Self { + fn new_inclusive(low_b: B1, high_b: B2) -> Self + where + B1: SampleBorrow + Sized, + B2: SampleBorrow + Sized, + { + let low = low_b.borrow(); + let high = high_b.borrow(); assert!(low <= high); Self::new(low, high + 1u32) } @@ -207,8 +235,12 @@ impl UniformSampler for UniformBigInt { } #[inline] - fn sample_single(low: Self::X, high: Self::X, rng: &mut R) -> Self::X { - rng.gen_bigint_range(&low, &high) + fn sample_single(low: B1, high: B2, rng: &mut R) -> Self::X + where + B1: SampleBorrow + Sized, + B2: SampleBorrow + Sized, + { + rng.gen_bigint_range(low.borrow(), high.borrow()) } } diff --git a/src/biguint.rs b/src/biguint.rs index f6853fd0..ede74b06 100644 --- a/src/biguint.rs +++ b/src/biguint.rs @@ -11,9 +11,6 @@ use core::ops::{ use core::str::{self, FromStr}; use core::{f32, f64}; use core::{u32, u64, u8}; -#[cfg(feature = "std")] -#[allow(deprecated, unused_imports)] -use std::ascii::AsciiExt; #[cfg(feature = "quickcheck")] use std_alloc::Box; use std_alloc::{Cow, String, Vec}; @@ -573,7 +570,6 @@ pow_impl!(u16); pow_impl!(u32); pow_impl!(u64); pow_impl!(usize); -#[cfg(has_i128)] pow_impl!(u128); forward_all_binop_to_val_ref_commutative!(impl Add for BigUint, add); @@ -608,7 +604,6 @@ promote_unsigned_scalars!(impl Add for BigUint, add); promote_unsigned_scalars_assign!(impl AddAssign for BigUint, add_assign); forward_all_scalar_binop_to_val_val_commutative!(impl Add for BigUint, add); forward_all_scalar_binop_to_val_val_commutative!(impl Add for BigUint, add); -#[cfg(has_i128)] forward_all_scalar_binop_to_val_val_commutative!(impl Add for BigUint, add); impl Add for BigUint { @@ -682,7 +677,6 @@ impl AddAssign for BigUint { } } -#[cfg(has_i128)] impl Add for BigUint { type Output = BigUint; @@ -693,7 +687,6 @@ impl Add for BigUint { } } -#[cfg(has_i128)] impl AddAssign for BigUint { #[cfg(not(u64_digit))] #[inline] @@ -781,7 +774,6 @@ promote_unsigned_scalars!(impl Sub for BigUint, sub); promote_unsigned_scalars_assign!(impl SubAssign for BigUint, sub_assign); forward_all_scalar_binop_to_val_val!(impl Sub for BigUint, sub); forward_all_scalar_binop_to_val_val!(impl Sub for BigUint, sub); -#[cfg(has_i128)] forward_all_scalar_binop_to_val_val!(impl Sub for BigUint, sub); impl Sub for BigUint { @@ -793,6 +785,7 @@ impl Sub for BigUint { self } } + impl SubAssign for BigUint { fn sub_assign(&mut self, other: u32) { sub2(&mut self.data[..], &[other as BigDigit]); @@ -880,7 +873,6 @@ impl Sub for u64 { } } -#[cfg(has_i128)] impl Sub for BigUint { type Output = BigUint; @@ -890,7 +882,7 @@ impl Sub for BigUint { self } } -#[cfg(has_i128)] + impl SubAssign for BigUint { #[cfg(not(u64_digit))] #[inline] @@ -909,7 +901,6 @@ impl SubAssign for BigUint { } } -#[cfg(has_i128)] impl Sub for u128 { type Output = BigUint; @@ -960,7 +951,6 @@ promote_unsigned_scalars!(impl Mul for BigUint, mul); promote_unsigned_scalars_assign!(impl MulAssign for BigUint, mul_assign); forward_all_scalar_binop_to_val_val_commutative!(impl Mul for BigUint, mul); forward_all_scalar_binop_to_val_val_commutative!(impl Mul for BigUint, mul); -#[cfg(has_i128)] forward_all_scalar_binop_to_val_val_commutative!(impl Mul for BigUint, mul); impl Mul for BigUint { @@ -1023,7 +1013,6 @@ impl MulAssign for BigUint { } } -#[cfg(has_i128)] impl Mul for BigUint { type Output = BigUint; @@ -1033,7 +1022,7 @@ impl Mul for BigUint { self } } -#[cfg(has_i128)] + impl MulAssign for BigUint { #[cfg(not(u64_digit))] #[inline] @@ -1096,7 +1085,6 @@ promote_unsigned_scalars!(impl Div for BigUint, div); promote_unsigned_scalars_assign!(impl DivAssign for BigUint, div_assign); forward_all_scalar_binop_to_val_val!(impl Div for BigUint, div); forward_all_scalar_binop_to_val_val!(impl Div for BigUint, div); -#[cfg(has_i128)] forward_all_scalar_binop_to_val_val!(impl Div for BigUint, div); impl Div for BigUint { @@ -1171,7 +1159,6 @@ impl Div for u64 { } } -#[cfg(has_i128)] impl Div for BigUint { type Output = BigUint; @@ -1182,7 +1169,6 @@ impl Div for BigUint { } } -#[cfg(has_i128)] impl DivAssign for BigUint { #[inline] fn div_assign(&mut self, other: u128) { @@ -1190,7 +1176,6 @@ impl DivAssign for BigUint { } } -#[cfg(has_i128)] impl Div for u128 { type Output = BigUint; @@ -1265,7 +1250,6 @@ promote_unsigned_scalars!(impl Rem for BigUint, rem); promote_unsigned_scalars_assign!(impl RemAssign for BigUint, rem_assign); forward_all_scalar_binop_to_ref_val!(impl Rem for BigUint, rem); forward_all_scalar_binop_to_val_val!(impl Rem for BigUint, rem); -#[cfg(has_i128)] forward_all_scalar_binop_to_val_val!(impl Rem for BigUint, rem); impl<'a> Rem for &'a BigUint { @@ -1308,15 +1292,14 @@ macro_rules! impl_rem_assign_scalar { } } } + // we can scalar %= BigUint for any scalar, including signed types -#[cfg(has_i128)] impl_rem_assign_scalar!(u128, to_u128); impl_rem_assign_scalar!(usize, to_usize); impl_rem_assign_scalar!(u64, to_u64); impl_rem_assign_scalar!(u32, to_u32); impl_rem_assign_scalar!(u16, to_u16); impl_rem_assign_scalar!(u8, to_u8); -#[cfg(has_i128)] impl_rem_assign_scalar!(i128, to_i128); impl_rem_assign_scalar!(isize, to_isize); impl_rem_assign_scalar!(i64, to_i64); @@ -1350,7 +1333,6 @@ impl Rem for u64 { } } -#[cfg(has_i128)] impl Rem for BigUint { type Output = BigUint; @@ -1360,7 +1342,7 @@ impl Rem for BigUint { r } } -#[cfg(has_i128)] + impl RemAssign for BigUint { #[inline] fn rem_assign(&mut self, other: u128) { @@ -1368,7 +1350,6 @@ impl RemAssign for BigUint { } } -#[cfg(has_i128)] impl Rem for u128 { type Output = BigUint; @@ -1736,7 +1717,6 @@ impl ToPrimitive for BigUint { } #[inline] - #[cfg(has_i128)] fn to_i128(&self) -> Option { self.to_u128().as_ref().and_then(u128::to_i128) } @@ -1759,7 +1739,6 @@ impl ToPrimitive for BigUint { } #[inline] - #[cfg(has_i128)] fn to_u128(&self) -> Option { let mut ret: u128 = 0; let mut bits = 0; @@ -1822,7 +1801,6 @@ impl FromPrimitive for BigUint { } #[inline] - #[cfg(has_i128)] fn from_i128(n: i128) -> Option { if n >= 0 { Some(BigUint::from(n as u128)) @@ -1837,7 +1815,6 @@ impl FromPrimitive for BigUint { } #[inline] - #[cfg(has_i128)] fn from_u128(n: u128) -> Option { Some(BigUint::from(n)) } @@ -1888,7 +1865,6 @@ impl From for BigUint { } } -#[cfg(has_i128)] impl From for BigUint { #[inline] fn from(mut n: u128) -> Self { @@ -1948,7 +1924,6 @@ impl_to_biguint!(i8, FromPrimitive::from_i8); impl_to_biguint!(i16, FromPrimitive::from_i16); impl_to_biguint!(i32, FromPrimitive::from_i32); impl_to_biguint!(i64, FromPrimitive::from_i64); -#[cfg(has_i128)] impl_to_biguint!(i128, FromPrimitive::from_i128); impl_to_biguint!(usize, FromPrimitive::from_usize); @@ -1956,7 +1931,6 @@ impl_to_biguint!(u8, FromPrimitive::from_u8); impl_to_biguint!(u16, FromPrimitive::from_u16); impl_to_biguint!(u32, FromPrimitive::from_u32); impl_to_biguint!(u64, FromPrimitive::from_u64); -#[cfg(has_i128)] impl_to_biguint!(u128, FromPrimitive::from_u128); impl_to_biguint!(f32, FromPrimitive::from_f32); @@ -2657,7 +2631,6 @@ impl IntDigits for BigUint { } /// Combine four `u32`s into a single `u128`. -#[cfg(has_i128)] #[cfg(any(test, not(u64_digit)))] #[inline] fn u32_to_u128(a: u32, b: u32, c: u32, d: u32) -> u128 { @@ -2665,7 +2638,6 @@ fn u32_to_u128(a: u32, b: u32, c: u32, d: u32) -> u128 { } /// Split a single `u128` into four `u32`. -#[cfg(has_i128)] #[cfg(any(test, not(u64_digit)))] #[inline] fn u32_from_u128(n: u128) -> (u32, u32, u32, u32) { @@ -2844,7 +2816,6 @@ fn test_from_slice() { check(&[-1i32 as u32], &[(-1i32 as u32) as BigDigit]); } -#[cfg(has_i128)] #[test] fn test_u32_u128() { assert_eq!(u32_from_u128(0u128), (0, 0, 0, 0)); @@ -2876,7 +2847,6 @@ fn test_u32_u128() { assert_eq!(u32_from_u128(36_893_488_151_714_070_528), (0, 2, 1, 0)); } -#[cfg(has_i128)] #[test] fn test_u128_u32_roundtrip() { // roundtrips diff --git a/src/lib.rs b/src/lib.rs index f23ff8dc..6dcc02a6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -46,14 +46,11 @@ //! //! It's easy to generate large random numbers: //! -//! ```rust -//! # #[cfg(feature = "rand")] +//! ```rust,ignore //! extern crate rand; -//! extern crate num_bigint as bigint; +//! extern crate num_bigint; //! -//! # #[cfg(feature = "rand")] -//! # fn main() { -//! use bigint::{ToBigInt, RandBigInt}; +//! use num_bigint::{ToBigInt, RandBigInt}; //! //! let mut rng = rand::thread_rng(); //! let a = rng.gen_bigint(1000); @@ -64,50 +61,36 @@ //! //! // Probably an even larger number. //! println!("{}", a * b); -//! # } -//! -//! # #[cfg(not(feature = "rand"))] -//! # fn main() { -//! # } //! ``` //! //! See the "Features" section for instructions for enabling random number generation. //! //! ## Features //! -//! The `std` crate feature is mandatory and enabled by default. If you depend on -//! `num-bigint` with `default-features = false`, you must manually enable the -//! `std` feature yourself. In the future, we hope to support `#![no_std]` with -//! the `alloc` crate when `std` is not enabled. -//! //! The `std` crate feature is enabled by default, and is mandatory before Rust //! 1.36 and the stabilized `alloc` crate. If you depend on `num-bigint` with //! `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`. //! //! //! ## 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. -#![doc(html_root_url = "https://docs.rs/num-bigint/0.2")] +#![doc(html_root_url = "https://docs.rs/num-bigint/0.3")] #![no_std] #[cfg(feature = "std")] diff --git a/tests/bigint.rs b/tests/bigint.rs index 76fb1588..f179dce0 100644 --- a/tests/bigint.rs +++ b/tests/bigint.rs @@ -1,8 +1,6 @@ extern crate num_bigint; extern crate num_integer; extern crate num_traits; -#[cfg(feature = "rand")] -extern crate rand; use num_bigint::BigUint; use num_bigint::Sign::{Minus, NoSign, Plus}; @@ -14,7 +12,6 @@ use std::hash::{BuildHasher, Hash, Hasher}; use std::iter::repeat; use std::ops::Neg; use std::{f32, f64}; -#[cfg(has_i128)] use std::{i128, u128}; use std::{i16, i32, i64, i8, isize}; use std::{u16, u32, u64, u8, usize}; @@ -294,7 +291,6 @@ fn test_convert_i64() { } #[test] -#[cfg(has_i128)] fn test_convert_i128() { fn check(b1: BigInt, i: i128) { let b2: BigInt = FromPrimitive::from_i128(i).unwrap(); @@ -352,7 +348,6 @@ fn test_convert_u64() { } #[test] -#[cfg(has_i128)] fn test_convert_u128() { fn check(b1: BigInt, u: u128) { let b2: BigInt = FromPrimitive::from_u128(u).unwrap(); @@ -578,7 +573,6 @@ fn test_convert_from_uint() { check!(u16, BigInt::from_slice(Plus, &[u16::MAX as u32])); check!(u32, BigInt::from_slice(Plus, &[u32::MAX])); check!(u64, BigInt::from_slice(Plus, &[u32::MAX, u32::MAX])); - #[cfg(has_i128)] check!( u128, BigInt::from_slice(Plus, &[u32::MAX, u32::MAX, u32::MAX, u32::MAX]) @@ -620,7 +614,6 @@ fn test_convert_from_int() { BigInt::from_slice(Minus, &[0, 1 << 31]), BigInt::from_slice(Plus, &[u32::MAX, i32::MAX as u32]) ); - #[cfg(has_i128)] check!( i128, BigInt::from_slice(Minus, &[0, 0, 0, 1 << 31]), @@ -1088,25 +1081,6 @@ fn test_negative_shr() { assert_eq!(BigInt::from(-3) >> 2, BigInt::from(-1)); } -#[test] -#[cfg(feature = "rand")] -fn test_random_shr() { - use rand::distributions::Standard; - use rand::Rng; - let mut rng = rand::thread_rng(); - - for p in rng.sample_iter::(&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); - } - } -} - #[test] fn test_iter_sum() { let result: BigInt = FromPrimitive::from_isize(-1234567).unwrap(); diff --git a/tests/biguint.rs b/tests/biguint.rs index e417af4f..450d243d 100644 --- a/tests/biguint.rs +++ b/tests/biguint.rs @@ -14,7 +14,6 @@ use std::i64; use std::iter::repeat; use std::str::FromStr; use std::{f32, f64}; -#[cfg(has_i128)] use std::{i128, u128}; use std::{u16, u32, u64, u8, usize}; @@ -542,7 +541,6 @@ fn test_convert_i64() { } #[test] -#[cfg(has_i128)] fn test_convert_i128() { fn check(b1: BigUint, i: i128) { let b2: BigUint = FromPrimitive::from_i128(i).unwrap(); @@ -591,7 +589,6 @@ fn test_convert_u64() { } #[test] -#[cfg(has_i128)] fn test_convert_u128() { fn check(b1: BigUint, u: u128) { let b2: BigUint = FromPrimitive::from_u128(u).unwrap(); @@ -791,7 +788,6 @@ fn test_convert_from_uint() { check!(u16, BigUint::from_slice(&[u16::MAX as u32])); check!(u32, BigUint::from_slice(&[u32::MAX])); check!(u64, BigUint::from_slice(&[u32::MAX, u32::MAX])); - #[cfg(has_i128)] check!( u128, BigUint::from_slice(&[u32::MAX, u32::MAX, u32::MAX, u32::MAX]) @@ -1515,9 +1511,6 @@ fn test_from_str_radix() { #[test] fn test_all_str_radix() { - #[allow(deprecated, unused_imports)] - use std::ascii::AsciiExt; - let n = BigUint::new((0..10).collect()); for radix in 2..37 { let s = n.to_str_radix(radix); @@ -1707,7 +1700,6 @@ fn test_pow() { check!(u16); check!(u32); check!(u64); - check!(usize); - #[cfg(has_i128)] check!(u128); + check!(usize); } diff --git a/tests/macros/mod.rs b/tests/macros/mod.rs index d848b29b..367af0aa 100644 --- a/tests/macros/mod.rs +++ b/tests/macros/mod.rs @@ -35,15 +35,6 @@ macro_rules! assert_scalar_op { }; } -#[cfg(not(has_i128))] -macro_rules! assert_unsigned_scalar_op { - ($left:ident $op:tt $right:ident == $expected:expr) => { - assert_scalar_op!((to_u8, to_u16, to_u32, to_u64, to_usize) - $left $op $right == $expected); - }; -} - -#[cfg(has_i128)] macro_rules! assert_unsigned_scalar_op { ($left:ident $op:tt $right:ident == $expected:expr) => { assert_scalar_op!((to_u8, to_u16, to_u32, to_u64, to_usize, to_u128) @@ -51,16 +42,6 @@ macro_rules! assert_unsigned_scalar_op { }; } -#[cfg(not(has_i128))] -macro_rules! assert_signed_scalar_op { - ($left:ident $op:tt $right:ident == $expected:expr) => { - assert_scalar_op!((to_u8, to_u16, to_u32, to_u64, to_usize, - to_i8, to_i16, to_i32, to_i64, to_isize) - $left $op $right == $expected); - }; -} - -#[cfg(has_i128)] macro_rules! assert_signed_scalar_op { ($left:ident $op:tt $right:ident == $expected:expr) => { assert_scalar_op!((to_u8, to_u16, to_u32, to_u64, to_usize, to_u128, diff --git a/tests/roots.rs b/tests/roots.rs index 39201fa9..bb52e827 100644 --- a/tests/roots.rs +++ b/tests/roots.rs @@ -2,9 +2,6 @@ extern crate num_bigint; extern crate num_integer; extern crate num_traits; -#[cfg(feature = "rand")] -extern crate rand; - mod biguint { use num_bigint::BigUint; use num_traits::{One, Pow, Zero}; @@ -101,25 +98,6 @@ mod biguint { assert!(x.nth_root(u32::MAX).is_one()); } - #[cfg(feature = "rand")] - #[test] - fn test_roots_rand() { - use num_bigint::RandBigInt; - use rand::distributions::Uniform; - use rand::{thread_rng, Rng}; - - 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); - } - } - #[test] fn test_roots_rand1() { // A random input that found regressions