1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 20:37:35 +00:00

LibJS: Unify exponentiation logic for ** operator and Math.pow

The JS behaviour of exponentiation on two number typed values is
not a simple matter of forwarding to ::pow(double, double). So,
this factors out the Math.pow logic to allow it to be shared with
Value::exp.
This commit is contained in:
Anonymous 2022-02-17 11:52:45 -08:00 committed by Linus Groh
parent c0735b047e
commit c45922c637
3 changed files with 70 additions and 48 deletions

View file

@ -35,3 +35,18 @@ test("exponentiation that produces NaN", () => {
expect(2 ** "foo").toBeNaN();
expect("foo" ** 2).toBeNaN();
});
test("exponentiation with infinities", () => {
expect((-1) ** Infinity).toBeNaN();
expect(0 ** Infinity).toBe(0);
expect(1 ** Infinity).toBeNaN();
expect((-1) ** -Infinity).toBeNaN();
expect(0 ** -Infinity).toBe(Infinity);
expect(1 ** -Infinity).toBeNaN();
expect(Infinity ** -1).toBe(0);
expect(Infinity ** 0).toBe(1);
expect(Infinity ** 1).toBe(Infinity);
expect((-Infinity) ** -1).toBe(-0);
expect((-Infinity) ** 0).toBe(1);
expect((-Infinity) ** 1).toBe(-Infinity);
});