[Tutor] list output -- float output
spir
denis.spir at free.fr
Fri Nov 14 15:21:17 CET 2008
A.T.Hofkamp a écrit :
> spir wrote:
>> # By the way, I do not understand at all the behaviour of repr on
>> rounded floats:
>> x = round(1.1,1)
>> print x, repr(x), "%s" %x
>> 1.1 1.1000000000000001 1.1
>
> This is a FAQ question:
>
>
http://www.python.org/doc/faq/general/#why-are-floating-point-calculations-so-inaccurate
Well, actually not really I guess. I asked for rounded floats, not
full-precision ones.
Now, after more reflexion on the topic, I understand that even rounded floats
need to keep full precision internally, because of the 'modular' difference
between decimal and binary representations that causes 'epsilon' errors; which
still applies on rounded floats, for the rounding operates at the decimal
level. In other words, (decimal) rounding does not eliminate the source of
'little errors' -- it should be binary rounding instead, but this is probably
not very useful for us in the real world ;-).
The reason why repr(), that shows inner representation, is still full of junk
digits for rounded floats, while str() shows the expected format.
denis
> Sincerely,
> Albert
>
>
>
>
More information about the Tutor
mailing list