it's time to change how things are printed

Don nospam at nospam.com
Thu Nov 18 13:25:28 PST 2010


Steven Schveighoffer wrote:
> On Thu, 18 Nov 2010 15:13:19 -0500, Don <nospam at nospam.com> wrote:
> 
>> Lars T. Kyllingstad wrote:
>>> First of all, I think Andrei has already implemented this in the 
>>> write*() functions.  I use this toString() style also for 
>>> std.complex.Complex, and I can print complex numbers no problem.
>>
>> Really? It doesn't work for me.
>>
>> import std.complex;
>> import std.stdio;
>>
>> void main()
>> {
>>      cdouble z2 = 10 + 1.5e-6i;
>>      Complex!(double) z;
>>      z.re = 10;
>>      z.im = 1.5e-6;
>>      writefln("z= %.16f z2 = %.16f", z, z2);
>> }
>>
>> Prints:
>> z = 10+1.5e-06i z2 = 10.0000000000000000+0.0000015000000000i
> 
> Haven't tested, but docs state that
> 
> "Note that complex numbers are floating point numbers, so the only valid 
> format characters are 'e', 'f', 'g', 'a', and 's', where 's' gives the 
> default behaviour. ***Positional parameters are not valid in this 
> context.***"
> 
> I'd suggest trying one of those other format types without the numeric 
> parts.
> 
> -Steve

     writefln("z = %f z2 = %f", z, z2);
z = 10+1.5e-06i z2 = 10.000000+0.000001i
     writefln("z = %e z2 = %e", z, z2);
z = 10+1.5e-06i z2 = 1.000000e+01+1.500000e-06i
     writefln("z = %a z2 = %a", z, z2);
z = 10+1.5e-06i z2 = 0x1.4p+3+0x1.92a737110e454p-20i


More information about the Digitalmars-d mailing list