|
@@ -38,6 +38,7 @@ MathObject::MathObject()
|
|
|
put_native_function("random", random);
|
|
|
put_native_function("sqrt", sqrt, 1);
|
|
|
put_native_function("floor", floor, 1);
|
|
|
+ put_native_function("round", round, 1);
|
|
|
|
|
|
put("E", Value(M_E));
|
|
|
put("LN2", Value(M_LN2));
|
|
@@ -96,4 +97,16 @@ Value MathObject::floor(Interpreter& interpreter)
|
|
|
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()));
|
|
|
+}
|
|
|
+
|
|
|
}
|