From c555a01a485b3b31b633bc8096c34329369531a5 Mon Sep 17 00:00:00 2001 From: Sei Lisa Date: Wed, 6 Jan 2016 01:21:04 +0100 Subject: [PATCH] It's possible to enter Infinity as a float constant, so do that rather than the (float)"inf" kludge. It remains for NaN though. --- lslopt/lslfoldconst.py | 7 +++---- lslopt/lsloutput.py | 7 ++++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lslopt/lslfoldconst.py b/lslopt/lslfoldconst.py index fa0794d..5e460ce 100644 --- a/lslopt/lslfoldconst.py +++ b/lslopt/lslfoldconst.py @@ -1228,10 +1228,9 @@ class foldconst(object): + nt # pragma: no cover def IsValidGlobalIdOrConst(self, node): - # inf and nan can't be represented as a simple constant + # nan can't be represented as a simple constant; all others are valid return not (node['nt'] == 'CONST' and node['t'] == 'float' - and (math.isinf(node['value']) - or math.isnan(node['value']))) + and math.isnan(node['value'])) def IsValidGlobalConstant(self, decl): if 'ch' not in decl: @@ -1261,6 +1260,6 @@ class foldconst(object): self.FoldTree(tree, idx) self.globalmode = False if warningpass and not self.IsValidGlobalConstant(tree[idx]): - warning('Expression does not resolve to a simple constant.') + warning("Expression in globals doesn't resolve to a simple constant.") else: self.FoldTree(tree, idx) diff --git a/lslopt/lsloutput.py b/lslopt/lsloutput.py index 1d1fd10..93ad34d 100644 --- a/lslopt/lsloutput.py +++ b/lslopt/lsloutput.py @@ -71,8 +71,13 @@ class outscript(object): # Important inside lists!! return '((float)' + str(int(value)) + ')' s = repr(value) - if s in ('inf', '-inf', 'nan'): + 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 + ')' # Try to remove as many decimals as possible but keeping the F32 value intact exp = s.find('e') if ~exp: