This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author steven.daprano
Recipients Fenn Ehk, mark.dickinson, steven.daprano
Date 2020-06-20.18:14:59
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1592676899.39.0.351982142194.issue41057@roundup.psfhosted.org>
In-reply-to
Content
Further to what Mark said, I'm afraid you are mistaken when you thought that "the result was correct" on R. R cheats by not printing the full precision of the number, they just stop printing digits, giving a false impression of accuracy. You can prove this for yourself:

> 0.4 + 8/100
[1] 0.48
> (0.4 + 8/100) == 0.48
[1] FALSE

So even though the printed result *looks* like 0.48, it actually isn't. If you investigate carefully, you will probably find that the number R calculates is the same as Python.

And the same as Javascript:

js> 0.4 + 8/100
0.48000000000000004

and pretty much every programming language that uses 64-bit floats.


BTW, this is a FAQ:

https://docs.python.org/3/faq/design.html#why-are-floating-point-calculations-so-inaccurate

There are a ton of other resources on the web explaining this, since it occurs virtually everywhere, in every language with fixed-precision floating point numbers. For example:

https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html

https://randomascii.wordpress.com/2012/05/20/thats-not-normalthe-performance-of-odd-floats/

https://randomascii.wordpress.com/2012/04/05/floating-point-complexities/
History
Date User Action Args
2020-06-20 18:14:59steven.dapranosetrecipients: + steven.daprano, mark.dickinson, Fenn Ehk
2020-06-20 18:14:59steven.dapranosetmessageid: <1592676899.39.0.351982142194.issue41057@roundup.psfhosted.org>
2020-06-20 18:14:59steven.dapranolinkissue41057 messages
2020-06-20 18:14:59steven.dapranocreate