This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author gpk
Recipients
Date 2007-08-19.10:25:07
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
In python, -1**2 is -1.    This will horribly surprise
most mathematicians or C programmers where
unary - binds very tightly.   Such people will expect
-1**2 == 1.

This problem shows up in scientific contexts, especially
Numpy, where an easy way to generate an alternating
string of positive and negative numbers is
-1**numpy.arange(10).  In this example, one expects to produce [1, -1, 1, -1, ...].

So, please put a note in the documentation warning of this problem.  It can lead to subtly wrong computations.

The appropriate place to put the note is in the Python Reference Manual, section 5.4, The Power operator.

Please insert a final line saying:
"Note: since the minus sign is not part of a numeric literal,
powers of negative numeric constants need to be
written with parentheses. Be aware that -1**2 == -(1**2), not (-1)**2."
History
Date User Action Args
2007-08-23 14:59:16adminlinkissue1777160 messages
2007-08-23 14:59:16admincreate