Commit 6f060c90 authored by Dag Sverre Seljebotn's avatar Dag Sverre Seljebotn

complexvar.conjugate() support

parent 6add62f3
...@@ -871,9 +871,22 @@ class CComplexType(CNumericType): ...@@ -871,9 +871,22 @@ class CComplexType(CNumericType):
def attributes_known(self): def attributes_known(self):
if self.scope is None: if self.scope is None:
import Symtab import Symtab
self.scope = Symtab.StructOrUnionScope(self.specalization_name()) self.scope = scope = Symtab.CClassScope(
self.scope.declare_var("real", self.real_type, None, "real") '',
self.scope.declare_var("imag", self.real_type, None, "imag") None,
visibility="extern")
scope.parent_type = self
scope.declare_var("real", self.real_type, None, "real", is_cdef=True)
scope.declare_var("imag", self.real_type, None, "imag", is_cdef=True)
entry = scope.declare_cfunction(
"conjugate",
CFuncType(self, [CFuncTypeArg("self", self, None)]),
pos=None,
defining=1,
cname="__Pyx_c_conj%s" % self.real_type.math_h_modifier)
return True return True
def create_declaration_utility_code(self, env): def create_declaration_utility_code(self, env):
......
...@@ -58,9 +58,11 @@ __doc__ = u""" ...@@ -58,9 +58,11 @@ __doc__ = u"""
>>> test_real_imag_assignment(1.5, -3.5) >>> test_real_imag_assignment(1.5, -3.5)
(1.5-3.5j) (1.5-3.5j)
## XXX not implemented yet! >>> test_conjugate(2+3j)
## >>> test_conjugate(1+2j) (2-3j)
## (1-2j)
>>> test_conjugate_double(2+3j)
(2-3j)
""" """
#cdef extern from "complex.h": #cdef extern from "complex.h":
...@@ -109,6 +111,8 @@ def test_real_imag_assignment(object a, double b): ...@@ -109,6 +111,8 @@ def test_real_imag_assignment(object a, double b):
z.imag = b z.imag = b
return z return z
## XXX not implemented yet! def test_conjugate(float complex z):
## def test_conjugate(float complex z): return z.conjugate()
## return z.conjugate()
def test_conjugate_double(double complex z):
return z.conjugate()
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