Re: Bug Report on float number calculation in IDLE
Terry Reedy <[email protected]> Sat, 6 Feb 2016 14:50:53 -0500
| Newsgroups | gmane.comp.python.idle |
|---|---|
| Message-ID | <[email protected]> |
On 12/19/2015 5:20 AM, Grey wrote: > I have found a strange issue on float number calculation in IDEL > of Python 2.7X。 IDLE does not run you code. As far as running code goes, IDLE is an input-output front-end run by Python. It displays what Python outputs. If you had run the same code in Python directly, you would have seen the same result. >>> num = .1 + .1 + .1 + .1 +.1 +.1 + .1 + .1 + .1 >>> num 0.8999999999999999 >>> print(num) 0.9 Interactive echo (>>> num) prints repr(num), which is as accurate as possible. Print prints str(num), which in 2.7 is rounded to a 'nice' form. Because this was confusing, it was changed in 3.0. >>> repr(num) '0.8999999999999999' >>> str(num) '0.9' > 1,When I tried to calculate the sum of a bunch of float numbers > in IDLE of Python 2.7.6 I found that the result was not > accurate(well, I have knew that it is up to the storage format of > data by searching the information on Internet). Issues of round-off error with floats are well documented. I believe there is an entry in the Python FAQ for this. Summary: no bug, and nothing to do with IDLE -- Terry Jan Reedy _______________________________________________ IDLE-dev mailing list [email protected] https://mail.python.org/mailman/listinfo/idle-dev