Mathematics in Python are not correct
Michael Torrie
torriem at gmail.com
Thu May 8 19:04:26 EDT 2008
wxPythoner at gmail.com wrote:
> 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).
No python is correct. you're expression parses this way, when converted
to a lisp-ish prefix expression:
(- (123 ** 0 ))
All calculators work this way, so I don't know why you are expecting
anything otherwise.
>
> The problem is that Python parses -123**0 as -(123**0), not as
> (-123)**0.
>
> 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.
>
> This is a rare case when the parser is fooled, but it must be fixed in
> order to produce the correct mathematical result.
> --
> http://mail.python.org/mailman/listinfo/python-list
More information about the Python-list
mailing list