Complex number functions for std.math

Don Clugston dac at nospam.com.au
Fri Apr 7 07:41:50 PDT 2006


Norbert Nemec wrote:
> 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)?

That's not bad. I think I'll go with that. Thanks.

> 
> (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"...)

It is a bit of an oxymoron. I do like the idea of having 'complex' as a 
standard alias in std.math. It should operate almost as a reserved word, 
users should not be defining it to be anything other than creal.
But I would not like to have to type "imaginary" instead of "ireal" -- 
it's just too long. Any ideas on that one?

FWIW, the name "imaginary" is a bit stupid, too. In what sense is a 
negative "real" number more "real" than an "imaginary" number? Arguably, 
D is just continuing the trend of inappropriate names <g>.

>> * 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