Two questions about "%a"
Magnus Lie Hetland
magnus at hetland.org
Fri Mar 4 02:20:29 PST 2011
On 2011-03-04 03:16:50 +0100, Nick Sabalausky said:
> I'm no floating-point expert, but I would think that the only way to
> get an exact representation would be to output the raw data in hex (or
> binary, or octal, etc):
>
> writef("0x%X", cast(ulong)1.2);
That's also an option, certainly. Then I could just write it as a
decimal integer, I guess.
But the point of hex-literals for floats is precicely that they can
represent floats exactly (even though it may not *look* like it, as in
this case, because lots of digits are required to approximate the
decimal value 1.2). So using those shold be safe -- and perhaps more
easily read on other platforms, for example (byte order), or into
floats with other precisions or the like.
Thanks for the suggestion, though :)
--
Magnus Lie Hetland
http://hetland.org
More information about the Digitalmars-d-learn
mailing list