Skip to content

Commit 3dc934d

Browse files
Documenting rounding issue in Binomial (#24)
1 parent 987a975 commit 3dc934d

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/binomial.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ use rand::Rng;
4343
/// let v = bin.sample(&mut rand::rng());
4444
/// println!("{} is from a binomial distribution", v);
4545
/// ```
46+
///
47+
/// # Numerics
48+
/// The implementation uses `f64` internally, which leads to rounding errors for big numbers.
49+
/// For very large samples (`> 2^53`) the least significant bits of the output will not be random.
50+
/// This means that something like `bin.sample(&mut rand::rng()) % 4` will not follow the correct distribution.
51+
/// The more significant bits should be correctly distributed.
4652
#[derive(Clone, Copy, Debug, PartialEq)]
4753
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
4854
pub struct Binomial {

0 commit comments

Comments
 (0)