[Devin Jeanpierre <jeanpierr...@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
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to