Ok, just a word (carefully:) Ka-Ping Yee wrote: ... > I just tried this in Python 1.5.2+: > > >>> .1 > 0.10000000000000001 > >>> .2 > 0.20000000000000001 > >>> .3 > 0.29999999999999999 Agreed that this is not good. ... > repr()'s contract: > - if repr(x) is syntactically valid, eval(repr(x)) == x > - repr(x) displays x in a safe and readable way > - for objects composed of basic types, repr(x) reflects > what the user would have to say to produce x This sounds reasonable. BTW my problem did not come up by typing something in, but I just rounded a number down to 3 digits past the dot. Then, as usual, I just let the result drop from the prompt, without prefixing it with "print". repr() was used, and the result was astonishing. Here is the problem, as I see it: You say if you type 3.1416, you want to get exactly this back. But how should Python know that you typed it in? Same in my case: I just rounded to 3 digits, but how should Python know about this? And what do you expect when you type in 3.14160, do you want the trailing zero preserved or not? Maybe we would need to carry exactness around for numbers. Or even have a different float type for cases where we want exact numbers? Keyboard entry and rounding produce exact numbers. Simple operations between exact numbers would keep exactness, higher level functions would probably not. I think we dlved into a very difficult domain here. ciao - chris -- Christian Tismer :^) <mailto:tismer@appliedbiometrics.com> Applied Biometrics GmbH : Have a break! Take a ride on Python's Kaunstr. 26 : *Starship* http://starship.python.net 14163 Berlin : PGP key -> http://wwwkeys.pgp.net PGP Fingerprint E182 71C7 1A9D 66E9 9D15 D3CC D4D7 93E2 1FAE F6DF where do you want to jump today? http://www.stackless.com
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4