This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author belopolsky
Recipients belopolsky, casevh, pitrou, rhettinger, skrah
Date 2014-09-20.16:01:28
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1411228889.28.0.752055468204.issue22444@psf.upfronthosting.co.za>
In-reply-to
Content
> 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?
History
Date User Action Args
2014-09-20 16:01:29belopolskysetrecipients: + belopolsky, rhettinger, pitrou, casevh, skrah
2014-09-20 16:01:29belopolskysetmessageid: <1411228889.28.0.752055468204.issue22444@psf.upfronthosting.co.za>
2014-09-20 16:01:29belopolskylinkissue22444 messages
2014-09-20 16:01:28belopolskycreate