summaryrefslogtreecommitdiff
path: root/src/rand.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/rand.c')
-rw-r--r--src/rand.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/rand.c b/src/rand.c
index 1a6a3d4..75722ac 100644
--- a/src/rand.c
+++ b/src/rand.c
@@ -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;
}