std.complex

eles eles at eles.com
Tue May 11 08:08:07 PDT 2010


Maybe I am wrong, but my feeling is that if the complex numbers were a native
type (like creal&co. are now), then it would have been possible to have a
dedicated formatting (just like %f, %d and %s are) for writefln.

Putting the type into the library seems to forbid some very nice things:

 - initializing with "Complex!double z=1+2i" or "Complex!double z=1+2*i" or or
"Complex!double z=2.23*exp(1.107*i)" syntax (which is very practical) - even in
C99 one could write "complex double z=1+2*I" (but "I" is a defined symbol) -
instead of "Complex!double(2,3)"
 - lack of support for formatting in writef (although, that should not be
limited to native types)
 - formatting in writef/printf is quite versatile for regular use, and could be
immediately extended to complex numbers (e.g. if one formatting is specified,
then both real and imaginary parts would be displayed with that format),
although 2 different complex-number formats should be defined: real/imaginary
and amplitude/phase


More information about the Digitalmars-d-learn mailing list