[issue42148] floating point representation issues

2020-10-25 Thread Eric V. Smith
Eric V. Smith added the comment: Thanks for double-checking the other languages, Steven. -- ___ Python tracker ___ ___ Python-bugs-

[issue42148] floating point representation issues

2020-10-25 Thread Steven D'Aprano
Steven D'Aprano added the comment: It looks like Python is correct and the other languages may be just truncating the output. In the Lua interpreter: > =277*0.1 27.7 > = 277*0.1 == 27.7 false Perl: $ perl -e "use feature qw(say); say 277*0.1" 27.7 $ perl -e "use feature qw(say); if (277*

[issue42148] floating point representation issues

2020-10-25 Thread Steven D'Aprano
Steven D'Aprano 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

[issue42148] floating point representation issues

2020-10-25 Thread Eric V. Smith
Eric V. Smith added the comment: This isn't a bug. It's due to the base 2 representation of floating point numbers. See for example: See https://docs.python.org/3/tutorial/floatingpoint.html It's possible, depending on your use case, you might want to use the decimal module. But that has it

[issue42148] floating point representation issues

2020-10-25 Thread Andrea Tuccia
New submission from Andrea Tuccia : I'm noticing some floating point representation precision issues that occurs on all versions and platforms: >>> 277*0.1 27.703 >>> 1.2-1.0 0.19996 >>> import numpy as np >>> np.double(277*0.1) 27.703 >>> np.double(1.2-1.0)