Skip to content

Commit b6a5f08

Browse files
teryrorvks
authored andcommitted
Fix compile errors for older versions of rustc
1 parent 903817c commit b6a5f08

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

rand_distr/src/geometric.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl Distribution<u64> for Geometric
7575
return failures;
7676
}
7777

78-
if self.p == 0.0 { return u64::MAX; }
78+
if self.p == 0.0 { return core::u64::MAX; }
7979

8080
// Based on the algorithm presented in section 3 of
8181
// Karl Bringmann and Tobias Friedrich (July 2013) - Exact and Efficient
@@ -106,7 +106,7 @@ impl Distribution<u64> for Geometric
106106
// choose M uniformly from [0, 2^k), but reject with probability (1 - p)^M
107107
let m = loop {
108108
let m = rng.gen::<u64>() & ((1 << k) - 1);
109-
let p_reject = if m <= i32::MAX as u64 {
109+
let p_reject = if m <= core::i32::MAX as u64 {
110110
(1.0 - self.p).powi(m as i32)
111111
} else {
112112
(1.0 - self.p).powf(m as f64)
@@ -128,7 +128,7 @@ impl Distribution<u64> for Geometric
128128
///
129129
/// See [`Geometric`](crate::Geometric) for the general geometric distribution.
130130
///
131-
/// Implemented via iterated [Rng::gen::<u64>().leading_ones()].
131+
/// Implemented via iterated [Rng::gen::<u64>().leading_zeros()].
132132
///
133133
/// # Example
134134
/// ```
@@ -145,7 +145,7 @@ impl Distribution<u64> for StandardGeometric {
145145
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> u64 {
146146
let mut result = 0;
147147
loop {
148-
let x = rng.gen::<u64>().leading_ones() as u64;
148+
let x = rng.gen::<u64>().leading_zeros() as u64;
149149
result += x;
150150
if x < 64 { break; }
151151
}
@@ -201,7 +201,7 @@ mod test {
201201

202202
#[test]
203203
fn test_standard_geometric() {
204-
let mut rng = crate::test::rng(54321);
204+
let mut rng = crate::test::rng(654321);
205205

206206
let distr = StandardGeometric;
207207
let expected_mean = 1.0;

rand_distr/tests/value_stability.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ fn binominal_stability() {
3636

3737
#[test]
3838
fn geometric_stability() {
39-
test_samples(464, StandardGeometric, &[0, 2, 0, 2, 10, 0, 0, 0, 0, 2, 0, 2, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2]);
39+
test_samples(464, StandardGeometric, &[3, 0, 1, 0, 0, 3, 2, 1, 2, 0]);
4040

4141
test_samples(464, Geometric::new(0.5).unwrap(), &[2, 1, 1, 0, 0, 1, 0, 1]);
4242
test_samples(464, Geometric::new(0.05).unwrap(), &[24, 51, 81, 67, 27, 11, 7, 6]);

0 commit comments

Comments
 (0)