mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 04:25:13 +00:00
LibJS: Add Number constants
This commit is contained in:
parent
f85aa8462f
commit
b7032b4972
Notes:
sideshowbarker
2024-07-19 07:49:25 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/b7032b49724 Pull-request: https://github.com/SerenityOS/serenity/pull/1687
2 changed files with 22 additions and 0 deletions
|
@ -28,6 +28,7 @@
|
|||
#include <LibJS/Runtime/Error.h>
|
||||
#include <LibJS/Runtime/NumberConstructor.h>
|
||||
#include <LibJS/Runtime/NumberObject.h>
|
||||
#include <math.h>
|
||||
|
||||
namespace JS {
|
||||
|
||||
|
@ -35,6 +36,12 @@ NumberConstructor::NumberConstructor()
|
|||
{
|
||||
put("prototype", interpreter().number_prototype());
|
||||
put("length", Value(1));
|
||||
put("EPSILON", Value(pow(2, -52)));
|
||||
put("MAX_SAFE_INTEGER", Value(pow(2, 53) - 1));
|
||||
put("MIN_SAFE_INTEGER", Value(-(pow(2, 53) - 1)));
|
||||
put("NEGATIVE_INFINITY", Value(-js_infinity().as_double()));
|
||||
put("POSITIVE_INFINITY", js_infinity());
|
||||
put("NaN", js_nan());
|
||||
}
|
||||
|
||||
NumberConstructor::~NumberConstructor()
|
||||
|
|
15
Libraries/LibJS/Tests/Number-constants.js
Normal file
15
Libraries/LibJS/Tests/Number-constants.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
try {
|
||||
assert(Number.EPSILON === 2 ** -52);
|
||||
assert(Number.EPSILON > 0);
|
||||
assert(Number.MAX_SAFE_INTEGER === 2 ** 53 - 1);
|
||||
assert(Number.MAX_SAFE_INTEGER + 1 === Number.MAX_SAFE_INTEGER + 2);
|
||||
assert(Number.MIN_SAFE_INTEGER === -(2 ** 53 - 1));
|
||||
assert(Number.MIN_SAFE_INTEGER - 1 === Number.MIN_SAFE_INTEGER - 2);
|
||||
assert(Number.POSITIVE_INFINITY === Infinity);
|
||||
assert(Number.NEGATIVE_INFINITY === -Infinity);
|
||||
assert(isNaN(Number.NaN));
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
Loading…
Add table
Reference in a new issue