Skip to content

Rweber/wrapping #73

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ categories = ["algorithms", "science", "no-std"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/rust-num/num-integer"
name = "num-integer"
version = "0.1.46"
version = "0.2.0"
readme = "README.md"
exclude = ["/ci/*", "/.github/*"]
edition = "2018"
Expand All @@ -18,7 +18,7 @@ rust-version = "1.31"
features = ["std"]

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

Expand All @@ -28,3 +28,6 @@ std = ["num-traits/std"]

# vestigial features, now always in effect
i128 = []

[patch.crates-io]
num-traits = { git = "https://github.com/rickwebiii/num-traits.git", branch = "rweber/wrapping" }
20 changes: 17 additions & 3 deletions benches/average.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,23 @@ use test::{black_box, Bencher};

// --- Utilities for RNG ----------------------------------------------------

trait BenchInteger: Integer + PrimInt + WrappingAdd + WrappingMul + 'static {}
trait BenchInteger:
Integer
+ PrimInt
+ WrappingAdd<WrappingOutput = Self>
+ WrappingMul<WrappingOutput = Self>
+ 'static
{
}

impl<T> BenchInteger for T where T: Integer + PrimInt + WrappingAdd + WrappingMul + 'static {}
impl<T> BenchInteger for T where
T: Integer
+ PrimInt
+ WrappingAdd<WrappingOutput = T>
+ WrappingMul<WrappingOutput = T>
+ 'static
{
}

// Simple PRNG so we don't have to worry about rand compatibility
fn lcg<T>(x: T) -> T
Expand All @@ -26,7 +40,7 @@ where
// (but we're applying it to arbitrary sizes)
const LCG_A: u32 = 1664525;
const LCG_C: u32 = 1013904223;
x.wrapping_mul(&LCG_A.as_()).wrapping_add(&LCG_C.as_())
x.wrapping_mul(LCG_A.as_()).wrapping_add(LCG_C.as_())
}

// --- Alt. Implementations -------------------------------------------------
Expand Down
20 changes: 17 additions & 3 deletions benches/roots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,23 @@ use num_traits::checked_pow;
use num_traits::{AsPrimitive, PrimInt, WrappingAdd, WrappingMul};
use test::{black_box, Bencher};

trait BenchInteger: Integer + PrimInt + WrappingAdd + WrappingMul + 'static {}
trait BenchInteger:
Integer
+ PrimInt
+ WrappingAdd<WrappingOutput = Self>
+ WrappingMul<WrappingOutput = Self>
+ 'static
{
}

impl<T> BenchInteger for T where T: Integer + PrimInt + WrappingAdd + WrappingMul + 'static {}
impl<T> BenchInteger for T where
T: Integer
+ PrimInt
+ WrappingAdd<WrappingOutput = T>
+ WrappingMul<WrappingOutput = T>
+ 'static
{
}

fn bench<T, F>(b: &mut Bencher, v: &[T], f: F, n: u32)
where
Expand Down Expand Up @@ -55,7 +69,7 @@ where
// (but we're applying it to arbitrary sizes)
const LCG_A: u32 = 1664525;
const LCG_C: u32 = 1013904223;
x.wrapping_mul(&LCG_A.as_()).wrapping_add(&LCG_C.as_())
x.wrapping_mul(LCG_A.as_()).wrapping_add(LCG_C.as_())
}

fn bench_rand<T, F>(b: &mut Bencher, f: F, n: u32)
Expand Down