It's possible to enter Infinity as a float constant, so do that rather than the (float)"inf" kludge. It remains for NaN though.

This commit is contained in:
Sei Lisa 2016-01-06 01:21:04 +01:00
parent 881a33a427
commit c555a01a48
2 changed files with 9 additions and 5 deletions

View file

@ -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)

View file

@ -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: