mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:48:11 +00:00
LibJS: Implement exponentiation (** operator)
This commit is contained in:
parent
eafd3dbaf8
commit
0403845d3e
7 changed files with 48 additions and 1 deletions
30
Libraries/LibJS/Tests/exponentiation-basic.js
Normal file
30
Libraries/LibJS/Tests/exponentiation-basic.js
Normal file
|
@ -0,0 +1,30 @@
|
|||
function assert(x) { if (!x) throw 1; }
|
||||
|
||||
try {
|
||||
assert(2 ** 0 === 1);
|
||||
assert(2 ** 1 === 2);
|
||||
assert(2 ** 2 === 4);
|
||||
assert(2 ** 3 === 8);
|
||||
assert(2 ** -3 === 0.125);
|
||||
assert(3 ** 2 === 9);
|
||||
assert(0 ** 0 === 1);
|
||||
assert(2 ** 3 ** 2 === 512);
|
||||
assert(2 ** (3 ** 2) === 512);
|
||||
assert((2 ** 3) ** 2 === 64);
|
||||
assert("2" ** "3" === 8);
|
||||
assert("" ** [] === 1);
|
||||
assert([] ** null === 1);
|
||||
assert(null ** null === 1);
|
||||
assert(undefined ** null === 1);
|
||||
assert(isNaN(NaN ** 2));
|
||||
assert(isNaN(2 ** NaN));
|
||||
assert(isNaN(undefined ** 2));
|
||||
assert(isNaN(2 ** undefined));
|
||||
assert(isNaN(null ** undefined));
|
||||
assert(isNaN(2 ** "foo"));
|
||||
assert(isNaN("foo" ** 2));
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue