Mathematics in Python are not correct

Nicolas Dandrimont nicolas.dandrimont at gmail.com
Thu May 8 19:10:46 EDT 2008


* wxPythoner at gmail.com <wxPythoner at gmail.com> [2008-05-08 15:54:42 -0700]:

> Have a look at this:
> 
> >>> -123**0
> -1
> 
> 
> The result is not correct, because every number (positive or negative)
> raised to the power of 0 is ALWAYS 1 (a positive number 1 that is).
> 
> The problem is that Python parses -123**0 as -(123**0), not as
> (-123)**0.
> 

And why is this a problem ? It is the "standard" operator precedence 
that -123^0 is -(123^0), isn't it ?

> I suggest making the Python parser omit the negative sign if a
> negative number is raised to the power of 0. That way the result will
> always be a positive 1, which is the mathematically correct result.
> 

That's what it does : 

>>> -123**0
-1
>>> (-123)**0
1

> This is a rare case when the parser is fooled, but it must be fixed in
> order to produce the correct mathematical result.

Again, the mathematical result is correct. -123^0 is -(123^0), not
(-123)^0.

Regards,
-- 
Nicolas Dandrimont

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 196 bytes
Desc: Digital signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20080509/55b4cc14/attachment-0001.sig>


More information about the Python-list mailing list