avoid a floating point exception in RanMars::rayleigh() from taking log(0)

This commit is contained in:
Axel Kohlmeyer 2021-04-02 22:08:39 -04:00
parent 9da49d9c6f
commit 678302bfcb
No known key found for this signature in database
GPG Key ID: D9B44E93BF0C375A
1 changed files with 7 additions and 4 deletions

View File

@ -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));
}
/* ----------------------------------------------------------------------