Alexander Belopolsky added the comment:

> Is this change compelling enough to break compatibility,
> or is it just a matter of purity?

According to the PEP 3141, Integer is a subtype of Real, so one should be able 
to substitute an Integer whenever Real is expected.  The reverse is not true, 
for example

>>> [1,2][1.0]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: list indices must be integers, not float

This is one of the common uses of floor division - to find an index of a cell 
in a regular grid: (x - start) // step.  In this situation, it is convenient to 
have the result ready to be used as an index without a cast.

The substitution principle also suggests that compatibility issues are likely 
to be small: in most contexts integers behave the same as floats or "better".

Here is an example of a "better" behavior:

>>> x = 1 + 10**50
>>> x * 1 == x
True
>>> x * 1.0 == x
False

The only case I can think of where float result may be preferable is inf // 1 
because integers cannot represent infinity.  However, this case is arguably 
already broken.

What are the use-cases for float // float where integer result is not 
acceptable?

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue22444>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to