Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #42361

Re: Why does 1**2**3**4**5 raise a MemoryError?

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 <davea@davea.name>
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 <davea@davea.name>
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 <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.4011.1364716108.2939.python-list@python.org> (permalink)
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

Show key headers only | View raw


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 "<stdin>", line 1, in <module>
>> 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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Why does 1**2**3**4**5 raise a MemoryError? morphex <morphex@gmail.com> - 2013-03-30 23:56 -0700
  Re: Why does 1**2**3**4**5 raise a MemoryError? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-31 07:33 +0000
    Re: Why does 1**2**3**4**5 raise a MemoryError? Dave Angel <davea@davea.name> - 2013-03-31 03:48 -0400
    Re: Why does 1**2**3**4**5 raise a MemoryError? morphex <morphex@gmail.com> - 2013-03-31 05:07 -0700
      Re: Why does 1**2**3**4**5 raise a MemoryError? Dave Angel <d@davea.name> - 2013-03-31 08:43 -0400
        Re: Why does 1**2**3**4**5 raise a MemoryError? Roy Smith <roy@panix.com> - 2013-03-31 09:15 -0400
          Re: Why does 1**2**3**4**5 raise a MemoryError? Jason Swails <jason.swails@gmail.com> - 2013-03-31 10:03 -0400
      Re: Why does 1**2**3**4**5 raise a MemoryError? Roy Smith <roy@panix.com> - 2013-03-31 09:04 -0400
      Re: Why does 1**2**3**4**5 raise a MemoryError? Tim Roberts <timr@probo.com> - 2013-04-01 21:45 -0700
        Re: Why does 1**2**3**4**5 raise a MemoryError? Chris Angelico <rosuav@gmail.com> - 2013-04-02 17:16 +1100
        Re: Why does 1**2**3**4**5 raise a MemoryError? Dan Sommers <dan@tombstonezero.net> - 2013-04-02 12:56 +0000
    Re: Why does 1**2**3**4**5 raise a MemoryError? Roy Smith <roy@panix.com> - 2013-03-31 08:59 -0400
  Re: Why does 1**2**3**4**5 raise a MemoryError? Dave Angel <davea@davea.name> - 2013-03-31 03:34 -0400
    Re: Why does 1**2**3**4**5 raise a MemoryError? "Alex" <foo@email.invalid> - 2013-03-31 22:06 +0000
      Re: Why does 1**2**3**4**5 raise a MemoryError? Chris Angelico <rosuav@gmail.com> - 2013-04-01 09:28 +1100
        Re: Why does 1**2**3**4**5 raise a MemoryError? "Alex" <foo@email.invalid> - 2013-04-01 00:39 +0000
          Re: Why does 1**2**3**4**5 raise a MemoryError? Chris Angelico <rosuav@gmail.com> - 2013-04-01 11:58 +1100
          Re: Why does 1**2**3**4**5 raise a MemoryError? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-01 04:16 +0000
            Re: Why does 1**2**3**4**5 raise a MemoryError? Roy Smith <roy@panix.com> - 2013-04-01 07:48 -0400
          Re: Why does 1**2**3**4**5 raise a MemoryError? Nobody <nobody@nowhere.com> - 2013-04-02 08:40 +0100
      Re: Why does 1**2**3**4**5 raise a MemoryError? Chris Angelico <rosuav@gmail.com> - 2013-04-01 09:32 +1100
      Re: Why does 1**2**3**4**5 raise a MemoryError? Dave Angel <davea@davea.name> - 2013-03-31 18:34 -0400

csiph-web