Steven D'Aprano <steve+pyt...@pearwood.info> added the comment:
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/ ---------- nosy: +steven.daprano _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue41057> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com