[Pyrex] C complex vs. python complex
Dan Christensen
jdc at uwo.ca
Thu Jun 22 13:03:23 UTC 2006
I need to wrap some functions that take C complex arguments
and return C complex results. I got this to work using
cdef extern from "complex.h":
ctypedef struct c_complex "complex":
pass
cdef double creal(c_complex z)
cdef double cimag(c_complex z)
cdef extern from "myfile.h":
cdef c_complex cplx(double r, double i)
cplx is actually the following macro:
#define cplx(r,i) ((r)+I*(i))
Then my pyrex code uses creal and cimag to convert a C complex
variable to a python complex, and uses cplx to convert the other way.
But it would be much cleaner if pyrex did the conversion for me.
Is there a way to do this?
Thanks,
Dan
More information about the Pyrex
mailing list