Re: "pow" (power) function
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Re: "pow" (power) function

From: Schüle Daniel <uval@rz.uni-karlsruhe.de>
Date: Thu Mar 16 2006 - 02:07:50 CET

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 (perhaps less efficient) algorithm based on logarithms?

you can try and timeit

>>> 111**111
107362012888474225801214565046695501959850723994224804804775911175625076195783347022491226170093634621466103743092986967777786330067310159463303558666910091026017785587295539622142057315437069730229375357546494103400699864397711L
>>> timeit.Timer("pow(111,111)").timeit()
40.888447046279907
>>> timeit.Timer("111**111").timeit()
39.732122898101807
>>> timeit.Timer("111**0.5").timeit()
2.0990891456604004
>>> timeit.Timer("pow(111,0.5)").timeit()
4.1776390075683594
>>> timeit.Timer("111**0.3").timeit()
2.3824679851531982
>>> timeit.Timer("pow(111,0.3)").timeit()
4.2945041656494141

interesting result
seems that ** computates faster
Received on Sun Apr 30 11:58:23 2006