Power operator, why does -2**3 throws?
mitch at niftyegg.com
Tue Oct 25 00:33:12 UTC 2016
This "should" be correct in the context of correct mathematics.
Expectations and correctness must bias toward correctness.
Math/Algebra has been one of the weak points of the web so it makes sense to
toss an error and demand the programmer make his intention clear.
It also helps with testing to have the programmer add clarity. Still both
and negative values of x need testing. Some folk generate code with
programs and scripts
emitting strings and would likely see value in the error to avoid odd
things. They should
Wikipedia seems to have it discussed well:
"The minus sign (*−*) has three main uses in mathematics:
1. The subtraction <https://en.wikipedia.org/wiki/Subtraction> operator:
A binary operator <https://en.wikipedia.org/wiki/Binary_operator> to
indicate the operation of subtraction, as in 5 − 3 = 2. Subtraction is the
inverse of addition.
2. Directly in front of
<https://en.wikipedia.org/wiki/Sign_(mathematics)> a number and when it
is not a subtraction operator it means a negative number
<https://en.wikipedia.org/wiki/Negative_number>. For instance −5 is
3. A unary operator <https://en.wikipedia.org/wiki/Unary_operator> that
acts as an instruction to replace the operand by its additive inverse
<https://en.wikipedia.org/wiki/Additive_inverse>. For example, if *x* is
3, then −*x* is −3, but if *x* is −3, then −*x* is 3. Similarly, −(−2)
is equal to 2. The above is a special case of this."
On Tue, Oct 18, 2016 at 1:59 AM, Jordan Harband <ljharb at gmail.com> wrote:
> It's quite simple (as has already been stated): some people expect `-x **
> y` to be `-(x ** y)`. Some expect it to be `(-x) ** y`.
> The early SyntaxError ensures that nobody is confused - programmers will
> immediately add parens to disambiguate.
T o m M i t c h e l l
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss