# Power operator, why does -2**3 throws?

Cyril Auburtin cyril.auburtin at gmail.com
Fri Oct 14 12:33:04 UTC 2016

```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 forbidden `2**2**3` too
because it's not obvious it's right associative

But ok, thanks for the explanation.

2016-10-14 14:05 GMT+02:00 Bergi <a.d.bergi at web.de>:

> 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 been decided to make it a syntax error if
> the two operators are used together. If you want `-(2**3)`, you have to
> write it like that, and if you want `(-2)**3` you have to write it
> explicitly as well.
> See https://esdiscuss.org/topic/exponentiation-operator-precedence for
> the full discussion.
>
> - Bergi
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20161014/03ce8596/attachment.html>
```