Comparison of Imaginary types

Nick Treleaven nick at geany.org
Sat Jul 11 10:56:33 UTC 2026


On Saturday, 11 July 2026 at 08:33:13 UTC, Damian McGuckin wrote:
> On Friday, 10 July 2026 at 15:21:08 UTC, Nick Treleaven wrote:
>> 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.

Don said:

> Complex numbers are fundamental to mathematics in a way that 
> quaternions are not.

Though however important something is, it doesn't automatically 
justify having a language feature if a library solution is good 
enough. I'm not saying there isn't a justification for complex 
numbers in the language, but the technical case needs to be made.

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

Would it help to use UFCS?
```d
import std;

auto i(T)(T im) => complex(0, im);

void main()
{
     auto c = 4 + 2.i;
     c.writeln;
}
```

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

A justification is in the D vs C++ article link I sent you 
earlier.

There is a Phobos issue for imaginary support:
https://github.com/dlang/phobos/issues/10022



More information about the Digitalmars-d-learn mailing list