2011-08-21 14 views
5

अजगर प्रलेखनअतिप्रवाह वास्तव में उठाया गया है?

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. 

दरअसल के अनुसार, इस त्रुटि जब पूर्णांकों बह निकला स्वचालित रूप से लंबे समय के लिए परिवर्तित नहीं कर रहे थे समझ में बनाया है। इसी तरह, inf पर अतिप्रवाह तैरता है। मुझे वास्तव में कोई ऐसी स्थिति दिखाई नहीं देती है जहां मानक दुभाषिया अभी भी ओवरफ्लो इरर बढ़ा सकता है। क्या ऐसा कोई मामला है? बस एक जिज्ञासा।

उत्तर

7
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 

(मुझे लगता है कि मैं एक टिप्पणी जो गायब हो गया है में पहली एक देखा था, इसलिए मैं जो क्रेडिट करने के लिए यकीन नहीं है) इसके बारे में सोचने के लिए आओ:

>>> 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 

इन के सभी कर रहे हैं एक्स-टू-इंट-पावर या इंट-टू-फ्लोट (या जटिल काम भी) टाइप करें।

और - क्योंकि यह संबंधित प्रश्नों में दाईं ओर दिखाई देता है! - नहीं है:

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

एक अलग तरह का है।

+0

ठीक है, दिलचस्प है। मुझे उम्मीद है कि इसे "inf" में परिवर्तित किया जाएगा। >>> एक = 1e1000 >>> inf' –

संबंधित मुद्दे