| 1 |
// Copyright (C) 2016 Rick Waldron. All rights reserved. |
| 2 |
// This code is governed by the BSD license found in the LICENSE file. |
| 3 |
|
| 4 |
/*--- |
| 5 |
author: Rick Waldron |
| 6 |
esid: sec-update-expressions |
| 7 |
description: Exponentiation Operator expression precedence of update operators |
| 8 |
info: | |
| 9 |
ExponentiationExpression : |
| 10 |
... |
| 11 |
UpdateExpression `**` ExponentiationExpression |
| 12 |
|
| 13 |
UpdateExpression : |
| 14 |
LeftHandSideExpression `++` |
| 15 |
LeftHandSideExpression `--` |
| 16 |
`++` UnaryExpression |
| 17 |
`--` UnaryExpression |
| 18 |
---*/ |
| 19 |
|
| 20 |
var base = 4; |
| 21 |
assert.sameValue(--base ** 2, 9, "(--base ** 2) === 9"); |
| 22 |
assert.sameValue(++base ** 2, 16, "(++base ** 2) === 16"); |
| 23 |
assert.sameValue(base++ ** 2, 16, "(base++ ** 2) === 16"); |
| 24 |
assert.sameValue(base-- ** 2, 25, "(base-- ** 2) === 25"); |
| 25 |
|
| 26 |
base = 4; |
| 27 |
|
| 28 |
// --base ** --base ** 2 -> 3 ** 2 ** 2 -> 3 ** (2 ** 2) -> 81 |
| 29 |
assert.sameValue( |
| 30 |
--base ** --base ** 2, |
| 31 |
Math.pow(3, Math.pow(2, 2)), |
| 32 |
"(--base ** --base ** 2) === Math.pow(3, Math.pow(2, 2))" |
| 33 |
); |
| 34 |
|
| 35 |
// ++base ** ++base ** 2 -> 3 ** 4 ** 2 -> 3 ** (4 ** 2) -> 43046721 |
| 36 |
assert.sameValue( |
| 37 |
++base ** ++base ** 2, |
| 38 |
Math.pow(3, Math.pow(4, 2)), |
| 39 |
"(++base ** ++base ** 2) === Math.pow(3, Math.pow(4, 2))" |
| 40 |
); |
| 41 |
|
| 42 |
base = 4; |
| 43 |
|
| 44 |
// base-- ** base-- ** 2 -> 4 ** 3 ** 2 -> 4 ** (3 ** 2) -> 262144 |
| 45 |
assert.sameValue( |
| 46 |
base-- ** base-- ** 2, |
| 47 |
Math.pow(4, Math.pow(3, 2)), |
| 48 |
"(base-- ** base-- ** 2) === Math.pow(4, Math.pow(3, 2))" |
| 49 |
); |
| 50 |
|
| 51 |
// base++ ** base++ ** 2 -> 2 ** 3 ** 2 -> 2 ** (3 ** 2) -> 262144 |
| 52 |
assert.sameValue( |
| 53 |
base++ ** base++ ** 2, |
| 54 |
Math.pow(2, Math.pow(3, 2)), |
| 55 |
"(base++ ** base++ ** 2) === Math.pow(2, Math.pow(3, 2))" |
| 56 |
); |
| 57 |
|