Comparison of Imaginary types
Damian McGuckin
damianm at esi.com.au
Sat Jul 11 08:33:13 UTC 2026
On Friday, 10 July 2026 at 15:21:08 UTC, Nick Treleaven wrote:
> One difference is that `*=` with an imaginary (or complex) type
> on the right-hand side is not allowed:
Yes, but that operation is illegal mathematics so quite expected.
>
> Also Don made an argument why imaginary types are not needed in
> D:
> https://forum.dlang.org/post/fmg01c$253i$1@digitalmars.com
Interesting arguments. Not sure I agree with all of it. What is
done in C99 (and even C23) reflects the mathematics, so it is not
a hack.
While 2D CFD (computational fluid dynamics) uses complex
arithmetic, 3D CFD does not (it needs quaternions which are way
too specialised). But structural dynamics uses complex and
imaginary numbers extensively in both 2D and 3D, to handle the
phase of a dynamic load. Also, the field of engineering uses
complex numbers even more extensively but as I am not an
electrical engineer, I will leave niche alone.
When I used D well over 15 years ago, all our work was done with
reals. But I have been using the complex arithmetic of Chapel for
nearly a decade and its imaginary and complex types made life a
dream for dealing with this task. It is also so much easier to
explain the complex arithmetic in the program logic if one can
talk about real and imaginary numbers when discussing complex
numbers. Trying to explain complex numbers in terms of a complex
number with a real component of zero is recursive and I find
recursive explanations very difficult to write.
I will look through those old discussions although they all seem
to deal with the removal of an imaginary type. I was actually
looking for the justification for their original inclusion in D
which would be very much earlier.
More information about the Digitalmars-d-learn
mailing list