Merge pull request #25 from phayes/master

This commit is contained in:
Friedel Ziegelmayer 2021-03-05 13:36:26 +01:00 committed by GitHub
commit e88a3f8a5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 22 deletions

View File

@ -1,10 +1,13 @@
[package] [package]
authors = ["dignifiedquire <dignifiedquire@gmail.com>", "The Rust Project Developers"] authors = [
"dignifiedquire <dignifiedquire@gmail.com>",
"The Rust Project Developers"
]
description = "Big integer implementation for Rust" description = "Big integer implementation for Rust"
documentation = "https://docs.rs/num-bigint-dig" documentation = "https://docs.rs/num-bigint-dig"
homepage = "https://github.com/dignifiedquire/num-bigint" homepage = "https://github.com/dignifiedquire/num-bigint"
keywords = ["mathematics", "numerics", "bignum"] keywords = ["mathematics", "numerics", "bignum"]
categories = [ "algorithms", "data-structures", "science" ] categories = ["algorithms", "data-structures", "science"]
license = "MIT/Apache-2.0" license = "MIT/Apache-2.0"
name = "num-bigint-dig" name = "num-bigint-dig"
repository = "https://github.com/dignifiedquire/num-bigint" repository = "https://github.com/dignifiedquire/num-bigint"
@ -36,7 +39,7 @@ default-features = false
[dependencies.rand] [dependencies.rand]
optional = true optional = true
version = "0.7" version = "0.8.3"
default-features = false default-features = false
[dependencies.zeroize] [dependencies.zeroize]
@ -65,10 +68,10 @@ version = "1.2.7"
default-features = false default-features = false
[dev-dependencies] [dev-dependencies]
rand_chacha = "0.2" rand_chacha = "0.3"
rand_xorshift = "0.2" rand_xorshift = "0.3"
rand_isaac = "0.2" rand_isaac = "0.3"
rand = { version = "0.7", features = ["small_rng"] } rand = { version = "0.8", features = ["small_rng"] }
[dev-dependencies.serde_test] [dev-dependencies.serde_test]
version = "1.0" version = "1.0"
@ -79,7 +82,13 @@ autocfg = "0.1.5"
[features] [features]
default = ["std", "i128", "u64_digit"] default = ["std", "i128", "u64_digit"]
i128 = ["num-integer/i128", "num-traits/i128"] i128 = ["num-integer/i128", "num-traits/i128"]
std = ["num-integer/std", "num-traits/std", "smallvec/write", "rand/std", "serde/std"] std = [
"num-integer/std",
"num-traits/std",
"smallvec/write",
"rand/std",
"serde/std"
]
u64_digit = [] u64_digit = []
prime = ["rand"] prime = ["rand/std_rng"]
nightly = [] nightly = []

View File

@ -12,8 +12,8 @@ name = "bench_main"
num-bigint-dig = { path = "../", features = ["prime", "rand"] } num-bigint-dig = { path = "../", features = ["prime", "rand"] }
num-integer = "0.1.39" num-integer = "0.1.39"
num-traits = "0.2.4" num-traits = "0.2.4"
rand = "0.7" rand = "0.8.3"
rand_chacha = "0.2" rand_chacha = "0.3.0"
[dev-dependencies] [dev-dependencies]
criterion = "0.2" criterion = "0.2"

View File

@ -2,7 +2,6 @@
use rand::distributions::uniform::{SampleBorrow, SampleUniform, UniformSampler}; use rand::distributions::uniform::{SampleBorrow, SampleUniform, UniformSampler};
use rand::prelude::*; use rand::prelude::*;
use rand::AsByteSliceMut;
use rand::Rng; use rand::Rng;
use BigInt; use BigInt;
@ -48,12 +47,11 @@ impl<R: Rng + ?Sized> RandBigInt for R {
use super::big_digit::BITS; use super::big_digit::BITS;
let (digits, rem) = bit_size.div_rem(&BITS); let (digits, rem) = bit_size.div_rem(&BITS);
let mut data = smallvec![BigDigit::default(); digits + (rem > 0) as usize]; let mut data = smallvec![BigDigit::default(); digits + (rem > 0) as usize];
// `fill_bytes` is faster than many `gen::<u32>` calls
self.fill_bytes(data[..].as_byte_slice_mut()); // `fill` is faster than many `gen::<u32>` calls
// Swap bytes per the `Rng::fill` source. This might be // Internally this calls `SeedableRng` where implementors are responsible for adjusting endianness for reproducable values.
// unnecessary if reproducibility across architectures is not self.fill(data.as_mut_slice());
// desired.
data.to_le();
if rem > 0 { if rem > 0 {
data[digits] >>= BITS - rem; data[digits] >>= BITS - rem;
} }

View File

@ -10,13 +10,16 @@ use rand::prelude::*;
fn test_mul_divide_torture_count(count: usize) { fn test_mul_divide_torture_count(count: usize) {
let bits_max = 1 << 12; let bits_max = 1 << 12;
let seed = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]; let seed = [
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
26, 27, 28, 29, 30, 31, 32,
];
let mut rng = rand::rngs::SmallRng::from_seed(seed); let mut rng = rand::rngs::SmallRng::from_seed(seed);
for _ in 0..count { for _ in 0..count {
// Test with numbers of random sizes: // Test with numbers of random sizes:
let xbits = rng.gen_range(0, bits_max); let xbits = rng.gen_range(0..bits_max);
let ybits = rng.gen_range(0, bits_max); let ybits = rng.gen_range(0..bits_max);
let x = rng.gen_biguint(xbits); let x = rng.gen_biguint(xbits);
let y = rng.gen_biguint(ybits); let y = rng.gen_biguint(ybits);