reduce the chance of rounding errors on int->float coercion
authorStefan Behnel <scoder@users.berlios.de>
Tue, 29 Mar 2011 06:55:10 +0000 (08:55 +0200)
committerStefan Behnel <scoder@users.berlios.de>
Tue, 29 Mar 2011 06:55:10 +0000 (08:55 +0200)
Cython/Compiler/ExprNodes.py

index d90b4b17fe4bf65cba3fe99203fb6a895f9f2875..2f51d4fb092116d83c8a900bcb311debd484f48c 100755 (executable)
@@ -861,9 +861,8 @@ class IntNode(ConstNode):
             return self
         elif dst_type.is_float:
             if self.constant_result is not not_a_constant:
-                float_value = float(self.constant_result)
-                return FloatNode(self.pos, value=repr(float_value), type=dst_type,
-                                 constant_result=float_value)
+                return FloatNode(self.pos, value='%d.0' % int(self.constant_result), type=dst_type,
+                                 constant_result=float(self.constant_result))
             else:
                 return FloatNode(self.pos, value=self.value, type=dst_type,
                                  constant_result=not_a_constant)