From 737c9641105427e4d7396dcb5911d6be64674912 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Tue, 11 May 2010 19:31:27 +0200 Subject: [PATCH] fix ticket #525: let float values pass through the compiler literally --- Cython/Compiler/ExprNodes.py | 10 ++++++---- tests/run/specialfloat.pyx | 9 +++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) 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() -- 2.26.2