Exponentiation operator precedence
Bergi
a.d.bergi at web.de
Wed Aug 26 22:14:39 UTC 2015
Alexander Jones schrieb:
> Exponentiation is written in conventional mathematics as if it were a
> postfix unary operator, parameterised by a value written in superscript.
> IMO this puts it in a whole different class to binary operators where both
> operands are written equally. I don't see a ** b ** c as a good reflection
> of mathematical convention.
I disagree. When in maths we write x <sup> y <sup> z </sup></sup>, we
mean x ^ (y ^ z). Which is exactly what `x ** y ** z` will do.
And no, we never write x <sup>y</sup> <sup>z</sup>, if we wanted to
express that we'd write x <sup>y * z</sup> (or often enough, with
implicit multiplication, i.e. no * operator: x <sup>y z</sup>).
If we'd want to express that in JS, it would by x ** (y * z).
> Number.prototype.pow, on the other hand, would be fine.
You don't mean to use it like `x.pow(y).pow(z)`, do you? Sure, a
function or method invocation is always explicit with parenthesis. But
that's no improvement over the current `Math.pow`.
Bergi
More information about the es-discuss
mailing list