From fc97ce42df1614b33abbf051e5a42eb390098b9d Mon Sep 17 00:00:00 2001 From: Sei Lisa Date: Wed, 21 Dec 2016 21:49:43 +0100 Subject: [PATCH] Be explicit about corner cases for llFrand. inf and nan already did the right thing in Python, but just in case that doesn't happen in all platforms, we handle them explicitly. Also, that will make it more immune to bugs in future. --- lslopt/lslbasefuncs.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lslopt/lslbasefuncs.py b/lslopt/lslbasefuncs.py index 1fbcd73..00933ca 100644 --- a/lslopt/lslbasefuncs.py +++ b/lslopt/lslbasefuncs.py @@ -1058,6 +1058,11 @@ if lslcommon.IsCalc: import random def llFrand(lim): assert isfloat(lim) + if math.isinf(lim): + return 0. + if math.isnan(lim): + return lim + lim = F32(lim) # apply constraints val = random.random() * lim # Truncate, rather than rounding