Commit 495011ef authored by Stefan Behnel's avatar Stefan Behnel

fix inf/NaN float constants

parent a60e97c2
...@@ -677,6 +677,17 @@ class FloatNode(ConstNode): ...@@ -677,6 +677,17 @@ class FloatNode(ConstNode):
def compile_time_value(self, denv): def compile_time_value(self, denv):
return float(self.value) return float(self.value)
def calculate_result_code(self):
strval = str(self.value)
if strval == 'nan':
return "NAN"
elif strval == 'inf':
return "INFINITY"
elif strval == '-inf':
return "(-INFINITY)"
else:
return strval
class StringNode(ConstNode): class StringNode(ConstNode):
......
...@@ -11,6 +11,12 @@ __doc__ = """ ...@@ -11,6 +11,12 @@ __doc__ = """
666 666
>>> f() >>> f()
12.5 12.5
>>> nan()
nan
>>> infp()
inf
>>> infn()
-inf
>>> s() >>> s()
'spam' 'spam'
>>> two() >>> two()
...@@ -32,6 +38,9 @@ DEF INT2 = 0x42 ...@@ -32,6 +38,9 @@ DEF INT2 = 0x42
DEF INT3 = 042 DEF INT3 = 042
DEF LONG = 666L DEF LONG = 666L
DEF FLOAT = 12.5 DEF FLOAT = 12.5
DEF FLOAT_NAN = float('nan')
DEF FLOAT_INFP = float('+inf')
DEF FLOAT_INFN = float('-inf')
DEF STR = "spam" DEF STR = "spam"
DEF TWO = TUPLE[1] DEF TWO = TUPLE[1]
DEF FIVE = TWO + 3 DEF FIVE = TWO + 3
...@@ -68,6 +77,21 @@ def f(): ...@@ -68,6 +77,21 @@ def f():
f = FLOAT f = FLOAT
return f return f
def nan():
cdef float f
f = FLOAT_NAN
return f
def infp():
cdef float f
f = FLOAT_INFP
return f
def infn():
cdef float f
f = FLOAT_INFN
return f
def s(): def s():
cdef char *s cdef char *s
s = STR s = STR
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment