std.complex
Joseph Rushton Wakeling
joseph.wakeling at webdrake.net
Thu Jan 2 16:22:16 PST 2014
On 03/01/14 01:04, Lars T. Kyllingstad wrote:
> Mathematically, the real numbers are a ring, whereas the purely imaginary
> numbers are not. (I've been out of the abstract algebra game for a couple of
> years now, so please arrest me if I've remembered the terminology wrongly.)
> What it boils down to is that they are not closed under multiplication, which
> gives them radically different properties - or lack thereof.
I've been out of the abstract algebra game for rather longer :-) but regardless
of terminology, I understand what you mean.
My point was meant to be somewhat simpler: if you have
x * (a + bi)
(i.e. real * complex in terms of the computer representation) then, this will
come out with higher precision than
(x + 0i) * (a + bi)
... because you can avoid unnecessary multiplications by zero and other such
things. You can also avoid some nasty nan's that may arise in the latter case.
You get to enjoy this extra-precision-and-avoid-nasty-errors because we already
have built-in numerical types and std.complex.Complex defines binary operations
relative to them as well as to other Complex types. I'm simply suggesting that
the same opportunities to avoid those calculation errors should be available
when you're dealing with purely-imaginary types.
It's an implementation issue AFAICS, not a question of mathematical theory,
although like you and Don I find the lack of closure for imaginary op imaginary
to be very annoying. (I got round it simply by not defining opOpAssign for
operations that could not be assigned back to an Imaginary type.)
More information about the Digitalmars-d
mailing list