star-sp

Random number generators and distributions
git clone git://git.meso-star.fr/star-sp.git
Log | Files | Refs | README | LICENSE

commit abd4afca65ec25ca19208670afd1f8723fcfa7db
parent 952521287a20346a6ba8404aab152b21c80ec203
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Thu, 13 Oct 2016 14:23:14 +0200

Fix the canonical random number generation for float

Diffstat:
Msrc/ssp_rng.c | 13++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/src/ssp_rng.c b/src/ssp_rng.c @@ -580,13 +580,12 @@ ssp_rng_canonical_float(struct ssp_rng* rng) return RAN_NAMESPACE::generate_canonical <float, std::numeric_limits<float>::digits>(rng_cxx); #else - const double rd = RAN_NAMESPACE::generate_canonical - <double, std::numeric_limits<float>::digits>(rng_cxx); - float rf = (float)rd; - if(rf > rd) { - rf = std::nextafter(rf, -std::numeric_limits<float>::infinity()); - } - return rf; + float r; + do { + r = RAN_NAMESPACE::generate_canonical + <float, std::numeric_limits<float>::digits>(rng_cxx); + } while(r >= 1); + return r; #endif }