![]() |
Available news archives:
comp.lang.tcl
-
comp.lang.python
-
comp.security.firewalls
-
sci.crypt -
comp.lang.php -
comp.lang.javascript
|
|
comp.lang.python archiveRe: "pow" (power) function
From: Ben Cartwright <bencvt@gmail.com>
Date: Thu Mar 16 2006 - 01:51:39 CET
Russ wrote:
Sure, but the answers depend on the underlying Python implementation.
> Does "pow(x,2)" simply square x, or does it first compute logarithms
The former, using binary exponentiation (quite fast), assuming x is an
If x is a float, Python coerces the 2 to 2.0, and CPython's float_pow()
> Does "x**0.5" use the same algorithm as "sqrt(x)", or does it use some
The latter, and that algorithm is libm's pow(). Except for a few
If you're curious, download the Python source, open up
The 0.5 special check (and any other special case optimizations) could,
Hope that helps,
|