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).
This commit is contained in:
Sei Lisa 2016-05-26 19:45:31 +02:00
parent a067cc6b7f
commit f32489a5a8

View file

@ -20,6 +20,7 @@
import lslfuncs import lslfuncs
from lslcommon import Key, Vector, Quaternion from lslcommon import Key, Vector, Quaternion
from lslparse import warning from lslparse import warning
import math
class outscript(object): class outscript(object):
@ -74,12 +75,13 @@ class outscript(object):
return '((float)' + str(int(value)) + ')' return '((float)' + str(int(value)) + ')'
s = repr(value) s = repr(value)
if s == 'nan': if s == 'nan':
return '((float)"' + s + '")' # this shouldn't appear in globals if math.copysign(1, value) < 0: # Indeterminate
if s in ('inf', '-inf'): return '(1e40*0)'
s = '1e40' if s == 'inf' else '-1e40' return '((float)"NaN")' # this shouldn't appear in globals
if self.globalmode: if s == 'inf':
return s return '1e40'
return '((float)' + s + ')' 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 # Try to remove as many decimals as possible but keeping the F32 value intact
exp = s.find('e') exp = s.find('e')
if ~exp: if ~exp: