This is the mail archive of the guile@cygnus.com mailing list for the guile project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Jim> I take it the custom datatype used by gsl is something like Jim> struct complex { double x, y }; Actually we moved away from that because the layout of structs and arrays of structs is not guaranteed. The internal representation is now something like: typedef struct { double dat[2]; } gsl_complex; #define GSL_REAL(z) ((z).dat[0]) #define GSL_IMAG(z) ((z).dat[1]) #define GSL_COMPLEX_P_REAL(zp) ((zp)->dat[0]) #define GSL_COMPLEX_P_IMAG(zp) ((zp)->dat[1]) #define GSL_COMPLEX_EQ(z1,z2) ((z1).dat[0] == (z2).dat[0] && \ ((z1).dat[1] == (z2).dat[1])) #define GSL_COMPLEX_SET(z,x,y) do {(z).dat[0]=(x); (z).dat[1]=(y);} while(0) and it is very important to only access the functions through those macros. The rest of what Jim says mostly works; the code should maybe be: gsl_complex scm2gsl_complex (SCM z); { gsl_complex out; if (SCM_CPLXP (z)) out = GLS_COMPLEX_SET(scm_num2dbl(z), SCM_IMAG(z)); else out = GLS_COMPLEX_SET(scm_num2dbl(z), 0.0); return out; }