Complex number functions for std.math

Norbert Nemec Norbert at Nemec-online.de
Fri Mar 31 05:41:56 PST 2006


Don Clugston wrote:
> Some time ago I wrote some complex number functions for std.math, but
> they were not really usable because of the implicit real->creal
> conversion issue. Now that that problem has been removed in DMD 0.150,
> several could be added.
> 
> There are a few issues to be addressed, though:
> * The function cos(x) + I*sin(x), which on x86 machines is very
> efficient, and available through the FSINCOS asm instruction (the only
> CPU support for complex numbers!) is important for many of these
> functions, and it could usefully become an intrinsic.
> What should it be called? Ideas I've had
> creal exp(ireal x)  -- It's correct, but I don't think this 'feels' like
>               an intrinsic.
> creal cis(real x)   -- namespace pollution could be an issue
> creal cosisin(real x) -- doesn't this look a bit silly?
> creal fcis(real x)  -- mirrors fabs(), this is what I put into Ares,
>                     but is it too obscure?

How about
        alias creal complex;
	complex expi(real x)
reflecting the fact that it actually computes exp(I*x)?

(Sorry for writing "complex" instead of the monstrosity "creal". My
fingers just don't obey me when I command them to write about a
"complex real" number. Of course, "creal" could also stand for "really
complex". But then "real" should be renamed into "cnreal", standing for
"not really complex"...)

> 
> * DDoc comments.
> Should sin(creal) be with sin(real) ? Or should the complex trig
> functions be put together?
> 



More information about the Digitalmars-d mailing list