Mathematics in Python are not correct

Ben Finney bignose+hates-spam at benfinney.id.au
Thu May 8 19:34:38 EDT 2008


wxPythoner at gmail.com writes:

> The problem is that Python parses -123**0 as -(123**0), not as
> (-123)**0.

As explicitly defined in the language reference, the "negative"
operator has lower binding precedence than the "power" operator
<URL:http://www.python.org/doc/ref/summary.html>.

> I suggest making the Python parser omit the negative sign if a
> negative number is raised to the power of 0.

It does, if you actually have a negative number that you're raising to
power 0.

    >>> (-123)**0
    1

> This is a rare case when the parser is fooled

The parser is operating according to the documented language
specification. It can't account for the user being fooled by external
sources.

-- 
 \     "You know what I hate? Indian givers... no, I take that back."  |
  `\                                                    -- Emo Philips |
_o__)                                                                  |
Ben Finney



More information about the Python-list mailing list