Subject: [clisp-list] FFI with complex numbers?

From: "Hoehle, Joerg-Cyril" <[email-masked]>
Date: Fri May 7 01:31:01 2004

Hi,

Michael Goffioul asks:
>Is it possible to use complex numbers with FFI? What I want to 
>do is to pass 
>complex numbers from LISP to C code (whatever the format 
>received by the C function)

Since there's no standard format for complex numbers in C, the CLISP FFI doesn't provide standardized means to pass such objetcs.
My guess is that a good enough approach is to pass real and imaginary part separately, each using a known format (e.g. double-float) and COERCE to this chosen format on the Lisp side.

Is there anything else that would make you happy?

You could also define a C-STRUCT {double real, imag}, write two functions to convert Common Lisps COMPLEX numbers to that structure and vice-versa and pass along FFI pointers to that a structure.
You should then investigate DEF-C-TYPE and DEF-C-STRUCT and the constructors automatically generated by the FFI. Probably this approach looks like a better design than the above.

Don't the library you want to interface to provide some representation of complex numbers already?

Regards,
	Jorg.

---

From: Florian Weimer <[email-masked]>
Date: Fri May 7 15:38:04 2004

* Joerg-Cyril Hoehle:

> Since there's no standard format for complex numbers in C, the CLISP
> FFI doesn't provide standardized means to pass such objetcs.

ISO C99 adds complex numbers.  C99 support is still evolving in
compilers, though.  However, basic complex arithmetic works nowadays
(libquantum has become quite portable).

-- 
Current mail filters: many dial-up/DSL/cable modem hosts, and the
following domains: atlas.cz, bigpond.com, di-ve.com, hotmail.com,
jumpy.it, libero.it, netscape.net, postino.it, simplesnet.pt,
tiscali.co.uk, tiscali.cz, tiscali.it, voila.fr, yahoo.com.