[Python-ideas] Fwd: Make `float('inf') //1 == float('inf')`

Alexander Belopolsky alexander.belopolsky at gmail.com
Thu Sep 18 17:48:43 CEST 2014


On Thu, Sep 18, 2014 at 11:20 AM, Ian Cordasco <graffatcolmingov at gmail.com>
wrote:

> I understand that intuitively float('inf') // 1 being equal to
> infinity is nice, but it is inherently undefined. We don't really have
> the concept of undefined so NaN seems most acceptable.
>

The most acceptable would be to have x // 1 do the same as math.floor(x)
for any float x.  Note that math.floor() behavior changed from 2.x to 3.x:

Python 2.7.7:
>>> math.floor(float('inf'))
inf

Python 3.4.1:
>>> math.floor(float('inf'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: cannot convert float infinity to integer

It looks like float // float case was overlooked when it was decided that
math.floor() should return int.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140918/f41f49b0/attachment-0001.html>


More information about the Python-ideas mailing list