Thread overview
[Issue 5687] New: std.string.format() error with "%a"
Mar 03, 2011
Don
Mar 03, 2011
Don
Mar 03, 2011
Walter Bright
Apr 01, 2012
Stewart Gordon
March 03, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5687

           Summary: std.string.format() error with "%a"
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody@puremagic.com
        ReportedBy: bugzilla@kyllingen.net


--- Comment #0 from Lars T. Kyllingstad <bugzilla@kyllingen.net> 2011-03-02 23:23:44 PST ---
Magnus Lie Hetland wrote in D.learn:

I just noticed that writefln("%a", 1.2) writes 0x1.3333333333333p+0, while
writeln(format("%a", 1.2)) (that is, with std.string.format) writes
0x9.9999999999998p-3 ... wouldn't it be nice to be consistent here? (The former
is what printf in gcc gives.)

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



--- Comment #1 from Lars T. Kyllingstad <bugzilla@kyllingen.net> 2011-03-03 00:27:42 PST ---
I've found the cause for this:  1.2 is a double, and should be formatted as such, but it is converted to a real internally in std.format.doFormat().

I think the right way to go is to rewrite std.string.format() in terms of
std.format.formattedWrite() instead of std.format.doFormat().

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


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug@yahoo.com.au


--- Comment #2 from Don <clugdbug@yahoo.com.au> 2011-03-03 01:12:37 PST ---
(In reply to comment #1)
> I've found the cause for this:  1.2 is a double, and should be formatted as such, but it is converted to a real internally in std.format.doFormat().

I don't think that's the reason. On Windows, the %A format always begins with
0x1.  (except of course for 0, NaN, inf).
You will never, under any circumstances, see something beginning with 0x9.
Is it actually true that %A on Linux for doubles always begins with 0x1.  ?
If so, then it's a Linux %A bug for reals.

In fact, converting from double to real should NEVER change the %a result.


> I think the right way to go is to rewrite std.string.format() in terms of
> std.format.formattedWrite() instead of std.format.doFormat().

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



--- Comment #3 from Don <clugdbug@yahoo.com.au> 2011-03-03 01:17:33 PST ---
On Windows:

import std.stdio;
import std.string;

void main()
{
    writefln("%a", 1.2);
    writeln(format("%a", 1.2));
}
-------
0x1.3333333333333p+0
0x1.3333333333333p+0
-------
This bug is Linux-only.

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



--- Comment #4 from Lars T. Kyllingstad <bugzilla@kyllingen.net> 2011-03-03 01:57:22 PST ---
(In reply to comment #2)
> Is it actually true that %A on Linux for doubles always begins with 0x1.  ?

Having tested with a large number of random doubles, that certainly seems to be the case.

> If so, then it's a Linux %A bug for reals.

Wow, you'd think someone would have discovered this before.

> In fact, converting from double to real should NEVER change the %a result.

Thinking some more about it, that makes sense.

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


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com


--- Comment #5 from Walter Bright <bugzilla@digitalmars.com> 2011-03-03 11:55:36 PST ---
%a and %A formatting is done in Phobos using snprintf, which (sadly) produces different results on Windows than Linux.

In order to properly fix this, we just need to write our own %a formatter.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 01, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=5687


Stewart Gordon <smjg@iname.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |smjg@iname.com
         Resolution|                            |DUPLICATE


--- Comment #6 from Stewart Gordon <smjg@iname.com> 2012-04-01 15:04:28 PDT ---
*** This issue has been marked as a duplicate of issue 4532 ***

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