On Saturday, 19 November 2016 at 16:17:08 UTC, Meta wrote:
On Saturday, 19 November 2016 at 09:38:38 UTC, Marduk wrote:
Dear all,
I just discovered D and I am translating some numerical code I
wrote in C. I was surprised to learn that there are at least
two things that are easier in C than in D:
+ Writing complex numbers
C: complex double z = 2.0 + 3.0*I;
D: auto z = complex(2.0, 3.0);
+ Arrays of complex numbers
C: complex double a[2][2] = {{1.0*I, 0.0}, {0.0, 1.0*I}};
D: Complex!double[2][2] a = [[complex(0.0, 1.0),
complex(0.0)], [complex(0.0), complex(0.0, 1.0)]];
The difference is that D is more verbose. Am I missing
something? Can we have C's behaviour in D?
D used to support complex numbers in the language (actually it
still does, they're just deprecated). This code should compile
with any D compiler:
cdouble[2][2] a = [[0 + 1i, 0], [0, 0 + 1i]];
Thank you! However, I am concerned that if this is deprecated,
then I should not use it (it is not future-proof). I wonder why D
dropped this syntax for complex numbers. It is very handy.