BartC said:
I get:
300.029999999999970000000000000000000000000000000
using (mingw) gcc 4.5.0 on Windows. I'd prefer to get what you did..
Maybe stop using a second-rate OS with a crappy libc? It's within
the accuracy bounds demanded of the library, but IMHO is not a
useful string to output. It looks like it's just capping the
output at 17 significant digits.
However DMC gives:
300.029999999999972710000000000000000000000000000
It looks like %.__f is turned into %.17f for all __ > 17?
a few extra digits (but it seems incorrectly rounded down on the last
digit). And Pelles C gives:
300.029999999999953433870000000000000000000000000
I'm not sure I can work out what went "wrong" there. Do you get a
round-trip error from that expression when scanf-ed back in (to
any implementation)? I've not looked at the lowest bits in its
representation, but I think it should be OK - my ppc treats it
as the same value as 300.03 (anything above 300.029999999999945
is OK it seems).
which is not quite right. Finally, lcc-win32 gives:
300.030000000000000000000000000000000000000000000
which is either wildly inaccurate, or the only one that is spot on!
Well, it's not wildly inaccurate, as it's accurate to 17 digits, which
is all that is demanded of the library. However, the number you are
attempting to print out is 300.029999999999972715158946812152862548828125
and you have to ask yourself how you would want that number to be
printed. This is a different question from how you would want 300.03 to
be represented, of course.
I've got to admit, I certainly prefer the glibc output in all cases.
Phil