Skip to main content

Module badizadegan

Module badizadegan 

Source
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));

Functions§

f32_down
Returns a random f32 distributed as a uniform real in (0 . . 1) rounded down (toward −∞) to the nearest representable value.
f64_down
Returns a random f64 distributed as a uniform real in (0 . . 1) rounded down (toward −∞) to the nearest representable value.