Piet van Oostrum
piet at cs.uu.nl
Mon Feb 16 23:41:25 CET 2004
>>>>> "Terry Reedy" <tjreedy at udel.edu> (TR) wrote:
TR> "Piet van Oostrum" <piet at cs.uu.nl> wrote in message
TR> news:wzisi7b9nj.fsf at cs.uu.nl...
>> >>>>> Brian <pythonista_at_sbcglobal_dot_net at invalid.net> (B) wrote:
>> >>>> print str(0.1)
B> It's important to realize that this is, in a real sense, an illusion:
B> value in the machine is not exactly 1/10, you're simply rounding the
B> display of the true machine value."
>> On the other hand, python could have done better.
TR> Python gives you a choice between most exact and 'pleasant'. This *is*
TR> better, in my opinion, than no choice.
0.10000000000000001 is not more exact then 0.1. It is a false illusion of
>> There are algorithms to
>> print floating point numbers properly with a more pleasant output:
>> in this particular case python could have given "0.1" also with "print
TR> What? In 2.2:
>>>> print 0.1
TR> did this change in 2.3?
Ok, mistake, I should have left out the print. But you should know what I
>> Unfortunately most C libraries only use the stupid algorithm which often
>> gives some useless digits.
TR> They are not useless if you want more accuracy about what you have and what
TR> you will get with further computation. Tracking error expansion is an
TR> important part of designing floating point calculations.
>> This is because ideally it should print the representation with the least
>> number of digits that when read back gives the same internal value as the
>> number printed. In this case that is obviously "0.1".
TR> This is opinion, not fact. Opinions are divided.
It would cause no errors and it would prevent a lot of the questions that
appear about every few days here about this subject. So what is the
advantage of printing 0.10000000000000001 or xx.xxx999999999998?
Piet van Oostrum <piet at cs.uu.nl>
URL: http://www.cs.uu.nl/~piet [PGP]
Private email: P.van.Oostrum at hccnet.nl
More information about the Python-list