[issue42148] floating point representation issues

Steven D'Aprano report at bugs.python.org
Sun Oct 25 20:14:06 EDT 2020


Steven D'Aprano <steve+python at pearwood.info> 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*0.1 != 27.7) {say 'unequal'}"
unequal

In Ruby:

irb(main):001:0> 277*0.1
=> 27.7
irb(main):002:0> 277*0.1 == 27.7
=> false


Julia agrees with Python:

julia> 277*0.1
27.700000000000003

So does the Rhino javascript interpreter:

js> 277*0.1
27.700000000000003

I think Eric's instinct was correct.

----------

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


More information about the Python-bugs-list mailing list