1
Fork 0
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:
Linus Groh 2020-04-05 13:40:00 +01:00 committed by Andreas Kling
parent eafd3dbaf8
commit 0403845d3e
7 changed files with 48 additions and 1 deletions

View 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);
}