Power operator, why does -2**3 throws?
Tom Mitchell
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
positive
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
also comment...
Wikipedia seems to have it discussed well:
"The minus sign (*−*) has three main uses in mathematics:[11]
<https://en.wikipedia.org/wiki/Plus_and_minus_signs#cite_note-11>
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
negative 5.
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."
https://en.wikipedia.org/wiki/Plus_and_minus_signs#Minus_sign
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...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20161024/8d2c1c8d/attachment.html>
More information about the es-discuss
mailing list