Expand description
Nima Badizadegan’s “perfect” conversion.
A Rust port of the round-down variant of Nima Badizadegan’s algorithm.
The functions in this module return a value distributed exactly as if a real number had been drawn uniformly from (0 . . 1) and then rounded down (toward −∞) to a representable floating-point value. Every float in [0 . . 1), including every subnormal and 0 itself, is returned with probability equal to the measure of the interval of reals that rounds down to it.
let mut src = rand_float::sources::Weyl(42);
let x = rand_float::badizadegan::f64_down(|| src.next_u64());
assert!((0.0..1.0).contains(&x));
let y = rand_float::badizadegan::f32_down(|| src.next_u64());
assert!((0.0..1.0).contains(&y));