From 678302bfcb33486ea6cf1320538b203796e02306 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 2 Apr 2021 22:08:39 -0400 Subject: [PATCH] avoid a floating point exception in RanMars::rayleigh() from taking log(0) --- src/random_mars.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/random_mars.cpp b/src/random_mars.cpp index 621d7d3008..78c6f93ba4 100644 --- a/src/random_mars.cpp +++ b/src/random_mars.cpp @@ -136,13 +136,16 @@ double RanMars::gaussian(double mu, double sigma) double RanMars::rayleigh(double sigma) { - double first,v1; + double v1; - if (sigma <= 0) error->all(FLERR,"Invalid Rayleigh parameter"); + if (sigma <= 0.0) error->all(FLERR,"Invalid Rayleigh parameter"); v1 = uniform(); - first = sigma*sqrt(-2.0*log(v1)); - return first; + // avoid a floating point exception due to log(0.0) + // and just return a very big number + if (v1 == 0.0) return 1.0e300; + + return sigma*sqrt(-2.0*log(v1)); } /* ----------------------------------------------------------------------