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 hav
row for similar reason).
>>>>
>>>> Also argument that it's inconsistent with Math.pow(-2, 2), is total miss
>>>> in
>>>> my eyes.
>>>> I believe to most programmers `Math.pow(-2, 2)`, translates to
>>&g
t;> previous
> >>> case where one will throw for similar reason).
> >>>
> >>> Also argument that it's inconsistent with Math.pow(-2, 2), is total
> miss
> >>> in
> >>> my eyes.
> >>> I believe to most programmers `Math.pow(-
in context: http://mozilla.6506.n7.nabble.
>>> com/Power-operator-why-does-2-3-throws-tp359609p359731.html
>>> Sent from the Mozilla - ECMAScript 4 discussion mailing list archive at
>>> Nabble.com.
>>> _______________
>>> es-discuss mailing list
>>
(-2)**(2)`
and not to `-2**2`,
same as `Math.pow(a ? b : c, 2)` intuitively translates to `(a ? b :
c)**(2)` and not to `a ? b : c**2`
--
View this message in context: http://mozilla.6506.n7.nabble.
com/Power-operator-why-does-2-3-throws-tp359609p359731.html
Sent from the Mozilla
me as `Math.pow(a ? b : c, 2)` intuitively translates to `(a ? b :
>> c)**(2)` and not to `a ? b : c**2`
>>
>>
>>
>>
>> --
>> View this message in context: http://mozilla.6506.n7.nabble.
>> com/Power-operator-why-does-2-3-throws-tp359609p
elieve to most programmers `Math.pow(-2, 2)`, translates to `(-2)**(2)`
> and not to `-2**2`,
> same as `Math.pow(a ? b : c, 2)` intuitively translates to `(a ? b :
> c)**(2)` and not to `a ? b : c**2`
>
>
>
>
> --
> View this message in context: http://mozilla.6506.n7.
View this message in context:
http://mozilla.6506.n7.nabble.com/Power-operator-why-does-2-3-throws-tp359609p359731.html
Sent from the Mozilla - ECMAScript 4 discussion mailing list archive at
Nabble.com.
___
es-discuss mailing list
es-discuss@mozilla
If -2 ** 2 returned me -4 in JS I would be confused.
JS is not a math language, it's a programming language. We have basic math
operations on its syntax and that's fine.
> In the same vein, you have `pow(1+1, 2) == 4` but `1+1 ** 2 == 2`,
because the latter is interpreted as `1+(1 ** 2)`.
Where
> Le 14 oct. 2016 à 16:52, Rick Waldron a écrit :
>
> Python is also inconsistent:
>
> >>> pow(-2, 2)
> 4
> >>> -2 ** 2
> -4
> >>>
This is not inconsistency, but that follows from operator precedence rules
(those used in mathematics, not in C).
In the same vein, you have `pow(1+1, 2) == 4`
Here's some more specific notes:
On Fri, Oct 14, 2016 at 7:31 AM Cyril Auburtin
wrote:
> I would expect `-2**3` to return -8, or `-2**2 == -4`, since it should be
> like `-(2**3)`
>
Math.pow(-2, 3) === -8
Math.pow(-2, 2) === 4
To get -4: -Math.pow(-2, 2)
> Firefox gives a clearer error then
On Fri, Oct 14, 2016 at 7:31 AM Cyril Auburtin
wrote:
> I would expect `-2**3` to return -8, or `-2**2 == -4`, since it should be
> like `-(2**3)`
>
This was discussed extensively during the design process and determined
that requiring user code to be explicit about its intention was the only
sa
I was testing something https://caub.github.io/misc/calculator, and I
didn't see how it would be a problem to have the precedence of ** higher
than unaries.
But at least I'm happy something like (2).pow(3) wasn't chosen.
Thanks anyway and sorry for discussing something already frozen in spec
anyw
Ah, ok, a bit sad because all more scientific languages, and python too,
all math books, all will use `-e^3` for meaning `-(e^3)` (^ or **), because
it's just `-exp(3)` or `-pow(E, 3)`
and `(-1)^n` otherwise, when we want to take the signs with.
If you wanted to avoid any confusion you could have
Cyril Auburtin schrieb:
I would expect `-2**3` to return -8, or `-2**2 == -4`, since it should be
like `-(2**3)`
You would, others would not. -2 ** 2 clearly should return 4, shouldn't it?
Is there a reason for this restriction? Python does it `-2**3` fine
Because of the ambiguity it has be
What does it change if it handles floats?
I just checked
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence
unary + is 16, while exponentiation is 15, so the opposite order that I
thought
2016-10-14 13:37 GMT+02:00 J Decker :
> probably because it's
probably because it's floating point native not integer like you'd think,
so -2.0001 ** 3 is hard?
On Fri, Oct 14, 2016 at 4:30 AM, Cyril Auburtin
wrote:
> I would expect `-2**3` to return -8, or `-2**2 == -4`, since it should be
> like `-(2**3)`
>
> Firefox gives a clearer error then Chrome
I would expect `-2**3` to return -8, or `-2**2 == -4`, since it should be
like `-(2**3)`
Firefox gives a clearer error then Chrome with:
> SyntaxError: unparenthesized unary expression can't appear on the
left-hand side of '**'
Is there a reason for this restriction? Python does it `-2**3` fine
_
18 matches
Mail list logo