floating point glitch

Paul Foley see at below.invalid
Tue Sep 28 10:55:19 CEST 2004

On Mon, 27 Sep 2004 23:21:12 -0700, Tim Roberts wrote:

> Paul Rubin <http://phr.cx@NOSPAM.invalid> wrote:
>> Michael Hoffman <m.h.3.9.1.without.dots.at.cam.ac.uk at example.com> writes:
>>> Actually, print essentialy uses str() to get the string
>>> representation. But repr(list) or str(list) still gets the repr() of
>>> each item of the list rather than the str():
>> >>> print .66
>> 0.66
>> >>> print [.66]
>> [0.66000000000000003]
>> Yucch!  Also, str is not invertible:

> Right!  That's the point.  str() is the perfect solution in those cases
> where you want the language to lie to you.  In many cases, that IS what you
> want.  repr() is the perfect solution when you need an invertible function.

The "perfect solution" is either: (a) to print the minimal number of
digits that can maintain print/read consistency -- in this case, that
means printing "0.66", or (b) to print the actual, exact, decimal
representation of the value -- in this case, that means printing

And I think (a) is more perfect than (b) :-)

Malum est consilium quod mutari non potest             -- Publilius Syrus

(setq reply-to
  (concatenate 'string "Paul Foley " "<mycroft" '(#\@) "actrix.gen.nz>"))

More information about the Python-list mailing list