diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index f8733052aa5bde7149410f49afb3e52054e1bc1c..df1070631bf58bc6ba43d536eecda25ddde9169d 100644 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -11532,7 +11532,7 @@ class DivNode(NumBinopNode): self.operand2 = self.operand2.coerce_to_simple(env) def compute_c_result_type(self, type1, type2): - if self.operator == '/' and self.ctruedivision: + if self.operator == '/' and self.ctruedivision and not self.is_cpp_operation(): if not type1.is_float and not type2.is_float: widest_type = PyrexTypes.widest_numeric_type(type1, PyrexTypes.c_double_type) widest_type = PyrexTypes.widest_numeric_type(type2, widest_type) @@ -11623,7 +11623,7 @@ class DivNode(NumBinopNode): code.putln("}") def calculate_result_code(self): - if self.type.is_complex: + if self.type.is_complex or self.is_cpp_operation(): return NumBinopNode.calculate_result_code(self) elif self.type.is_float and self.operator == '//': return "floor(%s / %s)" % ( diff --git a/tests/run/cpp_operators.pyx b/tests/run/cpp_operators.pyx index 050806d8fac80eb4c23f0226fb7b2e530d6a4d55..7900aa0648621b25a4007a205a67d2bc44c645d5 100644 --- a/tests/run/cpp_operators.pyx +++ b/tests/run/cpp_operators.pyx @@ -1,6 +1,8 @@ # mode: run # tag: cpp, werror +from __future__ import division + from cython cimport typeof cimport cython.operator @@ -239,7 +241,7 @@ def test_nonmember_binop(): nonmember binary2 >> [const_char *] nonmember binary2 COMMA [const_char *] """ - + cdef TestOps* t = new TestOps() out(1 + t[0], typeof(1 + t[0])) out(1 - t[0], typeof(1 - t[0])) @@ -251,10 +253,10 @@ def test_nonmember_binop(): out(1 ^ t[0], typeof(1 ^ t[0])) out(1 << t[0], typeof(1 << t[0])) out(1 >> t[0], typeof(1 >> t[0])) - + x = cython.operator.comma(1, t[0]) out(x, typeof(x)) - + # now test float operators defined outside class out(1. + t[0], typeof(1. + t[0])) # operator - deliberately omitted @@ -266,7 +268,7 @@ def test_nonmember_binop(): out(1. ^ t[0], typeof(1. ^ t[0])) out(1. << t[0], typeof(1. << t[0])) out(1. >> t[0], typeof(1. >> t[0])) - + # for some reason we need a cdef here - not sure this is quite right y = cython.operator.comma(1., t[0]) out(y, typeof(y))