}
+static njs_ret_t
+njs_object_math_trunc(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
+ njs_index_t unused)
+{
+ double num;
+
+ if (nargs > 1) {
+ num = args[1].data.u.number;
+
+ } else {
+ num = NJS_NAN;
+ }
+
+ njs_number_set(&vm->retval, trunc(num));
+
+ return NXT_OK;
+}
+
+
static const njs_object_prop_t njs_math_object_properties[] =
{
{
.value = njs_native_function(njs_object_math_tan, 0,
NJS_SKIP_ARG, NJS_NUMBER_ARG),
},
+
+ /* ES6. */
+ {
+ .type = NJS_METHOD,
+ .name = njs_string("trunc"),
+ .value = njs_native_function(njs_object_math_trunc, 0,
+ NJS_SKIP_ARG, NJS_NUMBER_ARG),
+ },
};
{ nxt_string("Math.pow()"),
nxt_string("NaN") },
+ { nxt_string("Math.trunc(3.9)"),
+ nxt_string("3") },
+
+ { nxt_string("Math.trunc(-3.9)"),
+ nxt_string("-3") },
+
+ { nxt_string("Math.trunc(0)"),
+ nxt_string("0") },
+
+ { nxt_string("Math.trunc(-0)"),
+ nxt_string("-0") },
+
+ { nxt_string("Math.trunc(0.9)"),
+ nxt_string("0") },
+
+ { nxt_string("Math.trunc(-0.9)"),
+ nxt_string("-0") },
+
+ { nxt_string("Math.trunc(Infinity)"),
+ nxt_string("Infinity") },
+
+ { nxt_string("Math.trunc(-Infinity)"),
+ nxt_string("-Infinity") },
+
+ { nxt_string("Math.trunc(NaN)"),
+ nxt_string("NaN") },
+
+ { nxt_string("Math.trunc()"),
+ nxt_string("NaN") },
+
/* ES5FIX: "[object Math]". */
{ nxt_string("Math"),