mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 05:58:11 +00:00
LibJS: Add Math.floor()
This commit is contained in:
parent
3c99c27db4
commit
afff228308
2 changed files with 13 additions and 0 deletions
|
@ -37,6 +37,7 @@ MathObject::MathObject()
|
|||
put_native_function("abs", abs, 1);
|
||||
put_native_function("random", random);
|
||||
put_native_function("sqrt", sqrt, 1);
|
||||
put_native_function("floor", floor, 1);
|
||||
|
||||
put("E", Value(M_E));
|
||||
put("LN2", Value(M_LN2));
|
||||
|
@ -84,4 +85,15 @@ Value MathObject::sqrt(Interpreter& interpreter)
|
|||
return Value(::sqrt(number.as_double()));
|
||||
}
|
||||
|
||||
Value MathObject::floor(Interpreter& interpreter)
|
||||
{
|
||||
if (!interpreter.argument_count())
|
||||
return js_nan();
|
||||
|
||||
auto number = interpreter.argument(0).to_number();
|
||||
if (number.is_nan())
|
||||
return js_nan();
|
||||
return Value(::floor(number.as_double()));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue