You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
assignee=Noneclosed_at=<Date2020-03-04.17:45:59.511>created_at=<Date2020-02-02.14:17:34.755>labels= ['3.7', '3.8', '3.9', 'docs']
title='Documentation about comparisons between numeric types is misleading'updated_at=<Date2020-03-04.17:46:22.998>user='https://github.com/mdickinson'
The documentation 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.
I'm at the sprints at PyCascades and was looking for an issue to work on and came across this and wanted to know more about it. As I was doing some research, I found the terms "narrower" and "wider" to seem ambiguous. I'm assuming "narrower" to mean that an integer has a more precise value and "wider" to mean that a float has a less precise/wider range of possible values, but unless I'm missing something, it isn't clear. I think the first paragraph should be revised to make the meaning more explicit. Happy to assist (with some input), if applicable.
My report was really just about the last sentence, but I agree that the "narrower" language is confusing here. If someone says that a type "A" is narrower than type "B", that suggests to my ears that "A" represents a subset of the values of "B" (but conversely, that "B" can represent everything "A" can). That applies to the float/complex pair, or to Python 2's int/long, or to NumPy's float32/float64 or int32/int64, but not really to int/float, since int has many values that can't be represented as a float (and even has larger range than float).
I suspect that the wording may have made a bit (but only a bit) more sense in Python 2, where long was still in the mix, and int was the fixed-width type, which really would have been a subset of float on a typical 32-bit machine.
So yes, if we can find a way to ditch the "narrower" language altogether but still convey that idea of implicit conversions from int to float, and from float to complex, that would be good.
And then the last sentence still needs fixing somehow.