mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-01 23:58:20 +00:00
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:
parent
a067cc6b7f
commit
f32489a5a8
1 changed files with 8 additions and 6 deletions
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue