Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.034 X-Spam-Evidence: '*H*': 0.93; '*S*': 0.00; 'interpreter': 0.05; 'raises': 0.09; 'subject:Why': 0.09; 'python': 0.11; '2.7.3': 0.16; '488': 0.16; 'dump': 0.16; 'received:74.208.4.195': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'header:User-Agent:1': 0.23; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; "doesn't": 0.30; '"",': 0.31; '-0700,': 0.31; 'calculated': 0.31; "d'aprano": 0.31; 'sep': 0.31; 'steven': 0.31; 'anyone': 0.31; 'file': 0.32; '(most': 0.33; 'sense': 0.34; 'but': 0.35; 'subject:?': 0.36; 'to:addr:python-list': 0.38; 'recent': 0.39; 'does': 0.39; 'to:addr:python.org': 0.39; 'today,': 0.61; "you're": 0.61; 'more': 0.64; 'here': 0.66; 'mar': 0.68; 'received:74.208': 0.68; '2013': 0.98 Date: Sun, 31 Mar 2013 03:48:02 -0400 From: Dave Angel User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130308 Thunderbird/17.0.4 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Why does 1**2**3**4**5 raise a MemoryError? References: <8e43bc87-e822-4bb3-b9ef-ccd489da8bf3@googlegroups.com> <5157e6cc$0$29974$c3e8da3$5496439d@news.astraweb.com> In-Reply-To: <5157e6cc$0$29974$c3e8da3$5496439d@news.astraweb.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:6JobaOfUMNx9So1eylrgwN58hc0w/crJkSnM1BnAsb5 uCzpSQlaysWnsyy4J9f+wm91plfNM+3rb/7v1BxJMMd+cVmKA8 WnBQ8l0sVU3aOyTm84DA4IeVnG5345J+acakDgRCB3Cptf5Nir tpfLEvpKm4/AvGWPu1MUpD/cL5SeYZRTAaEXUwZwdZZi+yerXJ j0WQzP71Ug8K7U8zAsnuD14Dk2Rw2frRTfANPUSba4vD3gKdQy 10JRF3j79w8rpZyMpHAbnlRtxCDQWLSA8kCnJzv7+u342addGX ZPNJs7SBxY/oEv5SRcnXsFIoZeFTPoZwmyvNTTkvZRd4McFUw= = X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 41 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1364716108 news.xs4all.nl 6906 [2001:888:2000:d::a6]:51275 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:42361 On 03/31/2013 03:33 AM, Steven D'Aprano wrote: > On Sat, 30 Mar 2013 23:56:46 -0700, morphex wrote: > >> Hi. >> >> I was just doodling around with the python interpreter today, and here >> is the dump from the terminal: >> >> morphex@laptop:~$ python >> Python 2.7.3 (default, Sep 26 2012, 21:53:58) [GCC 4.7.2] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. >>>>> 1**2 >> 1 >>>>> 1**2**3 >> 1 >>>>> 1**2**3**4 >> 1L >>>>> 1**2**3**4**5 >> Traceback (most recent call last): >> File "", line 1, in >> MemoryError >>>>> >>>>> >> Does anyone know why this raises a MemoryError? Doesn't make sense to >> me. > > Because exponentiation is right-associative, not left. > > 1**2**3**4**5 is calculated like this: > > 1**2**3**4**5 > => 1**2**3**1024 > => 1**2**373...481 # 489-digit number Oops, you're right, it's 489. I figured 488 but was wrong. -- DaveA