complex number support

Quirin Schroll qs.il.paperinik at gmail.com
Mon Feb 9 11:20:14 UTC 2026


On Wednesday, 4 February 2026 at 18:00:45 UTC, Walter Bright 
wrote:
> On 2/4/2026 9:15 AM, Quirin Schroll wrote:
>> Having a built-in complex number types was a major selling 
>> point when I started looking into D ~10 years ago.
>
> I'm interested in your reasons!

I leaned C and C++ as part of a mandatory 2-semester university 
course that teaches programming with focus on numerical problems. 
I aced the exam and became a tutor for it the next years. That 
was at the time when I discovered D, and noticed several things 
are much easier in D. I thought of translating the exercises and 
possible solutions (from German to English and from C++ to D). I 
ended up discarding that project for lack of time, but it taught 
me a lot about D. This was before C++11 had widespread support, 
including user-defined literals for imaginary and complex 
numbers. Also, C++ has no pure-imaginary types!

Maybe it’s the pure mathematician in me, but complex numbers are 
numbers. And frankly, I never understand what’s the harm in 
supporting them. C++ can barely get away with an STL 
implementation and the `std::complex` template has lots of 
special restrictions and rules on it such as you can reinterpret 
a `std::complex<T>` as a `T[2]` and a `std::complex<T>[n]` as a 
`T[2*n]` if I remember correctly. All to be compatible with C’s 
types, which would be so much easier if it just were a built-in 
type officially.

When I discovered D, I was amazed in a bunch of ways (usually 
small stuff where it had options to express yourself instead of 
insisting on one style or another), and it having complex number 
support was like: Hey, those guys get it.

If you want to make D’s imaginary and complex types perfect, 
allow for an implicit conversion from floating point types to 
complex types that are bigger. I can’t remember how often I’ve 
written `+ 0i`.


More information about the Digitalmars-d mailing list