mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 01:35:08 +02: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:
Notes:
sideshowbarker
2024-07-19 18:29:38 +09:00
Committer: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/c45922c6379
@@ -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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user