Skip to content

Commit

Permalink
UniformInt: rename ints_to_reject/zone field
Browse files Browse the repository at this point in the history
  • Loading branch information
dhardy committed Jun 3, 2019
1 parent ca270f3 commit 0ac3766
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/distributions/uniform.rs
Expand Up @@ -337,7 +337,7 @@ impl<'a, Borrowed> SampleBorrow<Borrowed> for &'a Borrowed where Borrowed: Sampl
pub struct UniformInt<X> {
low: X,
range: X,
ints_to_reject: X,
z: X, // either ints_to_reject or zone depending on implementation
}

macro_rules! uniform_int_impl {
Expand Down Expand Up @@ -391,15 +391,15 @@ macro_rules! uniform_int_impl {
low: low,
// These are really $unsigned values, but store as $ty:
range: range as $ty,
ints_to_reject: ints_to_reject as $unsigned as $ty
z: ints_to_reject as $unsigned as $ty
}
}

fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X {
let range = self.range as $unsigned as $u_large;
if range > 0 {
let unsigned_max = ::core::$u_large::MAX;
let zone = unsigned_max - (self.ints_to_reject as $unsigned as $u_large);
let zone = unsigned_max - (self.z as $unsigned as $u_large);
loop {
let v: $u_large = rng.gen();
let (hi, lo) = v.wmul(range);
Expand Down Expand Up @@ -524,13 +524,13 @@ macro_rules! uniform_simd_int_impl {
low: low,
// These are really $unsigned values, but store as $ty:
range: range.cast(),
zone: zone.cast(),
z: zone.cast(),
}
}

fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X {
let range: $unsigned = self.range.cast();
let zone: $unsigned = self.zone.cast();
let zone: $unsigned = self.z.cast();

// This might seem very slow, generating a whole new
// SIMD vector for every sample rejection. For most uses
Expand Down

0 comments on commit 0ac3766

Please sign in to comment.