Thread overview |
---|
August 01, 2004 Complex math functions (importing from C) | ||||
---|---|---|---|---|
| ||||
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 |
August 01, 2004 Re: Complex math functions (importing from C) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nick | 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. |
August 01, 2004 Re: Complex math functions (importing from C) | ||||
---|---|---|---|---|
| ||||
Posted in reply to parabolis | 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 |
August 01, 2004 Re: Complex math functions (importing from C) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nick | 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 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 > > |
August 01, 2004 Re: Complex math functions (importing from C) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | In article <cejibv$2c39$2@digitaldaemon.com>, Walter says... > >Are you working with gcc? > Nah, why'd you think that? :) I've just done some experimenting with complex numbers in C using gcc. Nick |
August 02, 2004 Re: Complex math functions (importing from C) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nick | "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? > > > Nah, why'd you think that? :) I've just done some experimenting with complex > 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. |
Copyright © 1999-2021 by the D Language Foundation