From: Robert Bradshaw Date: Thu, 14 May 2009 08:25:06 +0000 (-0700) Subject: Complex negation X-Git-Tag: 0.11.2.rc1~10^2~16 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=9b7cc754b5ec699ce47b8effe77dae099d069d67;p=cython.git Complex negation --- diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index 5ae051bf..e2e25af2 100644 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -3706,6 +3706,7 @@ class UnopNode(ExprNode): # - Allocate temporary for result if needed. subexprs = ['operand'] + infix = True def calculate_constant_result(self): func = compile_time_unary_operators[self.operator] @@ -3820,13 +3821,17 @@ class UnaryMinusNode(UnopNode): self.type = self.operand.type else: self.type_error() + if self.type.is_complex: + self.infix = env.directives['c99_complex'] def py_operation_function(self): return "PyNumber_Negative" def calculate_result_code(self): - return "(-%s)" % self.operand.result() - + if self.infix: + return "(-%s)" % self.operand.result() + else: + return "%s(%s)" % (self.operand.type.unary_op('-'), self.operand.result()) class TildeNode(UnopNode): # unary '~' operator diff --git a/tests/run/complex_numbers_T305.pyx b/tests/run/complex_numbers_T305.pyx index 8cdd6087..5d89388a 100644 --- a/tests/run/complex_numbers_T305.pyx +++ b/tests/run/complex_numbers_T305.pyx @@ -5,11 +5,11 @@ __doc__ = u""" (-0.5+2j) >>> test_arithmetic(2j, 4j) - (6j, -2j, (-8+0j), (0.5+0j)) + (-2j, 6j, -2j, (-8+0j), (0.5+0j)) >>> test_arithmetic(6+12j, 3j) - ((6+15j), (6+9j), (-36+18j), (4-2j)) + ((-6-12j), (6+15j), (6+9j), (-36+18j), (4-2j)) >>> test_arithmetic(5-10j, 3+4j) - ((8-6j), (2-14j), (55-10j), (-1-2j)) + ((-5+10j), (8-6j), (2-14j), (55-10j), (-1-2j)) >>> test_div_by_zero(4j) -0.25j @@ -57,7 +57,7 @@ def test_object_conversion(o): return z def test_arithmetic(double complex z, double complex w): - return z+w, z-w, z*w, z/w + return -z, z+w, z-w, z*w, z/w @cython.cdivision(False) def test_div_by_zero(double complex z):