Steven D'Aprano <steve+pyt...@pearwood.info> added the comment:

This is not a bug. It is *literally correct* that the int 9007199254740993 is 
not equal to the float 9007199254740992.0 so I really don't know why you would 
desire a different result. If you want to compare two floats, compare two 
floats, not an int and a float.

And it's not a *potential behaviour change", it would be an actual behaviour 
change, and a serious regression.

Stefan states:

> But the way I would have expected this to work is that a comparison of an 
> integer to a float would first convert the integer to a float, and then 
> compare the two floating point values. That's also what the code says.


No it doesn't. What the code says:

    2**53 + 1 == float(2**53 + 1)

not:

    float(2**53 + 1) == float(2**53 + 1)

There's no conversion on the left hand side. The code literally says to compare 
an int to a float.


In general, Python is pretty good at giving as close to mathematically correct 
results as possible. If you want to compare values approximately as floats, you 
should explicitly convert them to floats.

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

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue44054>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to