e vs exp()?
tjreedy at udel.edu
Fri Sep 20 23:56:53 CEST 2002
"Fernando Pérez" <fperez528 at yahoo.com> wrote in message
news:amflhl$3eb$1 at peabody.colorado.edu...
> Buckshot wrote:
> > Can anyone here explain why I'm getting different results from
> > e**2 and exp(2)? Which is more accurate?
> > Python 2.2 (#1, Mar 27 2002, 14:56:58)
> > [GCC 2.95.3 20010315 (release)] on sunos5
> > Type "help", "copyright", "credits" or "license" for more
> >>>> from math import *
> >>>> e**2
> > 7.3890560989306522
> >>>> exp(2)
> > 7.3890560989306504
> As someone already told you, exp(2) gives a more accurate answer.
> is, I think, the following: e**2 simply squares e,
Thanks. That seems to solve the particular problem posed:
Perhaps x**int is special-cased. But following must have a different
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.
Terry J. Reedy
More information about the Python-list