rust-random / rand

A Rust library for random number generation.
https://crates.io/crates/rand
Other
1.67k stars 432 forks source link

Hypergeo fix #1510

Closed benjamin-lieser closed 1 week ago

benjamin-lieser commented 1 month ago

Summary

This is a fix for https://github.com/rust-random/rand/issues/1508 Thanks a lot to @WarrenWeckesser for finding it.

And it also replaces the very crude Stirling's approximation with something more precise without depending on a ln_gamma implementation.

Details

I do not have evidence that the stirling errors effect sampling in a big way, but I also do not have evidence that they do not and the error is quite big for small values.

For performance reasons we could shift by less than 3, but the LOGSQRT2PI correction is cheap and helps already a lot. The 1/12v term might also not matter that much.