fix ticket #525: let float values pass through the compiler literally
authorStefan Behnel <scoder@users.berlios.de>
Tue, 11 May 2010 17:31:27 +0000 (19:31 +0200)
committerStefan Behnel <scoder@users.berlios.de>
Tue, 11 May 2010 17:31:27 +0000 (19:31 +0200)
Cython/Compiler/ExprNodes.py
tests/run/specialfloat.pyx

index dbaa142c05b2069010f80688f05fd9953e7bd042..cfd83ff6dc7d14dff6c95092fca7b7b98d22d0c9 100755 (executable)
@@ -839,12 +839,14 @@ class FloatNode(ConstNode):
         return float(self.value)
     
     def calculate_result_code(self):
-        strval = repr(float(self.value))
-        if strval == 'nan':
+        strval = self.value
+        assert isinstance(strval, (str, unicode))
+        cmpval = repr(float(strval))
+        if cmpval == 'nan':
             return "(Py_HUGE_VAL * 0)"
-        elif strval == 'inf':
+        elif cmpval == 'inf':
             return "Py_HUGE_VAL"
-        elif strval == '-inf':
+        elif cmpval == '-inf':
             return "(-Py_HUGE_VAL)"
         else:
             return strval
index 993d1478446844f255eb63cba2586aeec1c9b3c6..7b65942e8eccedbced323739be1d5fdb0887f32e 100644 (file)
@@ -1,4 +1,5 @@
 DEF FLOAT = 12.5
+DEF EFLOAT = 5e-1
 DEF FLOAT_NAN = float('nan')
 DEF FLOAT_INFP = float('+inf')
 DEF FLOAT_INFN = float('-inf')
@@ -20,6 +21,14 @@ def f():
     f = FLOAT
     return f
 
+def efloat():
+    """
+    >>> efloat()
+    0.5
+    """
+    cdef float f = EFLOAT
+    return f
+
 def nan1():
     """
     >>> nan1()