On Tue, Mar 13, 2001 at 05:18:35AM -0500, Guido van Rossum wrote: > I think the extent to which HWFP doesn't work for newbies is mostly > related to the change we made in 2.0 where repr() (and hence the > interactive prompt) show full precision, leading to annoyances like > repr(1.1) == '1.1000000000000001'. I'll argue now -- just as i argued back then, but louder! -- that this isn't necessary. repr(1.1) can be 1.1 without losing any precision. Simply stated, you only need to display as many decimal places as are necessary to regenerate the number. So if x happens to be the floating-point number closest to 1.1, then 1.1 is all you have to show. By definition, if you type x = 1.1, x will get the floating-point number closest in value to 1.1. So x will print as 1.1. And entering 1.1 will be sufficient to reproduce x exactly. Thomas Wouters wrote: > I suspect that the change in float.__repr__() did reduce the number of > suprises over something like this, though: (taken from a 1.5.2 interpreter) > > >>> x = 1.000000000001 > >>> x > 1.0 > >>> x == 1.0 > 0 Stick in a warning: floating-point numbers should not be tested for equality and that should help at least somewhat. If you follow the rule i stated above, you would get this: >>> x = 1.1 >>> x 1.1 >>> x == 1.1 warning: floating-point numbers should not be tested for equality 1 >>> x = 1.000000000001 >>> x 1.0000000000010001 >>> x == 1.000000000001 warning: floating-point numbers should not be tested for equality 1 >>> x == 1.0 warning: floating-point numbers should not be tested for equality 0 All of this seems quite reasonable to me. -- ?!ng "Computers are useless. They can only give you answers." -- Pablo Picasso
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