Author mark.dickinson
Recipients cvrebert, docs@python, ezio.melotti, mark.dickinson, rhettinger, terry.reedy
Date 2011-05-13.07:20:42
SpamBayes Score 1.73134e-11
Marked as misclassified No
Message-id <1305271243.86.0.874496378001.issue12067@psf.upfronthosting.co.za>
In-reply-to
Content
[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.
History
Date User Action Args
2011-05-13 07:20:44mark.dickinsonsetrecipients: + mark.dickinson, rhettinger, terry.reedy, ezio.melotti, cvrebert, docs@python
2011-05-13 07:20:43mark.dickinsonsetmessageid: <1305271243.86.0.874496378001.issue12067@psf.upfronthosting.co.za>
2011-05-13 07:20:43mark.dickinsonlinkissue12067 messages
2011-05-13 07:20:42mark.dickinsoncreate