From: Stefan Behnel Date: Tue, 11 May 2010 17:31:27 +0000 (+0200) Subject: fix ticket #525: let float values pass through the compiler literally X-Git-Tag: 0.13.beta0~93 X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=737c9641105427e4d7396dcb5911d6be64674912;p=cython.git fix ticket #525: let float values pass through the compiler literally --- diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index dbaa142c..cfd83ff6 100755 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -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 diff --git a/tests/run/specialfloat.pyx b/tests/run/specialfloat.pyx index 993d1478..7b65942e 100644 --- a/tests/run/specialfloat.pyx +++ b/tests/run/specialfloat.pyx @@ -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()