mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-19 15:32:31 +00:00
LibJS: Add Math.round()
This commit is contained in:
parent
afff228308
commit
16bd99aa52
Notes:
sideshowbarker
2024-07-19 07:55:13 +09:00
Author: https://github.com/awesomekling
Commit: 16bd99aa52
2 changed files with 14 additions and 0 deletions
|
@ -38,6 +38,7 @@ MathObject::MathObject()
|
||||||
put_native_function("random", random);
|
put_native_function("random", random);
|
||||||
put_native_function("sqrt", sqrt, 1);
|
put_native_function("sqrt", sqrt, 1);
|
||||||
put_native_function("floor", floor, 1);
|
put_native_function("floor", floor, 1);
|
||||||
|
put_native_function("round", round, 1);
|
||||||
|
|
||||||
put("E", Value(M_E));
|
put("E", Value(M_E));
|
||||||
put("LN2", Value(M_LN2));
|
put("LN2", Value(M_LN2));
|
||||||
|
@ -96,4 +97,16 @@ Value MathObject::floor(Interpreter& interpreter)
|
||||||
return Value(::floor(number.as_double()));
|
return Value(::floor(number.as_double()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Value MathObject::round(Interpreter& interpreter)
|
||||||
|
{
|
||||||
|
if (!interpreter.argument_count())
|
||||||
|
return js_nan();
|
||||||
|
|
||||||
|
auto number = interpreter.argument(0).to_number();
|
||||||
|
if (number.is_nan())
|
||||||
|
return js_nan();
|
||||||
|
// FIXME: Use ::round() instead of ::roundf().
|
||||||
|
return Value(::roundf(number.as_double()));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,7 @@ private:
|
||||||
static Value random(Interpreter&);
|
static Value random(Interpreter&);
|
||||||
static Value sqrt(Interpreter&);
|
static Value sqrt(Interpreter&);
|
||||||
static Value floor(Interpreter&);
|
static Value floor(Interpreter&);
|
||||||
|
static Value round(Interpreter&);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue