Skip to content

Commit

Permalink
Merge #130
Browse files Browse the repository at this point in the history
130: Update to 2018 edition and clippy fixes r=cuviper a=cuviper



Co-authored-by: Josh Stone <cuviper@gmail.com>
  • Loading branch information
bors[bot] and cuviper committed Jan 15, 2020
2 parents 355707b + 25913e8 commit d182c71
Show file tree
Hide file tree
Showing 28 changed files with 411 additions and 476 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ version = "0.3.0-pre"
readme = "README.md"
build = "build.rs"
publish = false
edition = "2018"

[package.metadata.docs.rs]
features = ["std", "serde", "rand", "quickcheck"]
Expand Down
43 changes: 19 additions & 24 deletions benches/bigint.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#![feature(test)]
#![cfg(feature = "rand")]

extern crate num_bigint;
extern crate num_integer;
extern crate num_traits;
extern crate rand;
extern crate test;

use num_bigint::{BigInt, BigUint, RandBigInt};
Expand Down Expand Up @@ -48,9 +44,9 @@ fn remainder_bench(b: &mut Bencher, xbits: usize, ybits: usize) {

fn factorial(n: usize) -> BigUint {
let mut f: BigUint = One::one();
for i in 1..(n + 1) {
for i in 1..=n {
let bu: BigUint = FromPrimitive::from_usize(i).unwrap();
f = f * bu;
f += bu;
}
f
}
Expand All @@ -72,7 +68,7 @@ fn fib2(n: usize) -> BigUint {
let mut f0: BigUint = Zero::zero();
let mut f1: BigUint = One::one();
for _ in 0..n {
f1 = f1 + &f0;
f1 += &f0;
f0 = &f1 - f0;
}
f0
Expand Down Expand Up @@ -301,7 +297,7 @@ fn shl(b: &mut Bencher) {
b.iter(|| {
let mut m = n.clone();
for i in 0..50 {
m = m << i;
m <<= i;
}
})
}
Expand All @@ -312,7 +308,7 @@ fn shr(b: &mut Bencher) {
b.iter(|| {
let mut m = n.clone();
for i in 0..50 {
m = m >> i;
m >>= i;
}
})
}
Expand All @@ -332,8 +328,8 @@ fn hash(b: &mut Bencher) {
fn pow_bench(b: &mut Bencher) {
b.iter(|| {
let upper = 100_usize;
for i in 2..upper + 1 {
for j in 2..upper + 1 {
for i in 2..=upper {
for j in 2..=upper {
let i_big = BigUint::from_usize(i).unwrap();
i_big.pow(j);
}
Expand All @@ -343,19 +339,18 @@ fn pow_bench(b: &mut Bencher) {

/// This modulus is the prime from the 2048-bit MODP DH group:
/// https://tools.ietf.org/html/rfc3526#section-3
const RFC3526_2048BIT_MODP_GROUP: &'static str =
"\
FFFFFFFF_FFFFFFFF_C90FDAA2_2168C234_C4C6628B_80DC1CD1\
29024E08_8A67CC74_020BBEA6_3B139B22_514A0879_8E3404DD\
EF9519B3_CD3A431B_302B0A6D_F25F1437_4FE1356D_6D51C245\
E485B576_625E7EC6_F44C42E9_A637ED6B_0BFF5CB6_F406B7ED\
EE386BFB_5A899FA5_AE9F2411_7C4B1FE6_49286651_ECE45B3D\
C2007CB8_A163BF05_98DA4836_1C55D39A_69163FA8_FD24CF5F\
83655D23_DCA3AD96_1C62F356_208552BB_9ED52907_7096966D\
670C354E_4ABC9804_F1746C08_CA18217C_32905E46_2E36CE3B\
E39E772C_180E8603_9B2783A2_EC07A28F_B5C55DF0_6F4C52C9\
DE2BCBF6_95581718_3995497C_EA956AE5_15D22618_98FA0510\
15728E5A_8AACAA68_FFFFFFFF_FFFFFFFF";
const RFC3526_2048BIT_MODP_GROUP: &str = "\
FFFFFFFF_FFFFFFFF_C90FDAA2_2168C234_C4C6628B_80DC1CD1\
29024E08_8A67CC74_020BBEA6_3B139B22_514A0879_8E3404DD\
EF9519B3_CD3A431B_302B0A6D_F25F1437_4FE1356D_6D51C245\
E485B576_625E7EC6_F44C42E9_A637ED6B_0BFF5CB6_F406B7ED\
EE386BFB_5A899FA5_AE9F2411_7C4B1FE6_49286651_ECE45B3D\
C2007CB8_A163BF05_98DA4836_1C55D39A_69163FA8_FD24CF5F\
83655D23_DCA3AD96_1C62F356_208552BB_9ED52907_7096966D\
670C354E_4ABC9804_F1746C08_CA18217C_32905E46_2E36CE3B\
E39E772C_180E8603_9B2783A2_EC07A28F_B5C55DF0_6F4C52C9\
DE2BCBF6_95581718_3995497C_EA956AE5_15D22618_98FA0510\
15728E5A_8AACAA68_FFFFFFFF_FFFFFFFF";

#[bench]
fn modpow(b: &mut Bencher) {
Expand Down
2 changes: 0 additions & 2 deletions benches/factorial.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#![feature(test)]

extern crate num_bigint;
extern crate num_traits;
extern crate test;

use num_bigint::BigUint;
Expand Down
6 changes: 1 addition & 5 deletions benches/gcd.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#![feature(test)]
#![cfg(feature = "rand")]

extern crate num_bigint;
extern crate num_integer;
extern crate num_traits;
extern crate rand;
extern crate test;

use num_bigint::{BigUint, RandBigInt};
Expand Down Expand Up @@ -41,7 +37,7 @@ fn euclid(x: &BigUint, y: &BigUint) -> BigUint {
m = n % &temp;
n = temp;
}
return n;
n
}

#[bench]
Expand Down
3 changes: 0 additions & 3 deletions benches/roots.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#![feature(test)]
#![cfg(feature = "rand")]

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

use num_bigint::{BigUint, RandBigInt};
Expand Down
10 changes: 3 additions & 7 deletions benches/shootout-pidigits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.

extern crate num_bigint;
extern crate num_integer;
extern crate num_traits;

use std::io;
use std::str::FromStr;

Expand Down Expand Up @@ -98,7 +94,7 @@ fn pidigits(n: isize, out: &mut dyn io::Write) -> io::Result<()> {
let mut k = 0;
let mut context = Context::new();

for i in 1..(n + 1) {
for i in 1..=n {
let mut d;
loop {
k += 1;
Expand All @@ -111,7 +107,7 @@ fn pidigits(n: isize, out: &mut dyn io::Write) -> io::Result<()> {

write!(out, "{}", d)?;
if i % 10 == 0 {
write!(out, "\t:{}\n", i)?;
writeln!(out, "\t:{}", i)?;
}

context.eliminate_digit(d);
Expand All @@ -122,7 +118,7 @@ fn pidigits(n: isize, out: &mut dyn io::Write) -> io::Result<()> {
for _ in m..10 {
write!(out, " ")?;
}
write!(out, "\t:{}\n", n)?;
writeln!(out, "\t:{}", n)?;
}
Ok(())
}
Expand Down
7 changes: 2 additions & 5 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate autocfg;

use std::env;
use std::error::Error;
use std::fs::File;
Expand All @@ -26,8 +24,7 @@ fn main() {
/// BASES_64[3] = (12157665459056928801, 40)
///
/// Powers of two are not included, just zeroed, as they're implemented with shifts.
#[allow(unknown_lints, bare_trait_objects)]
fn write_radix_bases() -> Result<(), Box<Error>> {
fn write_radix_bases() -> Result<(), Box<dyn Error>> {
let out_dir = env::var("OUT_DIR")?;
let dest_path = Path::new(&out_dir).join("radix_bases.rs");
let mut f = File::create(&dest_path)?;
Expand All @@ -42,7 +39,7 @@ fn write_radix_bases() -> Result<(), Box<Error>> {
writeln!(f, "#[deny(overflowing_literals)]")?;
writeln!(
f,
"pub static BASES_{bits}: [(u{bits}, usize); 257] = [",
"pub(crate) static BASES_{bits}: [(u{bits}, usize); 257] = [",
bits = bits
)?;
for radix in 0u64..257 {
Expand Down
1 change: 1 addition & 0 deletions ci/big_quickcheck/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "big_quickcheck"
version = "0.1.0"
authors = ["Josh Stone <cuviper@gmail.com>"]
edition = "2018"

[dependencies]
num-integer = "0.1.42"
Expand Down
9 changes: 1 addition & 8 deletions ci/big_quickcheck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,11 @@

#![cfg(test)]

extern crate num_bigint;
extern crate num_integer;
extern crate num_traits;

extern crate quickcheck;
#[macro_use]
extern crate quickcheck_macros;

use num_bigint::{BigInt, BigUint};
use num_integer::Integer;
use num_traits::{Num, One, Pow, Signed, Zero};
use quickcheck::{QuickCheck, StdThreadGen, TestResult};
use quickcheck_macros::quickcheck;

#[quickcheck]
fn quickcheck_unsigned_eq_reflexive(a: BigUint) -> bool {
Expand Down
1 change: 1 addition & 0 deletions ci/big_rand/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "big_rand"
version = "0.1.0"
authors = ["Josh Stone <cuviper@gmail.com>"]
edition = "2018"

[dependencies]
num-traits = "0.2.11"
Expand Down
11 changes: 2 additions & 9 deletions ci/big_rand/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@

#![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 {
Expand Down Expand Up @@ -257,7 +250,7 @@ mod bigint {
let u: BigInt = BigInt::from(403469000 + 3513);
check(l.clone(), u.clone());
check(-l.clone(), u.clone());
check(-u.clone(), -l.clone());
check(-u, -l);
}

#[test]
Expand Down Expand Up @@ -298,7 +291,7 @@ mod bigint {
let u: BigInt = BigInt::from(403469000 + 3513);
check(l.clone(), u.clone());
check(-l.clone(), u.clone());
check(-u.clone(), -l.clone());
check(-u, -l);
}

fn seeded_value_stability<R: SeedableRng + RandBigInt>(expected: &[&str]) {
Expand Down
1 change: 1 addition & 0 deletions ci/big_serde/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "big_serde"
version = "0.1.0"
authors = ["Josh Stone <cuviper@gmail.com>"]
edition = "2018"

[dependencies]
num-traits = "0.2.11"
Expand Down
8 changes: 2 additions & 6 deletions ci/big_serde/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@

#![cfg(test)]

extern crate num_bigint;
extern crate num_traits;
extern crate serde_test;

use num_bigint::{BigInt, BigUint};
use num_traits::{One, Zero};
use serde_test::{assert_tokens, Token};
Expand Down Expand Up @@ -69,7 +65,7 @@ fn bigint_negone() {
}

// Generated independently from python `hex(factorial(100))`
const FACTORIAL_100: &'static [u32] = &[
const FACTORIAL_100: &[u32] = &[
0x00000000, 0x00000000, 0x00000000, 0x2735c61a, 0xee8b02ea, 0xb3b72ed2, 0x9420c6ec, 0x45570cca,
0xdf103917, 0x943a321c, 0xeb21b5b2, 0x66ef9a70, 0xa40d16e9, 0x28d54bbd, 0xdc240695, 0x964ec395,
0x1b30,
Expand Down Expand Up @@ -110,7 +106,7 @@ fn bigint_factorial_100() {
fn big_digits() {
// Try a few different lengths for u32/u64 digit coverage
for len in 1..10 {
let digits = 1u32..len + 1;
let digits = 1u32..=len;
let n = BigUint::new(digits.clone().collect());

let mut tokens = vec![];
Expand Down
Loading

0 comments on commit d182c71

Please sign in to comment.