floating point in 2.0
Kurt B. Kaiser
kbk at shore.net
Wed Jun 6 11:52:49 EDT 2001
"Michael P. Soulier" wrote:
> In Python 1.5.2, I could do this:
>
> good = (0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0)
>
> I could then get back exactly this when I output the value of "good".
> However, with Python 2.0, I get this:
>
> >>> good
> (0.0, 0.10000000000000001, 0.20000000000000001, 0.29999999999999999,
> 0.40000000000000002, 0.5, 0.59999999999999998, 0.69999999999999996,
> 0.80000000000000004, 0.90000000000000002, 1.0)
from sys import displayhook
def nogeekydisplay(x):
print x
sys.displayhook = nogeekydisplay
Put that in your .pythonrc config file so it will load at startup.
****************************************
"The current Python solution has worked for many users, and this should
not break it. Therefore, in the default configuration,nothing will
change
in the REPL loop." - PEP 217 Final
While displayhook is a good thing, IMHO Python's value as a beginner
language is diminished by the new choice of default output format.
It would be interesting to know what percentage of those who use
Python "out of the box" really would choose the "more precise" default
output which has to be rounded off in their heads....
And now we're pounding on people because they keep asking a simple
question. Well, I'm afraid they're going to keep asking!!
It-may-not-be-a-bug-but-it's-an-infelicity'ly yrs, KBK
more keywords: floatingpoint floating-point bug
More information about the Python-list
mailing list