Commit aaad38f7 authored by Robert Bradshaw's avatar Robert Bradshaw

Fix C++ division when true division is enabled.

This fixes Github issue #1950.
parent 3844d1e1
...@@ -11559,7 +11559,7 @@ class DivNode(NumBinopNode): ...@@ -11559,7 +11559,7 @@ class DivNode(NumBinopNode):
self.operand2 = self.operand2.coerce_to_simple(env) self.operand2 = self.operand2.coerce_to_simple(env)
def compute_c_result_type(self, type1, type2): 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: 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(type1, PyrexTypes.c_double_type)
widest_type = PyrexTypes.widest_numeric_type(type2, widest_type) widest_type = PyrexTypes.widest_numeric_type(type2, widest_type)
...@@ -11650,7 +11650,7 @@ class DivNode(NumBinopNode): ...@@ -11650,7 +11650,7 @@ class DivNode(NumBinopNode):
code.putln("}") code.putln("}")
def calculate_result_code(self): 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) return NumBinopNode.calculate_result_code(self)
elif self.type.is_float and self.operator == '//': elif self.type.is_float and self.operator == '//':
return "floor(%s / %s)" % ( return "floor(%s / %s)" % (
......
# mode: run # mode: run
# tag: cpp, werror # tag: cpp, werror
from __future__ import division
from cython cimport typeof from cython cimport typeof
cimport cython.operator cimport cython.operator
...@@ -239,7 +241,7 @@ def test_nonmember_binop(): ...@@ -239,7 +241,7 @@ def test_nonmember_binop():
nonmember binary2 >> [const_char *] nonmember binary2 >> [const_char *]
nonmember binary2 COMMA [const_char *] nonmember binary2 COMMA [const_char *]
""" """
cdef TestOps* t = new TestOps() cdef TestOps* t = new TestOps()
out(1 + t[0], typeof(1 + t[0])) out(1 + t[0], typeof(1 + t[0]))
out(1 - t[0], typeof(1 - t[0])) out(1 - t[0], typeof(1 - t[0]))
...@@ -251,10 +253,10 @@ def test_nonmember_binop(): ...@@ -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])) 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]) x = cython.operator.comma(1, t[0])
out(x, typeof(x)) out(x, typeof(x))
# now test float operators defined outside class # now test float operators defined outside class
out(1. + t[0], typeof(1. + t[0])) out(1. + t[0], typeof(1. + t[0]))
# operator - deliberately omitted # operator - deliberately omitted
...@@ -266,7 +268,7 @@ def test_nonmember_binop(): ...@@ -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])) 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 # for some reason we need a cdef here - not sure this is quite right
y = cython.operator.comma(1., t[0]) y = cython.operator.comma(1., t[0])
out(y, typeof(y)) out(y, typeof(y))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment