mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:37:35 +00:00
LibJS: Add support for Math.ceil() and Math.trunc()
Introduce support for the both of these Math methods. Math.trunc is implemented in terms of Math.ceil or Math.floor based on the input value. Added tests as well.
This commit is contained in:
parent
4ea71c9571
commit
240a5b5fd7
4 changed files with 66 additions and 0 deletions
18
Libraries/LibJS/Tests/Math.trunc.js
Normal file
18
Libraries/LibJS/Tests/Math.trunc.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
function assert(x) { if (!x) throw 1; }
|
||||
|
||||
try {
|
||||
assert(Math.trunc(13.37) === 13);
|
||||
assert(Math.trunc(42.84) === 42);
|
||||
assert(Math.trunc(0.123) === 0);
|
||||
assert(Math.trunc(-0.123) === -0);
|
||||
|
||||
assert(isNaN(Math.trunc(NaN)));
|
||||
assert(isNaN(Math.trunc('foo')));
|
||||
assert(isNaN(Math.trunc()));
|
||||
|
||||
assert(Math.trunc.length === 1);
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue