Is an OverflowError raised?

According to python documentation

exception OverflowError
    Raised when the result of an arithmetic operation is too large to 
    be represented. This cannot occur for long integers (which would 
    rather raise MemoryError than give up) and for most operations with
    plain integers, which return a long integer instead. Because of the 
    lack of standardization of floating point exception handling in C, 
    most floating point operations also aren’t checked.

Indeed, this error made sense when overflowing integers were not automatically converted to long. Similarly, a float overflows to inf. I really don't see a situation where the standard interpreter can still raise an OverflowError. Is there such a case somewhere? Just curiosity.

+5
source share
1 answer
Python 2.7.2 (v2.7.2:8527427914a2, Jun 11 2011, 15:22:34) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> float(10**1000)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: long int too large to convert to float

Think about it (I think I saw the first one in the comment that disappeared, so I'm not sure who the loan is for):

>>> 10.0**1000
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: (34, 'Result too large')
>>> 10j**1000
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: complex exponentiation

These are all types of x-to-int-power or int-to-float (or complex work).

And - because he appeared on the right in related matters! - there is:

>>> xrange(10**100)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: Python int too large to convert to C long

which has a different look.

+7

All Articles