HELP: restore my faith in Python
John W. Baxter
jwbnews at scandaroon.com
Mon Mar 6 11:58:04 EST 2000
[Idle thoughts on the thread in general.]
1. Binary floating point correctness is much easier to manage with the
IEEE standard than it was on earlier implementations (eg, IBM 704, et
seq). It's still non-trivial, and still produces those little surprises
(such as 0.1 being inherently imprecise).
2. In the early days of Microsoft BASIC, at least on Mac, Mr. G
released two forms of the interpreter: one worked "speedily" with
binary floating point; one worked slowly and precisely for things like
decimal-based currency using a decimal floating point implementation.
Each had its place, and I used both.
3. Rationals as seen in the Smalltalk implementations I've used worked
fine. One key is that the numerator and denominator can't be limited to
tiny entities like Python integers; they need to be (or be growable to)
entities like Python long integers. [Smalltalk does the growing and
shrinking of numerator and denominator (one can be integer and the other
long integer if needed to express the number) for you, and indeed if a
computation results in a rational which is the moral equivalent of 2/1
the answer becomes the integer 2.]
4. A decimal floating point class could certainly be written for
Python. It would have surprises of its own, but at least 0.1 would be
precise. I haven't looked...perhaps it *has* been written.
--John (who does sometimes wish that 0.1 + 0.1 + 0.1 could be counted to
to equal 0.3, but Python is correct in the following for the floating
word size it uses:
Python 1.5.2 (#2, Dec 23 1999, 13:16:10) [GCC egcs-2.91.66 19990314
(egcs-1.1.2 on bsdos4
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> 0.1 + 0.1 + 0.1 == 0.3
0
>>> )
--
John W. Baxter Port Ludlow, WA USA jwbnews at scandaroon.com
More information about the Python-list
mailing list