complexvar.conjugate() support
authorDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Thu, 15 Oct 2009 08:35:20 +0000 (10:35 +0200)
committerDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Thu, 15 Oct 2009 08:35:20 +0000 (10:35 +0200)
Cython/Compiler/PyrexTypes.py
tests/run/complex_numbers_T305.pyx

index f6474f85c4b542460c2a5a22ccfe4fe7c263716d..f1636daa81f489eb37d3a86c185092534ba7ae0e 100644 (file)
@@ -871,9 +871,22 @@ class CComplexType(CNumericType):
     def attributes_known(self):
         if self.scope is None:
             import Symtab
-            self.scope = Symtab.StructOrUnionScope(self.specalization_name())
-            self.scope.declare_var("real", self.real_type, None, "real")
-            self.scope.declare_var("imag", self.real_type, None, "imag")
+            self.scope = scope = Symtab.CClassScope(
+                    '',
+                    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
 
     def create_declaration_utility_code(self, env):
index 231a4762eb48e81fc7779eb2ff51558e4d78cbfa..71846397882f216985df42e33ee2b80e0a0683f7 100644 (file)
@@ -58,9 +58,11 @@ __doc__ = u"""
     >>> test_real_imag_assignment(1.5, -3.5)
     (1.5-3.5j)
 
-## XXX not implemented yet!
-## >>> test_conjugate(1+2j)
-## (1-2j)
+    >>> test_conjugate(2+3j)
+    (2-3j)
+
+    >>> test_conjugate_double(2+3j)
+    (2-3j)
 """
 
 #cdef extern from "complex.h":
@@ -109,6 +111,8 @@ def test_real_imag_assignment(object a, double b):
     z.imag = b
     return z
 
-## XXX not implemented yet!
-## def test_conjugate(float complex z):
-##     return z.conjugate()
+def test_conjugate(float complex z):
+    return z.conjugate()
+
+def test_conjugate_double(double complex z):
+    return z.conjugate()