logo       

C complex vs. python complex: msg#00040

python.pyrex

Subject: C complex vs. python complex

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


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise