e vs exp()?

Fernando Pérez fperez528 at yahoo.com
Fri Sep 20 18:07:11 EDT 2002


Terry Reedy wrote:

> Perhaps x**int is special-cased.  But following must have a different
> explanation:
> 
>>>> e**2.1
> 8.1661699125676499
>>>> pow(e,2.1)
> 8.1661699125676499
>>>> exp(2.1)
> 8.1661699125676517
> 
> At least two of us expected x**y == pow(x,y) == exp(y*log(x)) (a
> standard method, and the only one I could find in Abrahamowitz and
> Stegun, Handbook of Mathematical Functions) but there must be a more
> direct method being used at least in some C libraries now.

Well, as Tim Peters already mentioned, implementing ** (or pow(), same thing) 
is a hairy problem and _not_ done through exp(log). On the other hand, exp() 
has its own separate implementation, even though it may or may not be as 
efficient as the one Tim mentioned with an error bound of .53 in the last 
digit, and fast to boot.

Incidentally, A&S is a fabulous reference for formulas and value tables. But I 
wouldn't consider it authoritative as a source of optimal numerical 
algorithms by any stretch of the imagination.

Cheers,

f.



More information about the Python-list mailing list