diff options
Diffstat (limited to 'src/rand.c')
-rw-r--r-- | src/rand.c | 9 |
1 files changed, 6 insertions, 3 deletions
@@ -9,12 +9,15 @@ unsigned long int rand_seed() { return seed; } -double rand_dist_pow(const gsl_rng *r, double beta) { - double x = 0; +long double rand_dist_pow(const gsl_rng *r, double beta) { + long double x = 0; // underflow means that for very small beta x is sometimes identically zero, // which causes problems - while ((x = exp(log(gsl_rng_uniform_pos(r)) / beta)) == 0.0); + while (x == 0.0) { + long double y = logl(gsl_rng_uniform_pos(r)) / beta; + x = expl(y); + } return x; } |