2**2**2**2**2 wrong? Bug?

Paul McGuire ptmcg at austin.rr.com
Wed Jul 11 15:39:17 EDT 2007


On Jul 11, 12:04 pm, David Jones <david.l.jo... at gmail.com> wrote:
> > In fact, if I put (2**2)**2**2**2
> > it comes up with the correct answer, 4294967296
>
> Actually, the "correct" answer (even by your own demonstration) is
> 65536.

It might be easier to demonstrate if we chose a less homogeneous
problem: 2**3**2.  A right (rightly?) associative language (such as
Python) reads this as 2**(3**2), or 2**9=512.  A left-associative
language (such as VB) reads this as (2**3)**2 or 8**2=64.  As was
pointed out earlier, left-associativity with exponentiation is of
little value, since (2**3)**2 is the same as 2**(3*2) or 2**6=64.

-- Paul




More information about the Python-list mailing list