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