== Quote from Lars T. Kyllingstad (pub...@kyllingen.nospamnet)'s article > On Tue, 11 May 2010 15:08:07 +0000, eles wrote: > > 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" > I don't think there will still be a special syntax for complex literals > when the built-in types are deprecated. I'd guess not. It is, however, > likely that creal etc. will be aliases for Complex!real etc. And this > doesn't look that bad: > auto z = cdouble(1,2);
My opinion is that it does. Image writing y=(3+2i)^2+z^2*i. OTOH, the suggestion you made below (see below)... > > or or > > "Complex!double z=2.23*exp(1.107*i)" syntax (which is very practical) - > The following does just that, and IMO it looks a lot better: > auto z = fromPolar(2.23, 1.107); > > even in C99 one could write "complex double z=1+2*I" (but "I" is a > > defined symbol) - instead of "Complex!double(2,3)" > If you want that, just define > immutable I = Complex!float(0, 1); it is nice. However, I think it should be defined as Complex!real (0,1); I hope it will be automatically downsized to Complex!int if the left value is a Complex!int and so on. I vote for defining it in std.complex for the folowing reasons: - it will enforce coding discipline and standardize code among libraries and users, the code will be consistent and copy-paste portable. - it is similar to C99, already judged as acceptable for the C community - if such an elementary thing is left to be defined by the programmer, what long before not using the std.complex module at all? I mean, as well one could re-define the whole complex library. I think having std.complex in the standard library is primarily for standardization and only second for its usefulness (ok, is useful too, but I want to make a point). Also, I think the best is to mimick the functions in the C99 <complex.h>: http://www.opengroup.org/onlinepubs/009695399/basedefs/ complex.h.html Me, for one, I prefer writing y=z*conj(z) instead of z=z*z.conj(). OK, maybe is just personal preference. OTOH, I feel like maintaining x.re and x.im instead of creal(x) and cimag(x), since the latter (as defined in C99) are only right-values. I have some experience with both C99 complex and with GNU Scientific Library GSL_COMPLEX. Both have ups and downs, I still prefer to work with C99, though. Also, if we are here, is any way to define ' (apostrophe) for an (unary) operator? Having z' to mean (z conjugate) would be awesome (y=z*z'). But maybe is just my Matlab background speaking here. Or another character (ideas, anyone?... #z, z#, z~ or ~z etc.). A note of modesty: I do not try to push it harder than it is acceptable, but since the complex numbers are just in a major rewrite, let's try to do it in the best way. We are not constrained by compatibility/legacy issues. Thanks. eles