Thread overview
[Issue 5237] New: writefln doesn't respect Complex.toString
Nov 18, 2010
Don
Nov 19, 2010
Don
Nov 19, 2010
Don
Nov 19, 2010
Don
Sep 02, 2011
Kenji Hara
Sep 10, 2011
Kenji Hara
November 18, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5237

           Summary: writefln doesn't respect Complex.toString
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody@puremagic.com
        ReportedBy: clugdbug@yahoo.com.au


--- Comment #0 from Don <clugdbug@yahoo.com.au> 2010-11-18 14:19:09 PST ---
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);
    writefln("z = %f z2 = %f", z, z2);
    writefln("z = %e z2 = %e", z, z2);
    writefln("z = %a z2 = %a", z, z2);
}

z = 10+1.5e-06i z2 = 10.0000000000000000+0.0000015000000000i
z = 10+1.5e-06i z2 = 10.000000+0.000001i
z = 10+1.5e-06i z2 = 1.000000e+01+1.500000e-06i
z = 10+1.5e-06i z2 = 0x1.4p+3+0x1.92a737110e454p-20i

Clearly the format string is not being passed, or is being ignored.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 19, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5237



--- Comment #1 from Don <clugdbug@yahoo.com.au> 2010-11-19 01:25:33 PST ---
Partial fix in svn 2183. This fixes the last 3 cases, not the first one.
It would be very straightforward to implement the first case, but we need to
think if it would really be a sensible design, since we'd be doing
atoi(itoa(atoi(original_string))).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 19, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5237


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jmdavisProg@gmx.com


--- Comment #2 from Don <clugdbug@yahoo.com.au> 2010-11-19 01:27:43 PST ---
*** Issue 5231 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 19, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5237


Lars T. Kyllingstad <bugzilla@kyllingen.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@kyllingen.net


--- Comment #3 from Lars T. Kyllingstad <bugzilla@kyllingen.net> 2010-11-19 02:26:47 PST ---
(In reply to comment #1)
> Partial fix in svn 2183. This fixes the last 3 cases, not the first one.
> It would be very straightforward to implement the first case, but we need to
> think if it would really be a sensible design, since we'd be doing
> atoi(itoa(atoi(original_string))).

Couln't that be easily solved by storing the full format string in FormatSpec?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 19, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5237



--- Comment #4 from Don <clugdbug@yahoo.com.au> 2010-11-19 04:19:11 PST ---
(In reply to comment #3)
> (In reply to comment #1)
> > Partial fix in svn 2183. This fixes the last 3 cases, not the first one.
> > It would be very straightforward to implement the first case, but we need to
> > think if it would really be a sensible design, since we'd be doing
> > atoi(itoa(atoi(original_string))).
> 
> Couln't that be easily solved by storing the full format string in FormatSpec?

Probably. My guess is that positional parameters will make it more complicated, but possibly it's really simple.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 19, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5237



--- Comment #5 from Lars T. Kyllingstad <bugzilla@kyllingen.net> 2010-11-19 04:32:21 PST ---
(In reply to comment #4)
> My guess is that positional parameters will make it more complicated, but possibly it's really simple.

Regarding positional parameters, allow me to restate a point I made in the DIP9 thread on the newsgroup:

I think it's best to leave out the '%' from the format string that is sent to toString().  This will facilitate the use of positional parameters, in which the percent is followed by a position specifier which necessarily has to be handled at a higher level than toString().  Example:

  BigInt i = "456";
  BigInt j = "123";
  writefln("%2$s %1$s", i, j);  // Prints "123 456"

The only thing BigInt.writeTo() needs to see is the part after the '$'
character.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 19, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5237



--- Comment #6 from Lars T. Kyllingstad <bugzilla@kyllingen.net> 2010-11-19 04:35:04 PST ---
(In reply to comment #3)
> (In reply to comment #1)
> > Partial fix in svn 2183. This fixes the last 3 cases, not the first one.
> > It would be very straightforward to implement the first case, but we need to
> > think if it would really be a sensible design, since we'd be doing
> > atoi(itoa(atoi(original_string))).
> 
> Couln't that be easily solved by storing the full format string in FormatSpec?

One problem is of course when the user passes a non-immutable format string, as in

  char[] fmt = "%s %s".dup;
  writefln(fmt, 1, 3.14);

Then each format specifier has to be dup-ed before being stored in FormatSpec.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 09, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5237


Andrei Alexandrescu <andrei@metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |andrei@metalanguage.com
         AssignedTo|nobody@puremagic.com        |andrei@metalanguage.com


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 02, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5237


Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch


--- Comment #7 from Kenji Hara <k.hara.pg@gmail.com> 2011-09-02 12:09:52 PDT ---
https://github.com/D-Programming-Language/phobos/pull/126

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 10, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5237


Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


--- Comment #8 from Kenji Hara <k.hara.pg@gmail.com> 2011-09-10 11:46:40 PDT ---
https://github.com/D-Programming-Language/phobos/commit/4c8cbd2f29637abfadb2d3057a5e747fe8084d4d

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