Debian Codegraph @

js/src/tests/test262/language/expressions/exponentiation/exp-operator-precedence-update-expression-semantics.js

raw
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 features: [exponentiation]
19 ---*/
20
21 var base = 4;
22 assert.sameValue(--base ** 2, 9, "(--base ** 2) === 9");
23 assert.sameValue(++base ** 2, 16, "(++base ** 2) === 16");
24 assert.sameValue(base++ ** 2, 16, "(base++ ** 2) === 16");
25 assert.sameValue(base-- ** 2, 25, "(base-- ** 2) === 25");
26
27 base = 4;
28
29 // --base ** --base ** 2 -> 3 ** 2 ** 2 -> 3 ** (2 ** 2) -> 81
30 assert.sameValue(
31 --base ** --base ** 2,
32 Math.pow(3, Math.pow(2, 2)),
33 "(--base ** --base ** 2) === Math.pow(3, Math.pow(2, 2))"
34 );
35
36 // ++base ** ++base ** 2 -> 3 ** 4 ** 2 -> 3 ** (4 ** 2) -> 43046721
37 assert.sameValue(
38 ++base ** ++base ** 2,
39 Math.pow(3, Math.pow(4, 2)),
40 "(++base ** ++base ** 2) === Math.pow(3, Math.pow(4, 2))"
41 );
42
43 base = 4;
44
45 // base-- ** base-- ** 2 -> 4 ** 3 ** 2 -> 4 ** (3 ** 2) -> 262144
46 assert.sameValue(
47 base-- ** base-- ** 2,
48 Math.pow(4, Math.pow(3, 2)),
49 "(base-- ** base-- ** 2) === Math.pow(4, Math.pow(3, 2))"
50 );
51
52 // base++ ** base++ ** 2 -> 2 ** 3 ** 2 -> 2 ** (3 ** 2) -> 262144
53 assert.sameValue(
54 base++ ** base++ ** 2,
55 Math.pow(2, Math.pow(3, 2)),
56 "(base++ ** base++ ** 2) === Math.pow(2, Math.pow(3, 2))"
57 );
58
59
60 reportCompare(0, 0);