fix inf/NaN float constants
authorStefan Behnel <scoder@users.berlios.de>
Mon, 21 Apr 2008 06:22:10 +0000 (08:22 +0200)
committerStefan Behnel <scoder@users.berlios.de>
Mon, 21 Apr 2008 06:22:10 +0000 (08:22 +0200)
Cython/Compiler/ExprNodes.py
tests/run/ct_DEF.pyx

index 77aa1bd9ffbeb47456bcea3cfff0b9e7807703ab..e79ae49ca6c6519696525782061dc634e9ea7948 100644 (file)
@@ -677,6 +677,17 @@ class FloatNode(ConstNode):
 
     def compile_time_value(self, denv):
         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):
index d85cfb0668a5fb637f6717a7a1309cdd92cfffc3..1d92cc87cbda0c201744984739aa9a41b14cef6e 100644 (file)
@@ -11,6 +11,12 @@ __doc__ = """
     666
     >>> f()
     12.5
+    >>> nan()
+    nan
+    >>> infp()
+    inf
+    >>> infn()
+    -inf
     >>> s()
     'spam'
     >>> two()
@@ -32,6 +38,9 @@ DEF INT2 = 0x42
 DEF INT3 = 042
 DEF LONG = 666L
 DEF FLOAT = 12.5
+DEF FLOAT_NAN = float('nan')
+DEF FLOAT_INFP = float('+inf')
+DEF FLOAT_INFN = float('-inf')
 DEF STR = "spam"
 DEF TWO = TUPLE[1]
 DEF FIVE = TWO + 3
@@ -68,6 +77,21 @@ def f():
     f = FLOAT
     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():
     cdef char *s
     s = STR