Message361234
The documentation[1] for comparisons between mixed types says:
> [...] when a binary arithmetic operator has operands of different
> numeric types, the operand with the "narrower" type is widened to
> that of the other, where integer is narrower than floating point,
> which is narrower than complex. Comparisons between numbers of
> mixed type use the same rule.
That "use the same rule" part of the last sentence is misleading: it suggests that (for example) when an int is compared with a float, the int is first converted to a float, and then the two floats are compared. But that's not what actually happens: instead, the exact values of the int and float are compared. (And it's essential that equality comparisons happen that way, else equality becomes intransitive and dictionaries with numeric keys get very confused as a result.)
I suggest dropping the last sentence and adding a new paragraph about comparisons between numbers of mixed type.
[1] https://github.com/python/cpython/blob/master/Doc/library/stdtypes.rst#numeric-types-----classint-classfloat-classcomplex |
|
Date |
User |
Action |
Args |
2020-02-02 14:17:34 | mark.dickinson | set | recipients:
+ mark.dickinson, docs@python |
2020-02-02 14:17:34 | mark.dickinson | set | messageid: <1580653054.78.0.127921454413.issue39530@roundup.psfhosted.org> |
2020-02-02 14:17:34 | mark.dickinson | link | issue39530 messages |
2020-02-02 14:17:34 | mark.dickinson | create | |
|