Skip to content

Commit 28e5fe4

Browse files
committed
Use quickcheck Rng utilities to choose better arbitrary floats
1 parent c0afae5 commit 28e5fe4

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/qc.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -155,26 +155,25 @@ macro_rules! arbitrary_float {
155155
where G: Gen
156156
{
157157
let special = [
158-
-0.0, 0.0, 1.0, $ty::NAN, $ty::INFINITY, -$ty::INFINITY
158+
-0.0, 0.0, $ty::NAN, $ty::INFINITY, -$ty::INFINITY
159159
];
160160

161-
if g.gen() { // Random special case
162-
let index: usize = g.gen();
163-
$TY(special[index % special.len()])
164-
} else if g.gen() { // Random anything
161+
if g.gen_weighted_bool(10) { // Random special case
162+
$TY(*g.choose(&special).unwrap())
163+
} else if g.gen_weighted_bool(10) { // NaN variants
165164
let sign: bool = g.gen();
166165
let exponent: <$ty as Float>::Int = g.gen();
167-
let significand: <$ty as Float>::Int = g.gen();
166+
let significand: <$ty as Float>::Int = 0;
168167
$TY($ty::from_parts(sign, exponent, significand))
169168
} else if g.gen() { // Denormalized
170169
let sign: bool = g.gen();
171170
let exponent: <$ty as Float>::Int = 0;
172171
let significand: <$ty as Float>::Int = g.gen();
173172
$TY($ty::from_parts(sign, exponent, significand))
174-
} else { // NaN variants
173+
} else { // Random anything
175174
let sign: bool = g.gen();
176175
let exponent: <$ty as Float>::Int = g.gen();
177-
let significand: <$ty as Float>::Int = 0;
176+
let significand: <$ty as Float>::Int = g.gen();
178177
$TY($ty::from_parts(sign, exponent, significand))
179178
}
180179
}

0 commit comments

Comments
 (0)