[Issue 10881] New: Support %f formatting for a std.complex.complex

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Aug 24 09:22:20 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=10881

           Summary: Support %f formatting for a std.complex.complex
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nobody at puremagic.com
        ReportedBy: bearophile_hugs at eml.cc


--- Comment #0 from bearophile_hugs at eml.cc 2013-08-24 09:22:18 PDT ---
In dmd 2.064alpha you have to use %s to print a std.complex.complex:


import std.stdio: writefln;
import std.complex: complex;
void main() {
    auto c = complex(1.2, 3.4);
    writefln("%s", c);
    auto gaussianInteger = complex!int(1, 2);
    writefln("%s", gaussianInteger);    
}


But today we can have something better so I suggest to modify the toString of
those complex structs to support a basic floating point formatting too (here
3.2f is used for both parts of the complex number):

auto c = complex(1.2, 3.4);
writefln("%3.2f", c);

If you are using the uncommon Gaussian integers then probably you have to use
%d:

auto gaussianInteger = complex!int(1, 2);
writefln("%10d", gaussianInteger);

If you want to format differently the two parts of a complex number, then a
syntax similar to array formatting could be supported, but this is less
important because I think it's a less common need, and could be left for a
successive enhancement:

writefln("%(%1.2f, -1.2f%)", c);

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list