www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5687] New: std.string.format() error with "%a"

reply d-bugmail puremagic.com writes:
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



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: -------
Mar 02 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5687




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: -------
Mar 03 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5687


Don <clugdbug yahoo.com.au> changed:

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




 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: -------
Mar 03 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5687




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: -------
Mar 03 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5687




01:57:22 PST ---

 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: -------
Mar 03 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5687


Walter Bright <bugzilla digitalmars.com> changed:

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



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: -------
Mar 03 2011
prev sibling parent d-bugmail puremagic.com writes:
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



*** 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: -------
Apr 01 2012