|
@@ -38,8 +38,10 @@ MathObject::MathObject()
|
|
|
put_native_function("random", random);
|
|
|
put_native_function("sqrt", sqrt, 1);
|
|
|
put_native_function("floor", floor, 1);
|
|
|
+ put_native_function("ceil", ceil, 1);
|
|
|
put_native_function("round", round, 1);
|
|
|
put_native_function("max", max, 2);
|
|
|
+ put_native_function("trunc", trunc, 1);
|
|
|
|
|
|
put("E", Value(M_E));
|
|
|
put("LN2", Value(M_LN2));
|
|
@@ -98,6 +100,17 @@ Value MathObject::floor(Interpreter& interpreter)
|
|
|
return Value(::floor(number.as_double()));
|
|
|
}
|
|
|
|
|
|
+Value MathObject::ceil(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(::ceil(number.as_double()));
|
|
|
+}
|
|
|
+
|
|
|
Value MathObject::round(Interpreter& interpreter)
|
|
|
{
|
|
|
if (!interpreter.argument_count())
|
|
@@ -127,4 +140,18 @@ Value MathObject::max(Interpreter& interpreter)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+Value MathObject::trunc(Interpreter& interpreter)
|
|
|
+{
|
|
|
+ if (!interpreter.argument_count())
|
|
|
+ return js_nan();
|
|
|
+
|
|
|
+ auto number = interpreter.argument(0).to_number();
|
|
|
+ if (number.is_nan())
|
|
|
+ return js_nan();
|
|
|
+
|
|
|
+ if (number.as_double() < 0)
|
|
|
+ return MathObject::ceil(interpreter);
|
|
|
+ return MathObject::floor(interpreter);
|
|
|
+}
|
|
|
+
|
|
|
}
|