// ♓🌟 Piscēs ∷ numeric.test.js
// ====================================================================
//
-// Copyright © 2022 Lady [@ Lady’s Computer].
+// Copyright © 2022–2023 Lady [@ Lady’s Computer].
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
import {
+ assert,
assertStrictEquals,
assertThrows,
describe,
} from "./dev-deps.js";
import {
abs,
- atan2,
+ arccos,
+ arccosh,
+ arcsin,
+ arcsinh,
+ arctan,
+ arctan2,
+ arctanh,
+ cbrt,
+ ceil,
clz32,
+ cos,
+ cosh,
+ exp,
+ expm1,
+ floor,
+ hypot,
+ isFiniteNumber,
+ isIntegralNumber,
+ isNan,
+ isSafeIntegralNumber,
+ ln,
+ ln1p,
+ log10,
+ log2,
max,
min,
+ rand,
+ round,
sgn,
+ sin,
+ sinh,
+ sqrt,
+ tan,
+ tanh,
toBigInt,
+ toExponentialNotation,
+ toFixedDecimalNotation,
toFloat32,
- toIntegerOrInfinity,
- toIntN,
+ toIntegralNumber,
+ toIntegralNumberOrInfinity,
toNumber,
toNumeric,
- toUintN,
+ toSignedIntegralNumeric,
+ toUnsignedIntegralNumeric,
+ trunc,
} from "./numeric.js";
describe("abs", () => {
const bn = BigInt(Number.MAX_SAFE_INTEGER) + 2n;
assertStrictEquals(abs(-bn), bn);
});
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new abs(0));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(abs.length, 1);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(abs.name, "abs");
+ });
+ });
+});
+
+describe("arccos", () => {
+ it("[[Call]] returns the arccos", () => {
+ assertStrictEquals(arccos(1), 0);
+ assertStrictEquals(arccos(0), Math.PI / 2);
+ });
+
+ it("[[Call]] throws with big·ints", () => {
+ assertThrows(() => arccos(1n));
+ });
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new arccos(1));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(arccos.length, 1);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(arccos.name, "arccos");
+ });
+ });
+});
+
+describe("arccosh", () => {
+ it("[[Call]] returns the arccosh", () => {
+ assertStrictEquals(arccosh(1), 0);
+ assertStrictEquals(arccosh(0), NaN);
+ });
+
+ it("[[Call]] throws with big·ints", () => {
+ assertThrows(() => arccosh(1n));
+ });
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new arccosh(1));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(arccosh.length, 1);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(arccosh.name, "arccosh");
+ });
+ });
+});
+
+describe("arcsin", () => {
+ it("[[Call]] returns the arcsin", () => {
+ assertStrictEquals(arcsin(1), Math.PI / 2);
+ assertStrictEquals(arcsin(0), 0);
+ });
+
+ it("[[Call]] throws with big·ints", () => {
+ assertThrows(() => arcsin(1n));
+ });
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new arcsin(1));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(arcsin.length, 1);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(arcsin.name, "arcsin");
+ });
+ });
+});
+
+describe("arcsinh", () => {
+ it("[[Call]] returns the arcsinh", () => {
+ assertStrictEquals(arcsinh(1), Math.asinh(1));
+ assertStrictEquals(arcsinh(0), 0);
+ });
+
+ it("[[Call]] throws with big·ints", () => {
+ assertThrows(() => arcsinh(1n));
+ });
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new arcsinh(1));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(arcsinh.length, 1);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(arcsinh.name, "arcsinh");
+ });
+ });
+});
+
+describe("arctan", () => {
+ it("[[Call]] returns the arctan", () => {
+ assertStrictEquals(arctan(1), Math.PI / 4);
+ assertStrictEquals(arctan(0), 0);
+ });
+
+ it("[[Call]] throws with big·ints", () => {
+ assertThrows(() => arctan(1n));
+ });
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new arctan(1));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(arctan.length, 1);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(arctan.name, "arctan");
+ });
+ });
});
-describe("atan2", () => {
- it("[[Call]] returns the atan2", () => {
- assertStrictEquals(atan2(6, 9), Math.atan2(6, 9));
+describe("arctan2", () => {
+ it("[[Call]] returns the arctan2", () => {
+ assertStrictEquals(arctan2(6, 9), Math.atan2(6, 9));
});
it("[[Call]] works with big·ints", () => {
- assertStrictEquals(atan2(6n, 9n), Math.atan2(6, 9));
+ assertStrictEquals(arctan2(6n, 9n), Math.atan2(6, 9));
+ });
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new arctan2(1, 0));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(arctan2.length, 2);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(arctan2.name, "arctan2");
+ });
+ });
+});
+
+describe("arctanh", () => {
+ it("[[Call]] returns the arctanh", () => {
+ assertStrictEquals(arctanh(1), Infinity);
+ assertStrictEquals(arctanh(0), 0);
+ });
+
+ it("[[Call]] throws with big·ints", () => {
+ assertThrows(() => arctanh(1n));
+ });
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new arctanh(1));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(arctanh.length, 1);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(arctanh.name, "arctanh");
+ });
+ });
+});
+
+describe("cbrt", () => {
+ it("[[Call]] returns the cbrt", () => {
+ assertStrictEquals(cbrt(1), 1);
+ assertStrictEquals(cbrt(2), Math.cbrt(2));
+ });
+
+ it("[[Call]] throws with big·ints", () => {
+ assertThrows(() => cbrt(1n));
+ });
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new cbrt(1));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(cbrt.length, 1);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(cbrt.name, "cbrt");
+ });
+ });
+});
+
+describe("ceil", () => {
+ it("[[Call]] returns the ceil", () => {
+ assertStrictEquals(ceil(1), 1);
+ assertStrictEquals(ceil(1.1), 2);
+ });
+
+ it("[[Call]] throws with big·ints", () => {
+ assertThrows(() => ceil(1n));
+ });
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new ceil(1));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(ceil.length, 1);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(ceil.name, "ceil");
+ });
});
});
it("[[Call]] works with big·ints", () => {
assertStrictEquals(clz32(1n << 28n), 3);
});
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new clz32(1));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(clz32.length, 1);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(clz32.name, "clz32");
+ });
+ });
+});
+
+describe("cos", () => {
+ it("[[Call]] returns the cos", () => {
+ assertStrictEquals(cos(1), Math.cos(1));
+ assertStrictEquals(cos(0), 1);
+ });
+
+ it("[[Call]] throws with big·ints", () => {
+ assertThrows(() => cos(1n));
+ });
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new cos(1));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(cos.length, 1);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(cos.name, "cos");
+ });
+ });
+});
+
+describe("cosh", () => {
+ it("[[Call]] returns the cosh", () => {
+ assertStrictEquals(cosh(1), Math.cosh(1));
+ assertStrictEquals(cosh(0), 1);
+ });
+
+ it("[[Call]] throws with big·ints", () => {
+ assertThrows(() => cosh(1n));
+ });
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new cosh(1));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(cosh.length, 1);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(cosh.name, "cosh");
+ });
+ });
+});
+
+describe("exp", () => {
+ it("[[Call]] returns the exp", () => {
+ assertStrictEquals(exp(1), Math.E);
+ assertStrictEquals(exp(0), 1);
+ });
+
+ it("[[Call]] throws with big·ints", () => {
+ assertThrows(() => exp(1n));
+ });
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new exp(1));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(exp.length, 1);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(exp.name, "exp");
+ });
+ });
+});
+
+describe("expm1", () => {
+ it("[[Call]] returns the expm1", () => {
+ assertStrictEquals(expm1(1), Math.E - 1);
+ assertStrictEquals(expm1(0), 0);
+ });
+
+ it("[[Call]] throws with big·ints", () => {
+ assertThrows(() => expm1(1n));
+ });
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new expm1(1));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(expm1.length, 1);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(expm1.name, "expm1");
+ });
+ });
+});
+
+describe("floor", () => {
+ it("[[Call]] returns the floor", () => {
+ assertStrictEquals(floor(1), 1);
+ assertStrictEquals(floor(0.1), 0);
+ });
+
+ it("[[Call]] throws with big·ints", () => {
+ assertThrows(() => floor(1n));
+ });
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new floor(1));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(floor.length, 1);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(floor.name, "floor");
+ });
+ });
+});
+
+describe("hypot", () => {
+ it("[[Call]] returns the floor", () => {
+ assertStrictEquals(hypot(1, 0), 1);
+ assertStrictEquals(hypot(3, 4), 5);
+ });
+
+ it("[[Call]] throws with big·ints", () => {
+ assertThrows(() => hypot(1n, 0n));
+ });
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new hypot(1, 0));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(hypot.length, 2);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(hypot.name, "hypot");
+ });
+ });
+});
+
+describe("isFiniteNumber", () => {
+ it("[[Call]] returns true for finite numbers", () => {
+ assertStrictEquals(isFiniteNumber(1), true);
+ assertStrictEquals(isFiniteNumber(Number.MAX_VALUE), true);
+ assertStrictEquals(isFiniteNumber(Number.EPSILON), true);
+ });
+
+ it("[[Call]] returns false for nonfinite numbers", () => {
+ assertStrictEquals(isFiniteNumber(NaN), false);
+ assertStrictEquals(isFiniteNumber(Infinity), false);
+ });
+
+ it("[[Call]] returns false for nonnumbers", () => {
+ assertStrictEquals(isFiniteNumber(1n), false);
+ assertStrictEquals(isFiniteNumber("1"), false);
+ });
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new isFiniteNumber(1));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(isFiniteNumber.length, 1);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(isFiniteNumber.name, "isFiniteNumber");
+ });
+ });
+});
+
+describe("isIntegralNumber", () => {
+ it("[[Call]] returns true for integral numbers", () => {
+ assertStrictEquals(isIntegralNumber(1), true);
+ assertStrictEquals(isIntegralNumber(Number.MAX_VALUE), true);
+ });
+
+ it("[[Call]] returns false for nonfinite numbers", () => {
+ assertStrictEquals(isIntegralNumber(NaN), false);
+ assertStrictEquals(isIntegralNumber(Infinity), false);
+ });
+
+ it("[[Call]] returns false for nonintegral numbers", () => {
+ assertStrictEquals(isIntegralNumber(.1), false);
+ assertStrictEquals(isIntegralNumber(Number.EPSILON), false);
+ });
+
+ it("[[Call]] returns false for nonnumbers", () => {
+ assertStrictEquals(isIntegralNumber(1n), false);
+ assertStrictEquals(isIntegralNumber("1"), false);
+ });
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new isIntegralNumber(1));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(isIntegralNumber.length, 1);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(isIntegralNumber.name, "isIntegralNumber");
+ });
+ });
+});
+
+describe("isNan", () => {
+ it("[[Call]] returns true for nan", () => {
+ assertStrictEquals(isNan(NaN), true);
+ });
+
+ it("[[Call]] returns false for infinite numbers", () => {
+ assertStrictEquals(isNan(-Infinity), false);
+ assertStrictEquals(isNan(Infinity), false);
+ });
+
+ it("[[Call]] returns false for finite numbers", () => {
+ assertStrictEquals(isNan(1), false);
+ assertStrictEquals(isNan(Number.MAX_VALUE), false);
+ assertStrictEquals(isNan(.1), false);
+ assertStrictEquals(isNan(Number.EPSILON), false);
+ });
+
+ it("[[Call]] returns false for nonnumbers", () => {
+ assertStrictEquals(isNan(1n), false);
+ assertStrictEquals(isNan("NaN"), false);
+ assertStrictEquals(isNan({}), false);
+ assertStrictEquals(isNan(new Date(NaN)), false);
+ });
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new isNan(1));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(isNan.length, 1);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(isNan.name, "isNan");
+ });
+ });
+});
+
+describe("isSafeIntegralNumber", () => {
+ it("[[Call]] returns true for safe integral numbers", () => {
+ assertStrictEquals(isSafeIntegralNumber(1), true);
+ assertStrictEquals(
+ isSafeIntegralNumber(Number.MAX_SAFE_INTEGER),
+ true,
+ );
+ });
+
+ it("[[Call]] returns false for nonfinite numbers", () => {
+ assertStrictEquals(isSafeIntegralNumber(NaN), false);
+ assertStrictEquals(isSafeIntegralNumber(Infinity), false);
+ });
+
+ it("[[Call]] returns false for nonintegral numbers", () => {
+ assertStrictEquals(isSafeIntegralNumber(.1), false);
+ assertStrictEquals(isSafeIntegralNumber(Number.EPSILON), false);
+ });
+ it("[[Call]] returns true for unsafe integral numbers", () => {
+ assertStrictEquals(isSafeIntegralNumber(Number.MAX_VALUE), false);
+ });
+
+ it("[[Call]] returns false for nonnumbers", () => {
+ assertStrictEquals(isSafeIntegralNumber(1n), false);
+ assertStrictEquals(isSafeIntegralNumber("1"), false);
+ });
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new isSafeIntegralNumber(1));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(isSafeIntegralNumber.length, 1);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(
+ isSafeIntegralNumber.name,
+ "isSafeIntegralNumber",
+ );
+ });
+ });
+});
+
+describe("ln", () => {
+ it("[[Call]] returns the ln", () => {
+ assertStrictEquals(ln(1), 0);
+ assertStrictEquals(ln(Math.E), 1);
+ });
+
+ it("[[Call]] throws with big·ints", () => {
+ assertThrows(() => ln(1n));
+ });
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new ln(1));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(ln.length, 1);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(ln.name, "ln");
+ });
+ });
+});
+
+describe("ln1p", () => {
+ it("[[Call]] returns the ln1p", () => {
+ assertStrictEquals(ln1p(1), Math.log1p(1));
+ assertStrictEquals(ln1p(Math.E - 1), 1);
+ });
+
+ it("[[Call]] throws with big·ints", () => {
+ assertThrows(() => ln1p(1n));
+ });
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new ln1p(1));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(ln1p.length, 1);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(ln1p.name, "ln1p");
+ });
+ });
+});
+
+describe("log10", () => {
+ it("[[Call]] returns the log10", () => {
+ assertStrictEquals(log10(1), 0);
+ assertStrictEquals(log10(10), 1);
+ });
+
+ it("[[Call]] throws with big·ints", () => {
+ assertThrows(() => log10(1n));
+ });
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new log10(1));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(log10.length, 1);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(log10.name, "log10");
+ });
+ });
+});
+
+describe("log2", () => {
+ it("[[Call]] returns the log2", () => {
+ assertStrictEquals(log2(1), 0);
+ assertStrictEquals(log2(2), 1);
+ });
+
+ it("[[Call]] throws with big·ints", () => {
+ assertThrows(() => log2(1n));
+ });
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new log2(1));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(log2.length, 1);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(log2.name, "log2");
+ });
+ });
});
describe("max", () => {
it("[[Call]] throws if both big·int and number arguments are provided", () => {
assertThrows(() => max(-Infinity, 0n));
});
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new max(1, 0));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(max.length, 2);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(max.name, "max");
+ });
+ });
});
describe("min", () => {
it("[[Call]] throws if both big·int and number arguments are provided", () => {
assertThrows(() => min(Infinity, 0n));
});
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new min(1, 0));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(min.length, 2);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(min.name, "min");
+ });
+ });
+});
+
+describe("rand", () => {
+ it("[[Call]] returns a random number between 0 and 1", () => {
+ // Not possible to fully test, obviously.
+ const r = rand();
+ assert(typeof r === "number");
+ assert(r >= 0 && r < 1);
+ });
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new rand());
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(rand.length, 0);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(rand.name, "rand");
+ });
+ });
+});
+
+describe("round", () => {
+ it("[[Call]] returns the round", () => {
+ assertStrictEquals(round(1), 1);
+ assertStrictEquals(round(0.5), 1);
+ assertStrictEquals(round(-0.5), -0);
+ });
+
+ it("[[Call]] throws with big·ints", () => {
+ assertThrows(() => round(1n));
+ });
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new round(1));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(round.length, 1);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(round.name, "round");
+ });
+ });
});
describe("sgn", () => {
assertStrictEquals(sgn(92n), 1n);
assertStrictEquals(sgn(-92n), -1n);
});
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new sgn(1));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(sgn.length, 1);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(sgn.name, "sgn");
+ });
+ });
+});
+
+describe("sin", () => {
+ it("[[Call]] returns the sin", () => {
+ assertStrictEquals(sin(1), Math.sin(1));
+ assertStrictEquals(sin(0), 0);
+ });
+
+ it("[[Call]] throws with big·ints", () => {
+ assertThrows(() => sin(1n));
+ });
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new sin(1));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(sin.length, 1);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(sin.name, "sin");
+ });
+ });
+});
+
+describe("sinh", () => {
+ it("[[Call]] returns the sinh", () => {
+ assertStrictEquals(sinh(1), Math.sinh(1));
+ assertStrictEquals(sinh(0), 0);
+ });
+
+ it("[[Call]] throws with big·ints", () => {
+ assertThrows(() => sinh(1n));
+ });
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new sinh(1));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(sinh.length, 1);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(sinh.name, "sinh");
+ });
+ });
+});
+
+describe("sqrt", () => {
+ it("[[Call]] returns the sqrt", () => {
+ assertStrictEquals(sqrt(1), 1);
+ assertStrictEquals(sqrt(2), Math.SQRT2);
+ });
+
+ it("[[Call]] throws with big·ints", () => {
+ assertThrows(() => sqrt(1n));
+ });
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new sqrt(1));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(sqrt.length, 1);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(sqrt.name, "sqrt");
+ });
+ });
+});
+
+describe("tan", () => {
+ it("[[Call]] returns the tan", () => {
+ assertStrictEquals(tan(1), Math.tan(1));
+ assertStrictEquals(tan(0), 0);
+ });
+
+ it("[[Call]] throws with big·ints", () => {
+ assertThrows(() => tan(1n));
+ });
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new tan(1));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(tan.length, 1);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(tan.name, "tan");
+ });
+ });
+});
+
+describe("tanh", () => {
+ it("[[Call]] returns the tanh", () => {
+ assertStrictEquals(tanh(1), Math.tanh(1));
+ assertStrictEquals(tanh(0), 0);
+ });
+
+ it("[[Call]] throws with big·ints", () => {
+ assertThrows(() => tanh(1n));
+ });
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new tanh(1));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(tanh.length, 1);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(tanh.name, "tanh");
+ });
+ });
});
describe("toBigInt", () => {
it("[[Call]] converts to a big·int", () => {
assertStrictEquals(toBigInt(2), 2n);
});
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new toBigInt(1));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(toBigInt.length, 1);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(toBigInt.name, "toBigInt");
+ });
+ });
+});
+
+describe("toExponentialNotation", () => {
+ it("[[Call]] converts to exponential notation", () => {
+ assertStrictEquals(toExponentialNotation(231), "2.31e+2");
+ });
+
+ it("[[Call]] works with big·ints", () => {
+ assertStrictEquals(
+ toExponentialNotation(9007199254740993n),
+ "9.007199254740993e+15",
+ );
+ });
+
+ it("[[Call]] respects the specified number of fractional digits", () => {
+ assertStrictEquals(
+ toExponentialNotation(.00000000642, 3),
+ "6.420e-9",
+ );
+ assertStrictEquals(toExponentialNotation(.00691, 1), "6.9e-3");
+ assertStrictEquals(toExponentialNotation(.00685, 1), "6.9e-3");
+ assertStrictEquals(toExponentialNotation(.004199, 2), "4.20e-3");
+ assertStrictEquals(
+ toExponentialNotation(6420000000n, 3),
+ "6.420e+9",
+ );
+ assertStrictEquals(toExponentialNotation(6910n, 1), "6.9e+3");
+ assertStrictEquals(toExponentialNotation(6850n, 1), "6.9e+3");
+ assertStrictEquals(toExponentialNotation(4199n, 2), "4.20e+3");
+ });
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new toExponentialNotation(1, 1));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(toExponentialNotation.length, 2);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(
+ toExponentialNotation.name,
+ "toExponentialNotation",
+ );
+ });
+ });
+});
+
+describe("toFixedDecimalNotation", () => {
+ it("[[Call]] converts to fixed decimal notation", () => {
+ assertStrictEquals(toFixedDecimalNotation(69.4199, 3), "69.420");
+ });
+
+ it("[[Call]] works with big·ints", () => {
+ assertStrictEquals(
+ toFixedDecimalNotation(9007199254740993n),
+ "9007199254740993",
+ );
+ assertStrictEquals(
+ toFixedDecimalNotation(9007199254740993n, 2),
+ "9007199254740993.00",
+ );
+ });
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new toFixedDecimalNotation(1, 1));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(toFixedDecimalNotation.length, 2);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(
+ toFixedDecimalNotation.name,
+ "toFixedDecimalNotation",
+ );
+ });
+ });
});
describe("toFloat32", () => {
Math.fround(562949953421313),
);
});
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new toFloat32(1));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(toFloat32.length, 1);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(toFloat32.name, "toFloat32");
+ });
+ });
});
-describe("toIntN", () => {
+describe("toSignedIntegralNumeric", () => {
it("[[Call]] converts to an int·n", () => {
- assertStrictEquals(toIntN(2, 7n), -1n);
+ assertStrictEquals(toSignedIntegralNumeric(2, 7n), -1n);
});
it("[[Call]] works with numbers", () => {
- assertStrictEquals(toIntN(2, 7), -1);
+ assertStrictEquals(toSignedIntegralNumeric(2, 7), -1);
});
it("[[Call]] works with non‐integers", () => {
- assertStrictEquals(toIntN(2, 7.21), -1);
- assertStrictEquals(toIntN(2, Infinity), 0);
+ assertStrictEquals(toSignedIntegralNumeric(2, 7.21), -1);
+ assertStrictEquals(toSignedIntegralNumeric(2, Infinity), 0);
+ });
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new toSignedIntegralNumeric(1, 1));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(toSignedIntegralNumeric.length, 2);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(
+ toSignedIntegralNumeric.name,
+ "toSignedIntegralNumeric",
+ );
+ });
+ });
+});
+
+describe("toIntegralNumber", () => {
+ it("[[Call]] converts nan to zero", () => {
+ assertStrictEquals(toIntegralNumber(NaN), 0);
+ });
+
+ it("[[Call]] converts negative zero to positive zero", () => {
+ assertStrictEquals(toIntegralNumber(-0), 0);
+ });
+
+ it("[[Call]] drops the fractional part of negative numbers", () => {
+ assertStrictEquals(toIntegralNumber(-1.79), -1);
+ });
+
+ it("[[Call]] returns zero for infinity", () => {
+ assertStrictEquals(toIntegralNumber(Infinity), 0);
+ });
+
+ it("[[Call]] returns zero for negative infinity", () => {
+ assertStrictEquals(toIntegralNumber(-Infinity), 0);
+ });
+
+ it("[[Call]] works with big·ints", () => {
+ assertStrictEquals(toIntegralNumber(2n), 2);
+ });
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new toIntegralNumber(1));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(toIntegralNumber.length, 1);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(toIntegralNumber.name, "toIntegralNumber");
+ });
});
});
-describe("toIntegerOrInfinity", () => {
+describe("toIntegralNumberOrInfinity", () => {
it("[[Call]] converts nan to zero", () => {
- assertStrictEquals(toIntegerOrInfinity(NaN), 0);
+ assertStrictEquals(toIntegralNumberOrInfinity(NaN), 0);
});
it("[[Call]] converts negative zero to positive zero", () => {
- assertStrictEquals(toIntegerOrInfinity(-0), 0);
+ assertStrictEquals(toIntegralNumberOrInfinity(-0), 0);
});
it("[[Call]] drops the fractional part of negative numbers", () => {
- assertStrictEquals(toIntegerOrInfinity(-1.79), -1);
+ assertStrictEquals(toIntegralNumberOrInfinity(-1.79), -1);
});
it("[[Call]] returns infinity for infinity", () => {
- assertStrictEquals(toIntegerOrInfinity(Infinity), Infinity);
+ assertStrictEquals(toIntegralNumberOrInfinity(Infinity), Infinity);
});
it("[[Call]] returns negative infinity for negative infinity", () => {
- assertStrictEquals(toIntegerOrInfinity(Infinity), Infinity);
+ assertStrictEquals(
+ toIntegralNumberOrInfinity(-Infinity),
+ -Infinity,
+ );
+ });
+
+ it("[[Call]] works with big·ints", () => {
+ assertStrictEquals(toIntegralNumberOrInfinity(2n), 2);
+ });
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new toIntegralNumberOrInfinity(1));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(toIntegralNumberOrInfinity.length, 1);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(
+ toIntegralNumberOrInfinity.name,
+ "toIntegralNumberOrInfinity",
+ );
+ });
});
});
231n,
);
});
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new toNumeric(1));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(toNumeric.length, 1);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(toNumeric.name, "toNumeric");
+ });
+ });
});
-describe("toUintN", () => {
+describe("toUnsignedIntegralNumeric", () => {
it("[[Call]] converts to an int·n", () => {
- assertStrictEquals(toUintN(2, 7n), 3n);
+ assertStrictEquals(toUnsignedIntegralNumeric(2, 7n), 3n);
});
it("[[Call]] works with numbers", () => {
- assertStrictEquals(toUintN(2, 7), 3);
+ assertStrictEquals(toUnsignedIntegralNumeric(2, 7), 3);
});
it("[[Call]] works with non‐integers", () => {
- assertStrictEquals(toUintN(2, 7.21), 3);
- assertStrictEquals(toUintN(2, Infinity), 0);
+ assertStrictEquals(toUnsignedIntegralNumeric(2, 7.21), 3);
+ assertStrictEquals(toUnsignedIntegralNumeric(2, Infinity), 0);
+ });
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new toUnsignedIntegralNumeric(1, 1));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(toUnsignedIntegralNumeric.length, 2);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(
+ toUnsignedIntegralNumeric.name,
+ "toUnsignedIntegralNumeric",
+ );
+ });
+ });
+});
+
+describe("trunc", () => {
+ it("[[Call]] returns the trunc", () => {
+ assertStrictEquals(trunc(1), 1);
+ assertStrictEquals(trunc(0.5), 0);
+ assertStrictEquals(trunc(-0.5), -0);
+ });
+
+ it("[[Call]] throws with big·ints", () => {
+ assertThrows(() => trunc(1n));
+ });
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new trunc(1));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(trunc.length, 1);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(trunc.name, "trunc");
+ });
});
});