[docs] [issue12067] Doc: remove errors about mixed-type comparisons.

Mark Dickinson report at bugs.python.org
Fri May 13 09:20:44 CEST 2011


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

[Docs]
"If both are numbers, they are converted to a common type."

[Terry]
"In any case, I think it is only true for built-in number types,"

It's not even true for built-in number types.  When comparing an int with a float, it's definitely *not* the case that the int is converted to a float and the floats compared.  And that's for good reason:  the int -> float conversion is lossy for large integers, so if int <-> float comparisons just converted the int to a float before comparing, we'd have (for example):

>>> 10**16 == 1e16 == 10**16 + 1

leading to broken transitivity of equality, and strange dict and set behaviour.

So int <-> float comparisons do a complicated dance under the hood to compare the exact numerical values of the two objects and produce the correct result.

I'm not sure what the intent of the original sentence was, or how to reword it.  The key point is simply that it *is* possible to compare an int with a float, and that the result is sensible, based on numeric values.

----------
nosy: +mark.dickinson

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12067>
_______________________________________


More information about the docs mailing list