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] |
> The gsl contains many functions that involve complex numbers. While they
> are a custom datatype in C libraries, they're a built-in type in scheme.
> How does one pass real- and imgainary part of a SCM obj representing a
> complex number through libguile, so that the gsl can map it from and to
> an instance of the corresponding struct ? I don't feel like constructing
> a smob for something that already has a built-in equivalent.
I take it the custom datatype used by gsl is something like
struct complex { double x, y };
What's wrong with converting between that and Guile's normal complex
number representation? That is, to convert a gsl complex number to a
Scheme value, call scm_makdbl; to do the reverse, do something like
this:
struct complex scm2complex (SCM z);
{
struct complex out;
out.x = scm_num2dbl (z);
if (SCM_CPLXP (z))
out.y = SCM_IMAG(z);
else
out.y = 0.0;
return out;
}