www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Complex math functions (importing from C)

reply Nick <Nick_member pathlink.com> writes:
While the complex number support of D is great, I've noticed that phobos still
lacks most math functions for complex numbers. In the mean time I thought I'd
try importing some functions from C, but haven't had much luck with this.

Since you can import non-complex math functions by using the 'real' type
directly, I thought you also might be able to do something like

extern (C) creal cexpl(creal);

but calling this just gives a segfault :( I've also tried calling the functions
with 24 byte structs (a gcc complex long double is 24 bytes, not 20 like creal)
but it still gives the occational segfault (I think it's messing up the stack.)

Anybody who can help me?

Nick
Aug 01 2004
next sibling parent reply parabolis <parabolis softhome.net> writes:
Nick wrote:

 but calling this just gives a segfault :( I've also tried calling the functions
 with 24 byte structs (a gcc complex long double is 24 bytes, not 20 like creal)
 but it still gives the occational segfault (I think it's messing up the stack.)

What do they do with the extra 4 bytes?
 
 Anybody who can help me?
 

I think somebody is currently working on math related functions.
Aug 01 2004
parent Nick <Nick_member pathlink.com> writes:
In article <cej9ja$28nr$1 digitaldaemon.com>, parabolis says...
Nick wrote:

 but calling this just gives a segfault :( I've also tried calling the functions
 with 24 byte structs (a gcc complex long double is 24 bytes, not 20 like creal)
 but it still gives the occational segfault (I think it's messing up the stack.)

What do they do with the extra 4 bytes?

A long double has two unused bytes, and a complex is composed of two of those. The two bytes take on semi-random values depending on which function created them and are ignored in any calculation. The 80 bit float is the maximum on Intel processors, so I guess they are reserved for other architectures. Nick
Aug 01 2004
prev sibling parent reply "Walter" <newshound digitalmars.com> writes:
Are you working with gcc?

"Nick" <Nick_member pathlink.com> wrote in message
news:cej7jg$285p$1 digitaldaemon.com...
 While the complex number support of D is great, I've noticed that phobos

 lacks most math functions for complex numbers. In the mean time I thought

 try importing some functions from C, but haven't had much luck with this.

 Since you can import non-complex math functions by using the 'real' type
 directly, I thought you also might be able to do something like

 extern (C) creal cexpl(creal);

 but calling this just gives a segfault :( I've also tried calling the

 with 24 byte structs (a gcc complex long double is 24 bytes, not 20 like

 but it still gives the occational segfault (I think it's messing up the

 Anybody who can help me?

 Nick

Aug 01 2004
parent reply Nick <Nick_member pathlink.com> writes:
In article <cejibv$2c39$2 digitaldaemon.com>, Walter says...
Are you working with gcc?

numbers in C using gcc. Nick
Aug 01 2004
parent "Walter" <newshound digitalmars.com> writes:
"Nick" <Nick_member pathlink.com> wrote in message
news:cejqit$2erh$1 digitaldaemon.com...
 In article <cejibv$2c39$2 digitaldaemon.com>, Walter says...
Are you working with gcc?


 numbers in C using gcc.

I suspect the problem is in the function return conventions used by the compiler. It's easy enough to check.
Aug 01 2004