[issue42148] floating point representation issues

Steven D'Aprano report at bugs.python.org
Sun Oct 25 19:55:13 EDT 2020


Steven D'Aprano <steve+python at pearwood.info> added the comment:

Eric I would normally agree with you but the only thing which gives me pause is the statement that this doesn't occur with C, Lua and Perl.

That alone doesn't mean much. Different interpreters can use different algorithms for printing floats, Python changed its algorithm in 3.1 and backported it to 2.7:

https://docs.python.org/3.1/whatsnew/3.1.html#other-language-changes

and now uses Gay's algorithm which will often give different, shorter, results than other algorithms. Other languages do other things, for example R is notorious for just terminating the float output after a few decimal places, so you have numbers which look identical but are unequal.

Andrea, do you still think this is a bug? Can you demonstrate some code in another language that shows the output you expect? (Preferably an interpreter rather than C.)

Most importantly, can you demonstrate that the other language's output is correct and Python's is wrong? In particular, are you sure that the output in those other languages is not just rounding the result to a certain number of decimal places?

If you can satisfy those, please re-open the ticket, otherwise I expect that Eric is correct.

----------
nosy: +steven.daprano

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42148>
_______________________________________


More information about the Python-bugs-list mailing list