Re: "pow" (power) function

2006-03-17 Thread David M. Cooke
"Russ" <[EMAIL PROTECTED]> writes: > Ben Cartwright wrote: >> Russ wrote: > >> > Does "pow(x,2)" simply square x, or does it first compute logarithms >> > (as would be necessary if the exponent were not an integer)? >> >> >> The former, using binary exponentiation (quite fast), assuming x is an >>

Re: "pow" (power) function

2006-03-17 Thread Paul Rubin
"Russ" <[EMAIL PROTECTED]> writes: > I just did a little time test (which I should have done *before* my > original post!), and 2.0**2 seems to be about twice as fast as > pow(2.0,2). That seems consistent with your claim above...> > I just did another little time test comparing 2.0**0.5 with sqrt

Re: "pow" (power) function

2006-03-16 Thread Terry Reedy
"Mike Ressler" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I have a counterexample. In the original timeit example, 111**111 was > used. When I run that > timeit.Timer("pow(111,111)").timeit() > 10.968398094177246 timeit.Timer("111**111").timeit() > 10.04007887840271 >

Re: "pow" (power) function

2006-03-16 Thread Ben Cartwright
Mike Ressler wrote: > >>> timeit.Timer("pow(111,111)").timeit() > 10.968398094177246 > >>> timeit.Timer("111**111").timeit() > 10.04007887840271 > >>> timeit.Timer("111.**111.").timeit() > 0.36576294898986816 > > The pow and ** on integers take 10 seconds, but the float ** takes only > 0.36 seconds

Re: "pow" (power) function

2006-03-16 Thread Mike Ressler
On Wed, 2006-03-15 at 18:46 -0800, Ben Cartwright wrote: > Anyway, if you want to see the int vs. float issue in action, try this: > > >>> from timeit import Timer > >>> Timer('2**2').timeit() > 0.12681011582321844 > >>> Timer('2.0**2.0').timeit() > 0.6011743438121 > >>> Timer('2.

Re: "pow" (power) function

2006-03-15 Thread Ben Cartwright
Russ wrote: > Ben Cartwright wrote: > > Russ wrote: > > > > Does "pow(x,2)" simply square x, or does it first compute logarithms > > > (as would be necessary if the exponent were not an integer)? > > > > > > The former, using binary exponentiation (quite fast), assuming x is an > > int or long. > >

Re: "pow" (power) function

2006-03-15 Thread Russ
Ben Cartwright wrote: > Russ wrote: > > Does "pow(x,2)" simply square x, or does it first compute logarithms > > (as would be necessary if the exponent were not an integer)? > > > The former, using binary exponentiation (quite fast), assuming x is an > int or long. > > If x is a float, Python coer

Re: "pow" (power) function

2006-03-15 Thread Ben Cartwright
Russ wrote: > I have a couple of questions for the number crunchers out there: Sure, but the answers depend on the underlying Python implementation. And if we're talking CPython, they also depend on the underlying C implementation of libm (i.e., math.h). > Does "pow(x,2)" simply square x, or do

Re: "pow" (power) function

2006-03-15 Thread Paul Rubin
Schüle Daniel <[EMAIL PROTECTED]> writes: > >>> timeit.Timer("111**0.3").timeit() > 2.3824679851531982 > >>> timeit.Timer("pow(111,0.3)").timeit() > 4.2945041656494141 > > interesting result > seems that ** computates faster Maybe "111**0.3" parses faster than pow(111,0.3), if timeit uses eval.

Re: "pow" (power) function

2006-03-15 Thread sam
I not shure which algorithm,but I am assumeing that all Python does,is to call the underlying C pow() function. Sam -- http://mail.python.org/mailman/listinfo/python-list

Re: "pow" (power) function

2006-03-15 Thread Schüle Daniel
Russ wrote: > I have a couple of questions for the number crunchers out there: > > Does "pow(x,2)" simply square x, or does it first compute logarithms > (as would be necessary if the exponent were not an integer)? > > Does "x**0.5" use the same algorithm as "sqrt(x)", or does it use some > other

"pow" (power) function

2006-03-15 Thread Russ
I have a couple of questions for the number crunchers out there: Does "pow(x,2)" simply square x, or does it first compute logarithms (as would be necessary if the exponent were not an integer)? Does "x**0.5" use the same algorithm as "sqrt(x)", or does it use some other (perhaps less efficient)