[issue44054] 2**53+1 != float(2**53+1)

Mark Dickinson report at bugs.python.org
Thu May 6 08:40:30 EDT 2021


Mark Dickinson <dickinsm at gmail.com> added the comment:

> 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

I have a vague memory that that's the way it *did* work once upon a time, many many decades ago. But an equality comparison between int and float that simply converted the int to a float would break transitivity of equality, leading to issues with containment in sets, dicts and lists. Given

n = 2**53
x = 2.**53

if equality comparison worked as you describe you'd have n == x and x == n + 1, so to keep transitivity you'd have to make n == n + 1.

In short, the behaviour is very much deliberate.

> That's also what the code says.

Do you have a pointer? This may be a comment bug.

----------

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


More information about the Python-bugs-list mailing list