[Python-Dev] Deprecating float.is_integer() (original) (raw)
Tim Peters tim.peters at gmail.com
Wed Mar 21 21:30:18 EDT 2018
- Previous message (by thread): [Python-Dev] Deprecating float.is_integer()
- Next message (by thread): [Python-Dev] Deprecating float.is_integer()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
[Devin Jeanpierre <jeanpierreda at gmail.com>]
PyPy (5.8): >>>> x = 1e300 >>>> x.isinteger() True >>>> math.sqrt(x**2).isinteger() 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 xx neither overflows nor underflows". Those are technical words related to IEEE-754: your xx 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
- Previous message (by thread): [Python-Dev] Deprecating float.is_integer()
- Next message (by thread): [Python-Dev] Deprecating float.is_integer()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]