}
+static njs_ret_t
+njs_object_math_acosh(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
+ njs_index_t unused)
+{
+ double num;
+
+ if (nargs > 1) {
+ num = acosh(args[1].data.u.number);
+
+ } else {
+ num = NAN;
+ }
+
+ njs_number_set(&vm->retval, num);
+
+ return NXT_OK;
+}
+
+
static njs_ret_t
njs_object_math_asin(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
njs_index_t unused)
}
+static njs_ret_t
+njs_object_math_asinh(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
+ njs_index_t unused)
+{
+ double num;
+
+ if (nargs > 1) {
+ num = asinh(args[1].data.u.number);
+
+ } else {
+ num = NAN;
+ }
+
+ njs_number_set(&vm->retval, num);
+
+ return NXT_OK;
+}
+
+
static njs_ret_t
njs_object_math_atan(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
njs_index_t unused)
}
+static njs_ret_t
+njs_object_math_atanh(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
+ njs_index_t unused)
+{
+ double num;
+
+ if (nargs > 1) {
+ num = atanh(args[1].data.u.number);
+
+ } else {
+ num = NAN;
+ }
+
+ njs_number_set(&vm->retval, num);
+
+ return NXT_OK;
+}
+
+
+static njs_ret_t
+njs_object_math_cbrt(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
+ njs_index_t unused)
+{
+ double num;
+
+ if (nargs > 1) {
+ num = cbrt(args[1].data.u.number);
+
+ } else {
+ num = NAN;
+ }
+
+ njs_number_set(&vm->retval, num);
+
+ return NXT_OK;
+}
+
+
static njs_ret_t
njs_object_math_ceil(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
njs_index_t unused)
}
+static njs_ret_t
+njs_object_math_cosh(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
+ njs_index_t unused)
+{
+ double num;
+
+ if (nargs > 1) {
+ num = cosh(args[1].data.u.number);
+
+ } else {
+ num = NAN;
+ }
+
+ njs_number_set(&vm->retval, num);
+
+ return NXT_OK;
+}
+
+
static njs_ret_t
njs_object_math_exp(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
njs_index_t unused)
}
+static njs_ret_t
+njs_object_math_expm1(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
+ njs_index_t unused)
+{
+ double num;
+
+ if (nargs > 1) {
+ num = expm1(args[1].data.u.number);
+
+ } else {
+ num = NAN;
+ }
+
+ njs_number_set(&vm->retval, num);
+
+ return NXT_OK;
+}
+
+
static njs_ret_t
njs_object_math_floor(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
njs_index_t unused)
}
+static njs_ret_t
+njs_object_math_fround(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
+ njs_index_t unused)
+{
+ double num;
+
+ if (nargs > 1) {
+ num = (float) args[1].data.u.number;
+
+ } else {
+ num = NAN;
+ }
+
+ njs_number_set(&vm->retval, num);
+
+ return NXT_OK;
+}
+
+
static njs_ret_t
njs_object_math_hypot(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
njs_index_t unused)
}
+static njs_ret_t
+njs_object_math_log10(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
+ njs_index_t unused)
+{
+ double num;
+
+ if (nargs > 1) {
+ num = log10(args[1].data.u.number);
+
+ } else {
+ num = NAN;
+ }
+
+ njs_number_set(&vm->retval, num);
+
+ return NXT_OK;
+}
+
+
+static njs_ret_t
+njs_object_math_log1p(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
+ njs_index_t unused)
+{
+ double num;
+
+ if (nargs > 1) {
+ num = log1p(args[1].data.u.number);
+
+ } else {
+ num = NAN;
+ }
+
+ njs_number_set(&vm->retval, num);
+
+ return NXT_OK;
+}
+
+
+static njs_ret_t
+njs_object_math_log2(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;
+
+#if (NXT_SOLARIS)
+ /* On Solaris 10 log(-1) returns -Infinity. */
+ if (num < 0) {
+ num = NAN;
+ }
+#endif
+
+ num = log2(num);
+
+ } else {
+ num = NAN;
+ }
+
+ njs_number_set(&vm->retval, num);
+
+ return NXT_OK;
+}
+
+
static njs_ret_t
njs_object_math_max(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
njs_index_t unused)
}
+static njs_ret_t
+njs_object_math_sinh(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
+ njs_index_t unused)
+{
+ double num;
+
+ if (nargs > 1) {
+ num = sinh(args[1].data.u.number);
+
+ } else {
+ num = NAN;
+ }
+
+ njs_number_set(&vm->retval, num);
+
+ return NXT_OK;
+}
+
+
static njs_ret_t
njs_object_math_sqrt(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
njs_index_t unused)
}
+static njs_ret_t
+njs_object_math_tanh(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
+ njs_index_t unused)
+{
+ double num;
+
+ if (nargs > 1) {
+ num = tanh(args[1].data.u.number);
+
+ } else {
+ num = NAN;
+ }
+
+ njs_number_set(&vm->retval, num);
+
+ return NXT_OK;
+}
+
+
static njs_ret_t
njs_object_math_trunc(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
njs_index_t unused)
NJS_SKIP_ARG, NJS_NUMBER_ARG),
},
+ /* ES6. */
+ {
+ .type = NJS_METHOD,
+ .name = njs_string("acosh"),
+ .value = njs_native_function(njs_object_math_acosh, 0,
+ NJS_SKIP_ARG, NJS_NUMBER_ARG),
+ },
+
{
.type = NJS_METHOD,
.name = njs_string("asin"),
NJS_SKIP_ARG, NJS_NUMBER_ARG),
},
+ /* ES6. */
+ {
+ .type = NJS_METHOD,
+ .name = njs_string("asinh"),
+ .value = njs_native_function(njs_object_math_asinh, 0,
+ NJS_SKIP_ARG, NJS_NUMBER_ARG),
+ },
+
{
.type = NJS_METHOD,
.name = njs_string("atan"),
NJS_SKIP_ARG, NJS_NUMBER_ARG, NJS_NUMBER_ARG),
},
+ /* ES6. */
+ {
+ .type = NJS_METHOD,
+ .name = njs_string("atanh"),
+ .value = njs_native_function(njs_object_math_atanh, 0,
+ NJS_SKIP_ARG, NJS_NUMBER_ARG),
+ },
+
+ /* ES6. */
+ {
+ .type = NJS_METHOD,
+ .name = njs_string("cbrt"),
+ .value = njs_native_function(njs_object_math_cbrt, 0,
+ NJS_SKIP_ARG, NJS_NUMBER_ARG),
+ },
+
{
.type = NJS_METHOD,
.name = njs_string("ceil"),
NJS_SKIP_ARG, NJS_NUMBER_ARG),
},
+ /* ES6. */
+ {
+ .type = NJS_METHOD,
+ .name = njs_string("cosh"),
+ .value = njs_native_function(njs_object_math_cosh, 0,
+ NJS_SKIP_ARG, NJS_NUMBER_ARG),
+ },
+
{
.type = NJS_METHOD,
.name = njs_string("exp"),
NJS_SKIP_ARG, NJS_NUMBER_ARG),
},
+ /* ES6. */
+ {
+ .type = NJS_METHOD,
+ .name = njs_string("expm1"),
+ .value = njs_native_function(njs_object_math_expm1, 0,
+ NJS_SKIP_ARG, NJS_NUMBER_ARG),
+ },
+
{
.type = NJS_METHOD,
.name = njs_string("floor"),
NJS_SKIP_ARG, NJS_NUMBER_ARG),
},
+ /* ES6. */
+ {
+ .type = NJS_METHOD,
+ .name = njs_string("fround"),
+ .value = njs_native_function(njs_object_math_fround, 0,
+ NJS_SKIP_ARG, NJS_NUMBER_ARG),
+ },
+
/* ES6. */
{
.type = NJS_METHOD,
NJS_SKIP_ARG, NJS_NUMBER_ARG),
},
+ /* ES6. */
+ {
+ .type = NJS_METHOD,
+ .name = njs_string("log10"),
+ .value = njs_native_function(njs_object_math_log10, 0,
+ NJS_SKIP_ARG, NJS_NUMBER_ARG),
+ },
+
+ /* ES6. */
+ {
+ .type = NJS_METHOD,
+ .name = njs_string("log1p"),
+ .value = njs_native_function(njs_object_math_log1p, 0,
+ NJS_SKIP_ARG, NJS_NUMBER_ARG),
+ },
+
+ /* ES6. */
+ {
+ .type = NJS_METHOD,
+ .name = njs_string("log2"),
+ .value = njs_native_function(njs_object_math_log2, 0,
+ NJS_SKIP_ARG, NJS_NUMBER_ARG),
+ },
+
{
.type = NJS_METHOD,
.name = njs_string("max"),
NJS_SKIP_ARG, NJS_NUMBER_ARG),
},
+ /* ES6. */
+ {
+ .type = NJS_METHOD,
+ .name = njs_string("sinh"),
+ .value = njs_native_function(njs_object_math_sinh, 0,
+ NJS_SKIP_ARG, NJS_NUMBER_ARG),
+ },
+
{
.type = NJS_METHOD,
.name = njs_string("sqrt"),
NJS_SKIP_ARG, NJS_NUMBER_ARG),
},
+ /* ES6. */
+ {
+ .type = NJS_METHOD,
+ .name = njs_string("tanh"),
+ .value = njs_native_function(njs_object_math_tanh, 0,
+ NJS_SKIP_ARG, NJS_NUMBER_ARG),
+ },
+
/* ES6. */
{
.type = NJS_METHOD,
{ nxt_string("Math.acos(0) - Math.PI/2"),
nxt_string("0") },
+ { nxt_string("Math.acosh()"),
+ nxt_string("NaN") },
+
+ { nxt_string("Math.acosh('abc')"),
+ nxt_string("NaN") },
+
+ { nxt_string("Math.acosh(0.9)"),
+ nxt_string("NaN") },
+
+ { nxt_string("Math.acosh(1)"),
+ nxt_string("0") },
+
+ { nxt_string("Math.acosh('Infinity')"),
+ nxt_string("Infinity") },
+
+ /*
+ * The difference is 2 * Number.EPSILON on FreeBSD
+ * and zero on other platforms.
+ */
+ { nxt_string("Math.abs(Math.cosh(1) - (1/Math.E + Math.E)/2)"
+ " <= 2 * Number.EPSILON"),
+ nxt_string("true") },
+
{ nxt_string("Math.asin()"),
nxt_string("NaN") },
{ nxt_string("Math.asin(1) - Math.PI/2"),
nxt_string("0") },
+ { nxt_string("Math.asinh()"),
+ nxt_string("NaN") },
+
+ { nxt_string("Math.asinh('abc')"),
+ nxt_string("NaN") },
+
+ { nxt_string("Math.asinh(0)"),
+ nxt_string("0") },
+
+ { nxt_string("Math.asinh('-0')"),
+ nxt_string("-0") },
+
+ { nxt_string("Math.asinh(Infinity)"),
+ nxt_string("Infinity") },
+
+ { nxt_string("Math.asinh(-Infinity)"),
+ nxt_string("-Infinity") },
+
+ { nxt_string("Math.asinh((Math.E - 1/Math.E)/2)"),
+ nxt_string("1") },
+
{ nxt_string("Math.atan()"),
nxt_string("NaN") },
{ nxt_string("Math.atan2(1, 1) - Math.atan2(-5, -5) - Math.PI"),
nxt_string("0") },
+ { nxt_string("Math.atanh()"),
+ nxt_string("NaN") },
+
+ { nxt_string("Math.atanh('abc')"),
+ nxt_string("NaN") },
+
+ { nxt_string("Math.atanh(-1.1)"),
+ nxt_string("NaN") },
+
+ { nxt_string("Math.atanh(1.1)"),
+ nxt_string("NaN") },
+
+ { nxt_string("Math.atanh(1)"),
+ nxt_string("Infinity") },
+
+ { nxt_string("Math.atanh('-1')"),
+ nxt_string("-Infinity") },
+
+ { nxt_string("Math.atanh(0)"),
+ nxt_string("0") },
+
+ { nxt_string("Math.atanh(-0)"),
+ nxt_string("-0") },
+
+ /*
+ * The difference is Number.EPSILON on Linux/i686
+ * and zero on other platforms.
+ */
+ { nxt_string("Math.abs(1 - Math.atanh((Math.E - 1)/(Math.E + 1)) * 2)"
+ " <= Number.EPSILON"),
+ nxt_string("true") },
+
+ { nxt_string("Math.cbrt()"),
+ nxt_string("NaN") },
+
+ { nxt_string("Math.cbrt('abc')"),
+ nxt_string("NaN") },
+
+ { nxt_string("Math.cbrt(0)"),
+ nxt_string("0") },
+
+ { nxt_string("Math.cbrt('-0')"),
+ nxt_string("-0") },
+
+ { nxt_string("Math.cbrt(Infinity)"),
+ nxt_string("Infinity") },
+
+ { nxt_string("Math.cbrt(-Infinity)"),
+ nxt_string("-Infinity") },
+
+ { nxt_string("Math.cbrt('27')"),
+ nxt_string("3") },
+
+ { nxt_string("Math.cbrt(-1)"),
+ nxt_string("-1") },
+
{ nxt_string("Math.ceil()"),
nxt_string("NaN") },
{ nxt_string("Math.cos(Math.PI*2)"),
nxt_string("1") },
+ { nxt_string("Math.cosh()"),
+ nxt_string("NaN") },
+
+ { nxt_string("Math.cosh('abc')"),
+ nxt_string("NaN") },
+
+ { nxt_string("Math.cosh('0')"),
+ nxt_string("1") },
+
+ { nxt_string("Math.cosh(-0)"),
+ nxt_string("1") },
+
+ { nxt_string("Math.cosh(Infinity)"),
+ nxt_string("Infinity") },
+
+ { nxt_string("Math.cosh(-Infinity)"),
+ nxt_string("Infinity") },
+
+ /*
+ * The difference is Number.EPSILON on FreeBSD
+ * and zero on other platforms.
+ */
+ { nxt_string("Math.abs(Math.cosh(1) - (1/Math.E + Math.E)/2)"
+ " <= Number.EPSILON"),
+ nxt_string("true") },
+
{ nxt_string("Math.exp()"),
nxt_string("NaN") },
{ nxt_string("Math.exp(1) - Math.E <= 2 * Number.EPSILON"),
nxt_string("true") },
+ { nxt_string("Math.expm1()"),
+ nxt_string("NaN") },
+
+ { nxt_string("Math.expm1('abc')"),
+ nxt_string("NaN") },
+
+ { nxt_string("Math.expm1('0')"),
+ nxt_string("0") },
+
+ { nxt_string("Math.expm1(-0)"),
+ nxt_string("-0") },
+
+ { nxt_string("Math.expm1(Infinity)"),
+ nxt_string("Infinity") },
+
+ { nxt_string("Math.expm1(-Infinity)"),
+ nxt_string("-1") },
+
+ /*
+ * The difference is 2 * Number.EPSILON on FreeBSD, Solaris,
+ * and MacOSX and zero on other platforms.
+ */
+ { nxt_string("Math.abs(1 + Math.expm1(1) - Math.E) <= 2 * Number.EPSILON"),
+ nxt_string("true") },
+
{ nxt_string("Math.floor()"),
nxt_string("NaN") },
{ nxt_string("Math.floor(-3.1)"),
nxt_string("-4") },
+ { nxt_string("Math.fround()"),
+ nxt_string("NaN") },
+
+ { nxt_string("Math.fround('abc')"),
+ nxt_string("NaN") },
+
+ { nxt_string("Math.fround(0)"),
+ nxt_string("0") },
+
+ { nxt_string("Math.fround('-0')"),
+ nxt_string("-0") },
+
+ { nxt_string("Math.fround('Infinity')"),
+ nxt_string("Infinity") },
+
+ { nxt_string("Math.fround(-Infinity)"),
+ nxt_string("-Infinity") },
+
+ { nxt_string("Math.fround('-1.5')"),
+ nxt_string("-1.5") },
+
+ { nxt_string("Math.fround(16777216)"),
+ nxt_string("16777216") },
+
+ { nxt_string("Math.fround(-16777217)"),
+ nxt_string("-16777216") },
+
{ nxt_string("Math.hypot()"),
nxt_string("0") },
{ nxt_string("Math.log(Math.E)"),
nxt_string("1") },
+ { nxt_string("Math.log10()"),
+ nxt_string("NaN") },
+
+ { nxt_string("Math.log10('abc')"),
+ nxt_string("NaN") },
+
+ { nxt_string("Math.log10(-1)"),
+ nxt_string("NaN") },
+
+ { nxt_string("Math.log10(0)"),
+ nxt_string("-Infinity") },
+
+ { nxt_string("Math.log10('-0')"),
+ nxt_string("-Infinity") },
+
+ { nxt_string("Math.log10(1)"),
+ nxt_string("0") },
+
+ { nxt_string("Math.log10(Infinity)"),
+ nxt_string("Infinity") },
+
+ { nxt_string("Math.log10(1000)"),
+ nxt_string("3") },
+
+ { nxt_string("Math.log1p()"),
+ nxt_string("NaN") },
+
+ { nxt_string("Math.log1p('abc')"),
+ nxt_string("NaN") },
+
+ { nxt_string("Math.log1p(-2)"),
+ nxt_string("NaN") },
+
+ { nxt_string("Math.log1p('-1')"),
+ nxt_string("-Infinity") },
+
+ { nxt_string("Math.log1p(0)"),
+ nxt_string("0") },
+
+ { nxt_string("Math.log1p(-0)"),
+ nxt_string("-0") },
+
+ { nxt_string("Math.log1p(Infinity)"),
+ nxt_string("Infinity") },
+
+ { nxt_string("Math.log1p(Math.E - 1)"),
+ nxt_string("1") },
+
+ { nxt_string("Math.log2()"),
+ nxt_string("NaN") },
+
+ { nxt_string("Math.log2('abc')"),
+ nxt_string("NaN") },
+
+ { nxt_string("Math.log2(-1)"),
+ nxt_string("NaN") },
+
+ { nxt_string("Math.log2(0)"),
+ nxt_string("-Infinity") },
+
+ { nxt_string("Math.log2('-0')"),
+ nxt_string("-Infinity") },
+
+ { nxt_string("Math.log2(1)"),
+ nxt_string("0") },
+
+ { nxt_string("Math.log2(Infinity)"),
+ nxt_string("Infinity") },
+
+ { nxt_string("Math.log2(128)"),
+ nxt_string("7") },
+
{ nxt_string("Math.max()"),
nxt_string("-Infinity") },
{ nxt_string("Math.sin(-Math.PI/2)"),
nxt_string("-1") },
+ { nxt_string("Math.sinh()"),
+ nxt_string("NaN") },
+
+ { nxt_string("Math.sinh('abc')"),
+ nxt_string("NaN") },
+
+ { nxt_string("Math.sinh('0')"),
+ nxt_string("0") },
+
+ { nxt_string("Math.sinh(-0)"),
+ nxt_string("-0") },
+
+ { nxt_string("Math.sinh(Infinity)"),
+ nxt_string("Infinity") },
+
+ { nxt_string("Math.sinh(-Infinity)"),
+ nxt_string("-Infinity") },
+
+ { nxt_string("Math.sinh(1) - (Math.E - 1/Math.E)/2"),
+ nxt_string("0") },
+
{ nxt_string("Math.sqrt()"),
nxt_string("NaN") },
{ nxt_string("Math.tan(Math.PI/3) + Math.tan(-Math.PI/3)"),
nxt_string("0") },
+ { nxt_string("Math.tanh()"),
+ nxt_string("NaN") },
+
+ { nxt_string("Math.tanh('abc')"),
+ nxt_string("NaN") },
+
+ { nxt_string("Math.tanh('0')"),
+ nxt_string("0") },
+
+ { nxt_string("Math.tanh(-0)"),
+ nxt_string("-0") },
+
+ { nxt_string("Math.tanh(Infinity)"),
+ nxt_string("1") },
+
+ { nxt_string("Math.tanh(-Infinity)"),
+ nxt_string("-1") },
+
+ { nxt_string("Math.tanh(0.5) - (Math.E - 1)/(Math.E + 1)"),
+ nxt_string("0") },
+
{ nxt_string("Math.trunc(3.9)"),
nxt_string("3") },