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

Stefan Krah stefan at bytereef.org
Fri Sep 19 11:16:15 CEST 2014


Case Van Horsen <casevh at gmail.com> wrote:
> > I don't think there is any dispute over what math.floor(inf) should return.
> > POSIX, C99, IEEE and probably many other standards agree that inf should be
> > returned as long as the resulting type can represent it.
> 
> I dispute that there is no dispute over what math.floot(inf) should return. ;-)
> 
> All the standards specify a result type can represent +-Inf and +-0. A
> standards compliant version should return +-Inf and +-0.  lrint() and llrint()
> are defined to return long or long long, respectively. It would be fine if
> they raised an exception. The current math.floor() actually behaves more
> like llrint() than floor().

I've always found the behavior of math.floor() a bit surprising, especially
since most functions in the module are thin wrappers around the C functions
from math.h.

>>> math.modf(float("inf"))
(0.0, inf)


So (if we can change it) I'd prefer that floor() behaves according to the
C standard.


Stefan Krah




More information about the Python-ideas mailing list