Commit 9b7cc754 authored by Robert Bradshaw's avatar Robert Bradshaw

Complex negation

parent 3bd0078f
......@@ -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
......
......@@ -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):
......
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