Two questions about "%a"

Lars T. Kyllingstad public at kyllingen.NOSPAMnet
Wed Mar 2 23:27:13 PST 2011


On Wed, 02 Mar 2011 13:35:11 +0100, Magnus Lie Hetland wrote:

> First question: 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.) Or am I
> missing a difference in functionality?

Hm, that's weird.  I'm pretty sure writefln() is doing the right thing 
here, since that's what printf() does.  I've had a look at the code for 
format(), and it looks to me like it is using some old formatting code 
that is being phased out.  I've created a bug report for this, and will 
look into fixing it shortly:

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


> Second question: Just to make sure, this *is* an exact representation of
> the underlying floating-point number? (I.e., if that'w what I'm after,
> using %a *is* the way to go?)

Yes, that's right.

-Lars


More information about the Digitalmars-d-learn mailing list