std.complex
John Colvin
john.loughran.colvin at gmail.com
Tue Nov 26 04:52:28 PST 2013
On Tuesday, 26 November 2013 at 11:22:38 UTC, Joseph Rushton
Wakeling wrote:
> On 26/11/13 02:02, Andrei Alexandrescu wrote:
>> If you got the blessing of some complex number expert, that
>> would be great.
>
> I'm in Italy, I could ask the pope ... :-)
>
> As far as I can see the behaviour of std.complex.Complex is
> consistent both with C++'s std::complex and with D's own
> internal cfloat/cdouble/creal types. The only case we don't
> cover with std.complex is that of multiplying a complex number
> with a purely imaginary one (the equivalent of multiplying,
> say, a creal and an ireal; multiplying a creal and a creal,
> even if the real part of the latter is 0, will give the same
> results as std.complex).
>
> We _could_ tweak Complex internally so that in the event that
> its real part is 0, it behaves like a purely imaginary number,
> and if its imaginary part is 0, it behaves like a purely real
> number; but that's problematic for reasons already discussed,
> because it doesn't distinguish between a purely imaginary
> number versus one where the real part is so vanishingly small
> that FP considers it to be 0.
>
> (It also leaves std.complex' behaviour incompatible with
> std::complex and other library implementations, though I guess
> that's less of a concern so long as we think what std.complex
> does is right.)
>
> So, as other people have suggested, really the only thing we
> can reasonably do is to define a separate Imaginary type -- or
> get round the problems with the built-in complex and imaginary
> types. It is really a shame if they are as problematic as I've
> heard. :-(
It seems to me that one really shouldn't special case for
absolute values when dealing with floating point. A floating
Imaginary type and an integer Complex type - both in std.complex
- are the correct solutions IMO.
More information about the Digitalmars-d
mailing list