From f32489a5a8ffdb716f81d04a6a0f0cc83f41293e Mon Sep 17 00:00:00 2001 From: Sei Lisa Date: Thu, 26 May 2016 19:45:31 +0200 Subject: [PATCH] Distinguish indeterminates and improve infinities in output. '(float)"-nan"' doesn't return Indet in LSL: llOwnerSay(llList2CSV([(float)"-nan"])); // outputs "nan", not "-nan" Therefore, for the output to yield the correct result we have to use a different strategy to generate an indeterminate. We choose '(1e40*0)' which is shorter than the rest. Also, we don't output infinites as '(float)"[-]inf"' but alwas as '1e40' or '(float)-1e40' (or just '-1e40' if we're in globals). --- lslopt/lsloutput.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lslopt/lsloutput.py b/lslopt/lsloutput.py index 800df86..9be6bdf 100644 --- a/lslopt/lsloutput.py +++ b/lslopt/lsloutput.py @@ -20,6 +20,7 @@ import lslfuncs from lslcommon import Key, Vector, Quaternion from lslparse import warning +import math class outscript(object): @@ -74,12 +75,13 @@ class outscript(object): return '((float)' + str(int(value)) + ')' s = repr(value) if s == 'nan': - return '((float)"' + s + '")' # this shouldn't appear in globals - if s in ('inf', '-inf'): - s = '1e40' if s == 'inf' else '-1e40' - if self.globalmode: - return s - return '((float)' + s + ')' + if math.copysign(1, value) < 0: # Indeterminate + return '(1e40*0)' + return '((float)"NaN")' # this shouldn't appear in globals + if s == 'inf': + return '1e40' + if s == '-inf': + return '-1e40' if self.globalmode else '((float)-1e40)' # Try to remove as many decimals as possible but keeping the F32 value intact exp = s.find('e') if ~exp: