[Numpy-discussion] exponentiation q.
Pauli Virtanen
pav@iki...
Fri Jul 25 15:39:34 CDT 2008
Fri, 25 Jul 2008 16:24:35 -0400, Gideon Simpson wrote:
> How does python (or numpy/scipy) do exponentiation? If I do x**p, where
> p is some positive integer, will it compute x*x*...*x (p times), or will
> it use logarithms?
For floats it will call operating system's pow, which supposedly is
optimized.
For integer powers |n| < 100 of complex numbers it computes the power by
repeated squarings and multiplications using a binary decomposition, and
for larger |n| falls back to using a logarithm.
For integer powers of integers, it also appears to use repeated squarings
and multiplications according to a binary decomposition.
--
Pauli Virtanen
More information about the Numpy-discussion
mailing list