2**HUGENUMBER Why not optimise it?

Mike C. Fletcher mcfletch at rogers.com
Wed May 22 14:02:07 EDT 2002


I've noticed the use of 2**HUGENUMBER as a speed test a couple of times 
now.  I'm curious why the language(s) doesn't (don't) optimise 2**X 
operations for really huge exponents.  Python obviously optimises 1**x 
(since 1**1000000 returns instantly), so why not 2**x where x > (30 or 62)?

i.e.  return 1L<<exponent

I'm guessing the reason is "no one really uses this much, so there's not 
much point putting the effort into the change", but I'm still curious if 
I'm missing something about 2-exponentiation.

Given that the test was stated as an English word problem, the 1L<<10000 
solution would probably even be acceptable in the speed tests.  We just 
need to restate the problem as:

     "What is the integer/long value of 2 raised to the power of 10000000?"

And Python will be universally acknowledged as the speediest language on 
the planet ;) .
Mike


In another thread Jeremy Yallop wrote:
> * George Demmy
> | "Python" is *much* "faster" than "Perl", "php", or "C" at answering
> | this question:
> | 
> | What is the integer value of 2 raised to the power of 10000?
...
_______________________________________
   Mike C. Fletcher
   http://members.rogers.com/mcfletch/







More information about the Python-list mailing list