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

Ticket #445, explicit complex casting

parent 539846c7
...@@ -4328,6 +4328,8 @@ class TypecastNode(ExprNode): ...@@ -4328,6 +4328,8 @@ class TypecastNode(ExprNode):
elif from_py and to_py: elif from_py and to_py:
if self.typecheck and self.type.is_extension_type: if self.typecheck and self.type.is_extension_type:
self.operand = PyTypeTestNode(self.operand, self.type, env, notnone=True) self.operand = PyTypeTestNode(self.operand, self.type, env, notnone=True)
elif self.type.is_complex and self.operand.type.is_complex:
self.operand = self.operand.coerce_to_simple(env)
def nogil_check(self, env): def nogil_check(self, env):
if self.type and self.type.is_pyobject and self.is_temp: if self.type and self.type.is_pyobject and self.is_temp:
...@@ -4342,8 +4344,20 @@ class TypecastNode(ExprNode): ...@@ -4342,8 +4344,20 @@ class TypecastNode(ExprNode):
pass pass
def calculate_result_code(self): def calculate_result_code(self):
opnd = self.operand if self.type.is_complex:
return self.type.cast_code(opnd.result()) operand_result = self.operand.result()
if self.operand.type.is_complex:
real_part = self.type.real_type.cast_code("__Pyx_CREAL(%s)" % operand_result)
imag_part = self.type.real_type.cast_code("__Pyx_CIMAG(%s)" % operand_result)
else:
real_part = self.type.real_type.cast_code(operand_result)
imag_part = "0"
return "%s(%s, %s)" % (
self.type.from_parts,
real_part,
imag_part)
else:
return self.type.cast_code(self.operand.result())
def get_constant_c_result_code(self): def get_constant_c_result_code(self):
operand_result = self.operand.get_constant_c_result_code() operand_result = self.operand.get_constant_c_result_code()
......
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