Mathematics in Python are not correct

Mark Dickinson dickinsm at gmail.com
Mon May 12 10:21:51 EDT 2008


On May 12, 2:09 am, "Terry Reedy" <tjre... at udel.edu> wrote:
> Then it seems equally dubious that 0.**y, y>0, should be well-defined.
> It seems to me that lim as x goes to 0. exp(y*log(x)) is equally well
> defined whether y is 0 or not, even though there is a discontinuity in the
> limit.

Well, there's a difference:  the limit of exp(y*log(x)) as (x, y) ->
(0, a) exists for all finite nonzero a.  The limit as (x, y) ->
(0, 0) doesn't.

> 2.5 raises an exception.  In 3.0,>>> (-2)**1.99999999
>
> (3.9999999722741113-1.2566370355167477e-07j)

Interesting---I hadn't realised that 3.0 had changed this.
I can't quite decide whether I like this behaviour much.  It
seems to be the only case where a computation involving only
floats can produce a complex number.

>
> | Incidentally, the decimal module is slightly schizophrenic about this:
>
> That module follows the IBM-led standard, no matter how crazy.

Yeah---I know. :-).  The current decimal __pow__ code is mostly
my fault, at least in 2.5.2/2.6/3.0 onwards.  For what it's
worth, the author of the Decimal standard has indicated that
the behaviour of 0**0 might change after IEEE 754r finally
sees the light of day.

Mark



More information about the Python-list mailing list