Message32660
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." |
|
Date |
User |
Action |
Args |
2007-08-23 14:59:16 | admin | link | issue1777160 messages |
2007-08-23 14:59:16 | admin | create | |
|