Handle inf, +inf, -nan, and nan constants

This commit is contained in:
rocky
2017-11-24 15:30:05 -05:00
parent 37b8e21c76
commit f34c558d38
3 changed files with 10 additions and 1 deletions

Binary file not shown.

View File

@@ -0,0 +1,4 @@
a = 1e300 * 1e300 * 0
b = -1e300 * 1e300 * 0
c = 1e300 * 1e300
d = -1e300 * 1e300

View File

@@ -808,7 +808,12 @@ class SourceWalker(GenericASTTraversal, object):
def n_LOAD_CONST(self, node): def n_LOAD_CONST(self, node):
data = node.pattr; datatype = type(data) data = node.pattr; datatype = type(data)
if isinstance(datatype, int) and data == minint: if isinstance(data, float) and str(data) in frozenset(['nan', '-nan', 'inf', '-inf']):
# float values 'nan' and 'inf' are not directly representable in Python at least
# before 3.5 and even there it is via a library constant.
# So we will canonicalize their representation as float('nan') and float('inf')
self.write("float('%s')" % data)
elif isinstance(datatype, int) and data == minint:
# convert to hex, since decimal representation # convert to hex, since decimal representation
# would result in 'LOAD_CONST; UNARY_NEGATIVE' # would result in 'LOAD_CONST; UNARY_NEGATIVE'
# change:hG/2002-02-07: this was done for all negative integers # change:hG/2002-02-07: this was done for all negative integers