[Python-Dev] Deprecating float.is_integer()

Tim Peters tim.peters at gmail.com
Wed Mar 21 21:30:18 EDT 2018


[Devin Jeanpierre <jeanpierreda at gmail.com>]
> PyPy (5.8):
> >>>> x = 1e300
> >>>> x.is_integer()
> True
> >>>> math.sqrt(x**2).is_integer()
> False
> >>>> x**2
> inf

I think you missed that David said "even without reaching inf" (you
did reach inf), and that I said "such that x*x neither overflows nor
underflows".  Those are technical words related to IEEE-754:  your x*x
sets the IEEE overflow flag, although CPython may or may not raise the
Python OverflowError exception.

>
> (It gives an OverflowError on my CPython installs.)
>
> I believe this is allowed, and Python is not required to raise
> OverflowError here:
> https://docs.python.org/3.6/library/exceptions.html#OverflowError
> says:
>
>> for historical reasons, OverflowError is sometimes raised for integers that are outside a required range. Because of the lack of standardization of floating point exception handling in C, most floating point operations are not checked

You can avoid the OverflowError (but not the IEEE overflow condition!)
under CPython by multiplying instead:

>>> x = 1e300
>>> x*x
inf


More information about the Python-Dev mailing list