1 // SPDX-FileCopyrightText: 2022, 2023, 2025 Lady <https://www.ladys.computer/about/#lady>
2 // SPDX-License-Identifier: MPL-2.0
4 * ⁌ ♓🧩 Piscēs ∷ numeric.test.js
6 * Copyright © 2022–2023, 2025 Lady [@ Ladys Computer].
8 * This Source Code Form is subject to the terms of the Mozilla Public
9 * License, v. 2.0. If a copy of the MPL was not distributed with this
10 * file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
19 } from "./dev-deps.js";
57 toExponentialNotation
,
58 toFixedDecimalNotation
,
61 toIntegralNumberOrInfinity
,
64 toSignedIntegralNumeric
,
65 toUnsignedIntegralNumeric
,
67 } from "./numeric.js";
69 describe("abs", () => {
70 it("[[Call]] returns the absolute value", () => {
71 assertStrictEquals(abs(-1), 1);
74 it("[[Call]] works with big·ints", () => {
75 const bn
= BigInt(Number
.MAX_SAFE_INTEGER
) + 2n
;
76 assertStrictEquals(abs(-bn
), bn
);
79 it("[[Construct]] throws an error", () => {
80 assertThrows(() => new abs(0));
83 describe(".length", () => {
84 it("[[Get]] returns the correct length", () => {
85 assertStrictEquals(abs
.length
, 1);
89 describe(".name", () => {
90 it("[[Get]] returns the correct name", () => {
91 assertStrictEquals(abs
.name
, "abs");
96 describe("arccos", () => {
97 it("[[Call]] returns the arccos", () => {
98 assertStrictEquals(arccos(1), 0);
99 assertStrictEquals(arccos(0), Math
.PI
/ 2);
102 it("[[Call]] throws with big·ints", () => {
103 assertThrows(() => arccos(1n
));
106 it("[[Construct]] throws an error", () => {
107 assertThrows(() => new arccos(1));
110 describe(".length", () => {
111 it("[[Get]] returns the correct length", () => {
112 assertStrictEquals(arccos
.length
, 1);
116 describe(".name", () => {
117 it("[[Get]] returns the correct name", () => {
118 assertStrictEquals(arccos
.name
, "arccos");
123 describe("arccosh", () => {
124 it("[[Call]] returns the arccosh", () => {
125 assertStrictEquals(arccosh(1), 0);
126 assertStrictEquals(arccosh(0), NaN
);
129 it("[[Call]] throws with big·ints", () => {
130 assertThrows(() => arccosh(1n
));
133 it("[[Construct]] throws an error", () => {
134 assertThrows(() => new arccosh(1));
137 describe(".length", () => {
138 it("[[Get]] returns the correct length", () => {
139 assertStrictEquals(arccosh
.length
, 1);
143 describe(".name", () => {
144 it("[[Get]] returns the correct name", () => {
145 assertStrictEquals(arccosh
.name
, "arccosh");
150 describe("arcsin", () => {
151 it("[[Call]] returns the arcsin", () => {
152 assertStrictEquals(arcsin(1), Math
.PI
/ 2);
153 assertStrictEquals(arcsin(0), 0);
156 it("[[Call]] throws with big·ints", () => {
157 assertThrows(() => arcsin(1n
));
160 it("[[Construct]] throws an error", () => {
161 assertThrows(() => new arcsin(1));
164 describe(".length", () => {
165 it("[[Get]] returns the correct length", () => {
166 assertStrictEquals(arcsin
.length
, 1);
170 describe(".name", () => {
171 it("[[Get]] returns the correct name", () => {
172 assertStrictEquals(arcsin
.name
, "arcsin");
177 describe("arcsinh", () => {
178 it("[[Call]] returns the arcsinh", () => {
179 assertStrictEquals(arcsinh(1), Math
.asinh(1));
180 assertStrictEquals(arcsinh(0), 0);
183 it("[[Call]] throws with big·ints", () => {
184 assertThrows(() => arcsinh(1n
));
187 it("[[Construct]] throws an error", () => {
188 assertThrows(() => new arcsinh(1));
191 describe(".length", () => {
192 it("[[Get]] returns the correct length", () => {
193 assertStrictEquals(arcsinh
.length
, 1);
197 describe(".name", () => {
198 it("[[Get]] returns the correct name", () => {
199 assertStrictEquals(arcsinh
.name
, "arcsinh");
204 describe("arctan", () => {
205 it("[[Call]] returns the arctan", () => {
206 assertStrictEquals(arctan(1), Math
.PI
/ 4);
207 assertStrictEquals(arctan(0), 0);
210 it("[[Call]] throws with big·ints", () => {
211 assertThrows(() => arctan(1n
));
214 it("[[Construct]] throws an error", () => {
215 assertThrows(() => new arctan(1));
218 describe(".length", () => {
219 it("[[Get]] returns the correct length", () => {
220 assertStrictEquals(arctan
.length
, 1);
224 describe(".name", () => {
225 it("[[Get]] returns the correct name", () => {
226 assertStrictEquals(arctan
.name
, "arctan");
231 describe("arctan2", () => {
232 it("[[Call]] returns the arctan2", () => {
233 assertStrictEquals(arctan2(6, 9), Math
.atan2(6, 9));
236 it("[[Call]] works with big·ints", () => {
237 assertStrictEquals(arctan2(6n
, 9n
), Math
.atan2(6, 9));
240 it("[[Construct]] throws an error", () => {
241 assertThrows(() => new arctan2(1, 0));
244 describe(".length", () => {
245 it("[[Get]] returns the correct length", () => {
246 assertStrictEquals(arctan2
.length
, 2);
250 describe(".name", () => {
251 it("[[Get]] returns the correct name", () => {
252 assertStrictEquals(arctan2
.name
, "arctan2");
257 describe("arctanh", () => {
258 it("[[Call]] returns the arctanh", () => {
259 assertStrictEquals(arctanh(1), Infinity
);
260 assertStrictEquals(arctanh(0), 0);
263 it("[[Call]] throws with big·ints", () => {
264 assertThrows(() => arctanh(1n
));
267 it("[[Construct]] throws an error", () => {
268 assertThrows(() => new arctanh(1));
271 describe(".length", () => {
272 it("[[Get]] returns the correct length", () => {
273 assertStrictEquals(arctanh
.length
, 1);
277 describe(".name", () => {
278 it("[[Get]] returns the correct name", () => {
279 assertStrictEquals(arctanh
.name
, "arctanh");
284 describe("cbrt", () => {
285 it("[[Call]] returns the cbrt", () => {
286 assertStrictEquals(cbrt(1), 1);
287 assertStrictEquals(cbrt(2), Math
.cbrt(2));
290 it("[[Call]] throws with big·ints", () => {
291 assertThrows(() => cbrt(1n
));
294 it("[[Construct]] throws an error", () => {
295 assertThrows(() => new cbrt(1));
298 describe(".length", () => {
299 it("[[Get]] returns the correct length", () => {
300 assertStrictEquals(cbrt
.length
, 1);
304 describe(".name", () => {
305 it("[[Get]] returns the correct name", () => {
306 assertStrictEquals(cbrt
.name
, "cbrt");
311 describe("ceil", () => {
312 it("[[Call]] returns the ceil", () => {
313 assertStrictEquals(ceil(1), 1);
314 assertStrictEquals(ceil(1.1), 2);
317 it("[[Call]] throws with big·ints", () => {
318 assertThrows(() => ceil(1n
));
321 it("[[Construct]] throws an error", () => {
322 assertThrows(() => new ceil(1));
325 describe(".length", () => {
326 it("[[Get]] returns the correct length", () => {
327 assertStrictEquals(ceil
.length
, 1);
331 describe(".name", () => {
332 it("[[Get]] returns the correct name", () => {
333 assertStrictEquals(ceil
.name
, "ceil");
338 describe("clz32", () => {
339 it("[[Call]] returns the clz32", () => {
340 assertStrictEquals(clz32(1 << 28), 3);
343 it("[[Call]] works with big·ints", () => {
344 assertStrictEquals(clz32(1n
<< 28n
), 3);
347 it("[[Construct]] throws an error", () => {
348 assertThrows(() => new clz32(1));
351 describe(".length", () => {
352 it("[[Get]] returns the correct length", () => {
353 assertStrictEquals(clz32
.length
, 1);
357 describe(".name", () => {
358 it("[[Get]] returns the correct name", () => {
359 assertStrictEquals(clz32
.name
, "clz32");
364 describe("cos", () => {
365 it("[[Call]] returns the cos", () => {
366 assertStrictEquals(cos(1), Math
.cos(1));
367 assertStrictEquals(cos(0), 1);
370 it("[[Call]] throws with big·ints", () => {
371 assertThrows(() => cos(1n
));
374 it("[[Construct]] throws an error", () => {
375 assertThrows(() => new cos(1));
378 describe(".length", () => {
379 it("[[Get]] returns the correct length", () => {
380 assertStrictEquals(cos
.length
, 1);
384 describe(".name", () => {
385 it("[[Get]] returns the correct name", () => {
386 assertStrictEquals(cos
.name
, "cos");
391 describe("cosh", () => {
392 it("[[Call]] returns the cosh", () => {
393 assertStrictEquals(cosh(1), Math
.cosh(1));
394 assertStrictEquals(cosh(0), 1);
397 it("[[Call]] throws with big·ints", () => {
398 assertThrows(() => cosh(1n
));
401 it("[[Construct]] throws an error", () => {
402 assertThrows(() => new cosh(1));
405 describe(".length", () => {
406 it("[[Get]] returns the correct length", () => {
407 assertStrictEquals(cosh
.length
, 1);
411 describe(".name", () => {
412 it("[[Get]] returns the correct name", () => {
413 assertStrictEquals(cosh
.name
, "cosh");
418 describe("exp", () => {
419 it("[[Call]] returns the exp", () => {
420 assertStrictEquals(exp(1), Math
.E
);
421 assertStrictEquals(exp(0), 1);
424 it("[[Call]] throws with big·ints", () => {
425 assertThrows(() => exp(1n
));
428 it("[[Construct]] throws an error", () => {
429 assertThrows(() => new exp(1));
432 describe(".length", () => {
433 it("[[Get]] returns the correct length", () => {
434 assertStrictEquals(exp
.length
, 1);
438 describe(".name", () => {
439 it("[[Get]] returns the correct name", () => {
440 assertStrictEquals(exp
.name
, "exp");
445 describe("expm1", () => {
446 it("[[Call]] returns the expm1", () => {
447 assertStrictEquals(expm1(1), Math
.E
- 1);
448 assertStrictEquals(expm1(0), 0);
451 it("[[Call]] throws with big·ints", () => {
452 assertThrows(() => expm1(1n
));
455 it("[[Construct]] throws an error", () => {
456 assertThrows(() => new expm1(1));
459 describe(".length", () => {
460 it("[[Get]] returns the correct length", () => {
461 assertStrictEquals(expm1
.length
, 1);
465 describe(".name", () => {
466 it("[[Get]] returns the correct name", () => {
467 assertStrictEquals(expm1
.name
, "expm1");
472 describe("floor", () => {
473 it("[[Call]] returns the floor", () => {
474 assertStrictEquals(floor(1), 1);
475 assertStrictEquals(floor(0.1), 0);
478 it("[[Call]] throws with big·ints", () => {
479 assertThrows(() => floor(1n
));
482 it("[[Construct]] throws an error", () => {
483 assertThrows(() => new floor(1));
486 describe(".length", () => {
487 it("[[Get]] returns the correct length", () => {
488 assertStrictEquals(floor
.length
, 1);
492 describe(".name", () => {
493 it("[[Get]] returns the correct name", () => {
494 assertStrictEquals(floor
.name
, "floor");
499 describe("hypot", () => {
500 it("[[Call]] returns the floor", () => {
501 assertStrictEquals(hypot(1, 0), 1);
502 assertStrictEquals(hypot(3, 4), 5);
505 it("[[Call]] throws with big·ints", () => {
506 assertThrows(() => hypot(1n
, 0n
));
509 it("[[Construct]] throws an error", () => {
510 assertThrows(() => new hypot(1, 0));
513 describe(".length", () => {
514 it("[[Get]] returns the correct length", () => {
515 assertStrictEquals(hypot
.length
, 2);
519 describe(".name", () => {
520 it("[[Get]] returns the correct name", () => {
521 assertStrictEquals(hypot
.name
, "hypot");
526 describe("isFiniteNumber", () => {
527 it("[[Call]] returns true for finite numbers", () => {
528 assertStrictEquals(isFiniteNumber(1), true);
529 assertStrictEquals(isFiniteNumber(Number
.MAX_VALUE
), true);
530 assertStrictEquals(isFiniteNumber(Number
.EPSILON
), true);
533 it("[[Call]] returns false for nonfinite numbers", () => {
534 assertStrictEquals(isFiniteNumber(NaN
), false);
535 assertStrictEquals(isFiniteNumber(Infinity
), false);
538 it("[[Call]] returns false for nonnumbers", () => {
539 assertStrictEquals(isFiniteNumber(1n
), false);
540 assertStrictEquals(isFiniteNumber("1"), false);
543 it("[[Construct]] throws an error", () => {
544 assertThrows(() => new isFiniteNumber(1));
547 describe(".length", () => {
548 it("[[Get]] returns the correct length", () => {
549 assertStrictEquals(isFiniteNumber
.length
, 1);
553 describe(".name", () => {
554 it("[[Get]] returns the correct name", () => {
555 assertStrictEquals(isFiniteNumber
.name
, "isFiniteNumber");
560 describe("isIntegralNumber", () => {
561 it("[[Call]] returns true for integral numbers", () => {
562 assertStrictEquals(isIntegralNumber(1), true);
563 assertStrictEquals(isIntegralNumber(Number
.MAX_VALUE
), true);
566 it("[[Call]] returns false for nonfinite numbers", () => {
567 assertStrictEquals(isIntegralNumber(NaN
), false);
568 assertStrictEquals(isIntegralNumber(Infinity
), false);
571 it("[[Call]] returns false for nonintegral numbers", () => {
572 assertStrictEquals(isIntegralNumber(.1), false);
573 assertStrictEquals(isIntegralNumber(Number
.EPSILON
), false);
576 it("[[Call]] returns false for nonnumbers", () => {
577 assertStrictEquals(isIntegralNumber(1n
), false);
578 assertStrictEquals(isIntegralNumber("1"), false);
581 it("[[Construct]] throws an error", () => {
582 assertThrows(() => new isIntegralNumber(1));
585 describe(".length", () => {
586 it("[[Get]] returns the correct length", () => {
587 assertStrictEquals(isIntegralNumber
.length
, 1);
591 describe(".name", () => {
592 it("[[Get]] returns the correct name", () => {
593 assertStrictEquals(isIntegralNumber
.name
, "isIntegralNumber");
598 describe("isNan", () => {
599 it("[[Call]] returns true for nan", () => {
600 assertStrictEquals(isNan(NaN
), true);
603 it("[[Call]] returns false for infinite numbers", () => {
604 assertStrictEquals(isNan(-Infinity
), false);
605 assertStrictEquals(isNan(Infinity
), false);
608 it("[[Call]] returns false for finite numbers", () => {
609 assertStrictEquals(isNan(1), false);
610 assertStrictEquals(isNan(Number
.MAX_VALUE
), false);
611 assertStrictEquals(isNan(.1), false);
612 assertStrictEquals(isNan(Number
.EPSILON
), false);
615 it("[[Call]] returns false for nonnumbers", () => {
616 assertStrictEquals(isNan(1n
), false);
617 assertStrictEquals(isNan("NaN"), false);
618 assertStrictEquals(isNan({}), false);
619 assertStrictEquals(isNan(new Date(NaN
)), false);
622 it("[[Construct]] throws an error", () => {
623 assertThrows(() => new isNan(1));
626 describe(".length", () => {
627 it("[[Get]] returns the correct length", () => {
628 assertStrictEquals(isNan
.length
, 1);
632 describe(".name", () => {
633 it("[[Get]] returns the correct name", () => {
634 assertStrictEquals(isNan
.name
, "isNan");
639 describe("isSafeIntegralNumber", () => {
640 it("[[Call]] returns true for safe integral numbers", () => {
641 assertStrictEquals(isSafeIntegralNumber(1), true);
643 isSafeIntegralNumber(Number
.MAX_SAFE_INTEGER
),
648 it("[[Call]] returns false for nonfinite numbers", () => {
649 assertStrictEquals(isSafeIntegralNumber(NaN
), false);
650 assertStrictEquals(isSafeIntegralNumber(Infinity
), false);
653 it("[[Call]] returns false for nonintegral numbers", () => {
654 assertStrictEquals(isSafeIntegralNumber(.1), false);
655 assertStrictEquals(isSafeIntegralNumber(Number
.EPSILON
), false);
657 it("[[Call]] returns true for unsafe integral numbers", () => {
658 assertStrictEquals(isSafeIntegralNumber(Number
.MAX_VALUE
), false);
661 it("[[Call]] returns false for nonnumbers", () => {
662 assertStrictEquals(isSafeIntegralNumber(1n
), false);
663 assertStrictEquals(isSafeIntegralNumber("1"), false);
666 it("[[Construct]] throws an error", () => {
667 assertThrows(() => new isSafeIntegralNumber(1));
670 describe(".length", () => {
671 it("[[Get]] returns the correct length", () => {
672 assertStrictEquals(isSafeIntegralNumber
.length
, 1);
676 describe(".name", () => {
677 it("[[Get]] returns the correct name", () => {
679 isSafeIntegralNumber
.name
,
680 "isSafeIntegralNumber",
686 describe("ln", () => {
687 it("[[Call]] returns the ln", () => {
688 assertStrictEquals(ln(1), 0);
689 assertStrictEquals(ln(Math
.E
), 1);
692 it("[[Call]] throws with big·ints", () => {
693 assertThrows(() => ln(1n
));
696 it("[[Construct]] throws an error", () => {
697 assertThrows(() => new ln(1));
700 describe(".length", () => {
701 it("[[Get]] returns the correct length", () => {
702 assertStrictEquals(ln
.length
, 1);
706 describe(".name", () => {
707 it("[[Get]] returns the correct name", () => {
708 assertStrictEquals(ln
.name
, "ln");
713 describe("ln1p", () => {
714 it("[[Call]] returns the ln1p", () => {
715 assertStrictEquals(ln1p(1), Math
.log1p(1));
716 assertStrictEquals(ln1p(Math
.E
- 1), 1);
719 it("[[Call]] throws with big·ints", () => {
720 assertThrows(() => ln1p(1n
));
723 it("[[Construct]] throws an error", () => {
724 assertThrows(() => new ln1p(1));
727 describe(".length", () => {
728 it("[[Get]] returns the correct length", () => {
729 assertStrictEquals(ln1p
.length
, 1);
733 describe(".name", () => {
734 it("[[Get]] returns the correct name", () => {
735 assertStrictEquals(ln1p
.name
, "ln1p");
740 describe("log10", () => {
741 it("[[Call]] returns the log10", () => {
742 assertStrictEquals(log10(1), 0);
743 assertStrictEquals(log10(10), 1);
746 it("[[Call]] throws with big·ints", () => {
747 assertThrows(() => log10(1n
));
750 it("[[Construct]] throws an error", () => {
751 assertThrows(() => new log10(1));
754 describe(".length", () => {
755 it("[[Get]] returns the correct length", () => {
756 assertStrictEquals(log10
.length
, 1);
760 describe(".name", () => {
761 it("[[Get]] returns the correct name", () => {
762 assertStrictEquals(log10
.name
, "log10");
767 describe("log2", () => {
768 it("[[Call]] returns the log2", () => {
769 assertStrictEquals(log2(1), 0);
770 assertStrictEquals(log2(2), 1);
773 it("[[Call]] throws with big·ints", () => {
774 assertThrows(() => log2(1n
));
777 it("[[Construct]] throws an error", () => {
778 assertThrows(() => new log2(1));
781 describe(".length", () => {
782 it("[[Get]] returns the correct length", () => {
783 assertStrictEquals(log2
.length
, 1);
787 describe(".name", () => {
788 it("[[Get]] returns the correct name", () => {
789 assertStrictEquals(log2
.name
, "log2");
794 describe("max", () => {
795 it("[[Call]] returns the largest number", () => {
796 assertStrictEquals(max(1, -6, 92, -Infinity
, 0), 92);
799 it("[[Call]] returns the largest big·int", () => {
800 assertStrictEquals(max(1n
, -6n
, 92n
, 0n
), 92n
);
803 it("[[Call]] returns nan if any argument is nan", () => {
804 assertStrictEquals(max(0, NaN
, 1), NaN
);
807 it("[[Call]] returns -Infinity when called with no arguments", () => {
808 assertStrictEquals(max(), -Infinity
);
811 it("[[Call]] throws if both big·int and number arguments are provided", () => {
812 assertThrows(() => max(-Infinity
, 0n
));
815 it("[[Construct]] throws an error", () => {
816 assertThrows(() => new max(1, 0));
819 describe(".length", () => {
820 it("[[Get]] returns the correct length", () => {
821 assertStrictEquals(max
.length
, 2);
825 describe(".name", () => {
826 it("[[Get]] returns the correct name", () => {
827 assertStrictEquals(max
.name
, "max");
832 describe("min", () => {
833 it("[[Call]] returns the largest number", () => {
834 assertStrictEquals(min(1, -6, 92, Infinity
, 0), -6);
837 it("[[Call]] returns the largest big·int", () => {
838 assertStrictEquals(min(1n
, -6n
, 92n
, 0n
), -6n
);
841 it("[[Call]] returns nan if any argument is nan", () => {
842 assertStrictEquals(min(0, NaN
, 1), NaN
);
845 it("[[Call]] returns Infinity when called with no arguments", () => {
846 assertStrictEquals(min(), Infinity
);
849 it("[[Call]] throws if both big·int and number arguments are provided", () => {
850 assertThrows(() => min(Infinity
, 0n
));
853 it("[[Construct]] throws an error", () => {
854 assertThrows(() => new min(1, 0));
857 describe(".length", () => {
858 it("[[Get]] returns the correct length", () => {
859 assertStrictEquals(min
.length
, 2);
863 describe(".name", () => {
864 it("[[Get]] returns the correct name", () => {
865 assertStrictEquals(min
.name
, "min");
870 describe("rand", () => {
871 it("[[Call]] returns a random number between 0 and 1", () => {
872 // Not possible to fully test, obviously.
874 assert(typeof r
=== "number");
875 assert(r
>= 0 && r
< 1);
878 it("[[Construct]] throws an error", () => {
879 assertThrows(() => new rand());
882 describe(".length", () => {
883 it("[[Get]] returns the correct length", () => {
884 assertStrictEquals(rand
.length
, 0);
888 describe(".name", () => {
889 it("[[Get]] returns the correct name", () => {
890 assertStrictEquals(rand
.name
, "rand");
895 describe("round", () => {
896 it("[[Call]] returns the round", () => {
897 assertStrictEquals(round(1), 1);
898 assertStrictEquals(round(0.5), 1);
899 assertStrictEquals(round(-0.5), -0);
902 it("[[Call]] throws with big·ints", () => {
903 assertThrows(() => round(1n
));
906 it("[[Construct]] throws an error", () => {
907 assertThrows(() => new round(1));
910 describe(".length", () => {
911 it("[[Get]] returns the correct length", () => {
912 assertStrictEquals(round
.length
, 1);
916 describe(".name", () => {
917 it("[[Get]] returns the correct name", () => {
918 assertStrictEquals(round
.name
, "round");
923 describe("sgn", () => {
924 it("[[Call]] returns the sign", () => {
925 assertStrictEquals(sgn(Infinity
), 1);
926 assertStrictEquals(sgn(-Infinity
), -1);
927 assertStrictEquals(sgn(0), 0);
928 assertStrictEquals(sgn(-0), -0);
929 assertStrictEquals(sgn(NaN
), NaN
);
932 it("[[Call]] works with big·ints", () => {
933 assertStrictEquals(sgn(0n
), 0n
);
934 assertStrictEquals(sgn(92n
), 1n
);
935 assertStrictEquals(sgn(-92n
), -1n
);
938 it("[[Construct]] throws an error", () => {
939 assertThrows(() => new sgn(1));
942 describe(".length", () => {
943 it("[[Get]] returns the correct length", () => {
944 assertStrictEquals(sgn
.length
, 1);
948 describe(".name", () => {
949 it("[[Get]] returns the correct name", () => {
950 assertStrictEquals(sgn
.name
, "sgn");
955 describe("sin", () => {
956 it("[[Call]] returns the sin", () => {
957 assertStrictEquals(sin(1), Math
.sin(1));
958 assertStrictEquals(sin(0), 0);
961 it("[[Call]] throws with big·ints", () => {
962 assertThrows(() => sin(1n
));
965 it("[[Construct]] throws an error", () => {
966 assertThrows(() => new sin(1));
969 describe(".length", () => {
970 it("[[Get]] returns the correct length", () => {
971 assertStrictEquals(sin
.length
, 1);
975 describe(".name", () => {
976 it("[[Get]] returns the correct name", () => {
977 assertStrictEquals(sin
.name
, "sin");
982 describe("sinh", () => {
983 it("[[Call]] returns the sinh", () => {
984 assertStrictEquals(sinh(1), Math
.sinh(1));
985 assertStrictEquals(sinh(0), 0);
988 it("[[Call]] throws with big·ints", () => {
989 assertThrows(() => sinh(1n
));
992 it("[[Construct]] throws an error", () => {
993 assertThrows(() => new sinh(1));
996 describe(".length", () => {
997 it("[[Get]] returns the correct length", () => {
998 assertStrictEquals(sinh
.length
, 1);
1002 describe(".name", () => {
1003 it("[[Get]] returns the correct name", () => {
1004 assertStrictEquals(sinh
.name
, "sinh");
1009 describe("sqrt", () => {
1010 it("[[Call]] returns the sqrt", () => {
1011 assertStrictEquals(sqrt(1), 1);
1012 assertStrictEquals(sqrt(2), Math
.SQRT2
);
1015 it("[[Call]] throws with big·ints", () => {
1016 assertThrows(() => sqrt(1n
));
1019 it("[[Construct]] throws an error", () => {
1020 assertThrows(() => new sqrt(1));
1023 describe(".length", () => {
1024 it("[[Get]] returns the correct length", () => {
1025 assertStrictEquals(sqrt
.length
, 1);
1029 describe(".name", () => {
1030 it("[[Get]] returns the correct name", () => {
1031 assertStrictEquals(sqrt
.name
, "sqrt");
1036 describe("tan", () => {
1037 it("[[Call]] returns the tan", () => {
1038 assertStrictEquals(tan(1), Math
.tan(1));
1039 assertStrictEquals(tan(0), 0);
1042 it("[[Call]] throws with big·ints", () => {
1043 assertThrows(() => tan(1n
));
1046 it("[[Construct]] throws an error", () => {
1047 assertThrows(() => new tan(1));
1050 describe(".length", () => {
1051 it("[[Get]] returns the correct length", () => {
1052 assertStrictEquals(tan
.length
, 1);
1056 describe(".name", () => {
1057 it("[[Get]] returns the correct name", () => {
1058 assertStrictEquals(tan
.name
, "tan");
1063 describe("tanh", () => {
1064 it("[[Call]] returns the tanh", () => {
1065 assertStrictEquals(tanh(1), Math
.tanh(1));
1066 assertStrictEquals(tanh(0), 0);
1069 it("[[Call]] throws with big·ints", () => {
1070 assertThrows(() => tanh(1n
));
1073 it("[[Construct]] throws an error", () => {
1074 assertThrows(() => new tanh(1));
1077 describe(".length", () => {
1078 it("[[Get]] returns the correct length", () => {
1079 assertStrictEquals(tanh
.length
, 1);
1083 describe(".name", () => {
1084 it("[[Get]] returns the correct name", () => {
1085 assertStrictEquals(tanh
.name
, "tanh");
1090 describe("toBigInt", () => {
1091 it("[[Call]] converts to a big·int", () => {
1092 assertStrictEquals(toBigInt(2), 2n
);
1095 it("[[Construct]] throws an error", () => {
1096 assertThrows(() => new toBigInt(1));
1099 describe(".length", () => {
1100 it("[[Get]] returns the correct length", () => {
1101 assertStrictEquals(toBigInt
.length
, 1);
1105 describe(".name", () => {
1106 it("[[Get]] returns the correct name", () => {
1107 assertStrictEquals(toBigInt
.name
, "toBigInt");
1112 describe("toExponentialNotation", () => {
1113 it("[[Call]] converts to exponential notation", () => {
1114 assertStrictEquals(toExponentialNotation(231), "2.31e+2");
1117 it("[[Call]] works with big·ints", () => {
1119 toExponentialNotation(9007199254740993n
),
1120 "9.007199254740993e+15",
1124 it("[[Call]] respects the specified number of fractional digits", () => {
1126 toExponentialNotation(.00000000642, 3),
1129 assertStrictEquals(toExponentialNotation(.00691, 1), "6.9e-3");
1130 assertStrictEquals(toExponentialNotation(.00685, 1), "6.9e-3");
1131 assertStrictEquals(toExponentialNotation(.004199, 2), "4.20e-3");
1133 toExponentialNotation(6420000000n
, 3),
1136 assertStrictEquals(toExponentialNotation(6910n
, 1), "6.9e+3");
1137 assertStrictEquals(toExponentialNotation(6850n
, 1), "6.9e+3");
1138 assertStrictEquals(toExponentialNotation(4199n
, 2), "4.20e+3");
1141 it("[[Construct]] throws an error", () => {
1142 assertThrows(() => new toExponentialNotation(1, 1));
1145 describe(".length", () => {
1146 it("[[Get]] returns the correct length", () => {
1147 assertStrictEquals(toExponentialNotation
.length
, 2);
1151 describe(".name", () => {
1152 it("[[Get]] returns the correct name", () => {
1154 toExponentialNotation
.name
,
1155 "toExponentialNotation",
1161 describe("toFixedDecimalNotation", () => {
1162 it("[[Call]] converts to fixed decimal notation", () => {
1163 assertStrictEquals(toFixedDecimalNotation(69.4199, 3), "69.420");
1166 it("[[Call]] works with big·ints", () => {
1168 toFixedDecimalNotation(9007199254740993n
),
1172 toFixedDecimalNotation(9007199254740993n
, 2),
1173 "9007199254740993.00",
1177 it("[[Construct]] throws an error", () => {
1178 assertThrows(() => new toFixedDecimalNotation(1, 1));
1181 describe(".length", () => {
1182 it("[[Get]] returns the correct length", () => {
1183 assertStrictEquals(toFixedDecimalNotation
.length
, 2);
1187 describe(".name", () => {
1188 it("[[Get]] returns the correct name", () => {
1190 toFixedDecimalNotation
.name
,
1191 "toFixedDecimalNotation",
1197 describe("toFloat32", () => {
1198 it("[[Call]] returns the 32‐bit floating‐point representation", () => {
1200 toFloat32(562949953421313),
1201 Math
.fround(562949953421313),
1205 it("[[Call]] works with big·ints", () => {
1207 toFloat32(562949953421313n
),
1208 Math
.fround(562949953421313),
1212 it("[[Construct]] throws an error", () => {
1213 assertThrows(() => new toFloat32(1));
1216 describe(".length", () => {
1217 it("[[Get]] returns the correct length", () => {
1218 assertStrictEquals(toFloat32
.length
, 1);
1222 describe(".name", () => {
1223 it("[[Get]] returns the correct name", () => {
1224 assertStrictEquals(toFloat32
.name
, "toFloat32");
1229 describe("toSignedIntegralNumeric", () => {
1230 it("[[Call]] converts to an int·n", () => {
1231 assertStrictEquals(toSignedIntegralNumeric(2, 7n
), -1n
);
1234 it("[[Call]] works with numbers", () => {
1235 assertStrictEquals(toSignedIntegralNumeric(2, 7), -1);
1238 it("[[Call]] works with non‐integers", () => {
1239 assertStrictEquals(toSignedIntegralNumeric(2, 7.21), -1);
1240 assertStrictEquals(toSignedIntegralNumeric(2, Infinity
), 0);
1243 it("[[Construct]] throws an error", () => {
1244 assertThrows(() => new toSignedIntegralNumeric(1, 1));
1247 describe(".length", () => {
1248 it("[[Get]] returns the correct length", () => {
1249 assertStrictEquals(toSignedIntegralNumeric
.length
, 2);
1253 describe(".name", () => {
1254 it("[[Get]] returns the correct name", () => {
1256 toSignedIntegralNumeric
.name
,
1257 "toSignedIntegralNumeric",
1263 describe("toIntegralNumber", () => {
1264 it("[[Call]] converts nan to zero", () => {
1265 assertStrictEquals(toIntegralNumber(NaN
), 0);
1268 it("[[Call]] converts negative zero to positive zero", () => {
1269 assertStrictEquals(toIntegralNumber(-0), 0);
1272 it("[[Call]] drops the fractional part of negative numbers", () => {
1273 assertStrictEquals(toIntegralNumber(-1.79), -1);
1276 it("[[Call]] returns zero for infinity", () => {
1277 assertStrictEquals(toIntegralNumber(Infinity
), 0);
1280 it("[[Call]] returns zero for negative infinity", () => {
1281 assertStrictEquals(toIntegralNumber(-Infinity
), 0);
1284 it("[[Call]] works with big·ints", () => {
1285 assertStrictEquals(toIntegralNumber(2n
), 2);
1288 it("[[Construct]] throws an error", () => {
1289 assertThrows(() => new toIntegralNumber(1));
1292 describe(".length", () => {
1293 it("[[Get]] returns the correct length", () => {
1294 assertStrictEquals(toIntegralNumber
.length
, 1);
1298 describe(".name", () => {
1299 it("[[Get]] returns the correct name", () => {
1300 assertStrictEquals(toIntegralNumber
.name
, "toIntegralNumber");
1305 describe("toIntegralNumberOrInfinity", () => {
1306 it("[[Call]] converts nan to zero", () => {
1307 assertStrictEquals(toIntegralNumberOrInfinity(NaN
), 0);
1310 it("[[Call]] converts negative zero to positive zero", () => {
1311 assertStrictEquals(toIntegralNumberOrInfinity(-0), 0);
1314 it("[[Call]] drops the fractional part of negative numbers", () => {
1315 assertStrictEquals(toIntegralNumberOrInfinity(-1.79), -1);
1318 it("[[Call]] returns infinity for infinity", () => {
1319 assertStrictEquals(toIntegralNumberOrInfinity(Infinity
), Infinity
);
1322 it("[[Call]] returns negative infinity for negative infinity", () => {
1324 toIntegralNumberOrInfinity(-Infinity
),
1329 it("[[Call]] works with big·ints", () => {
1330 assertStrictEquals(toIntegralNumberOrInfinity(2n
), 2);
1333 it("[[Construct]] throws an error", () => {
1334 assertThrows(() => new toIntegralNumberOrInfinity(1));
1337 describe(".length", () => {
1338 it("[[Get]] returns the correct length", () => {
1339 assertStrictEquals(toIntegralNumberOrInfinity
.length
, 1);
1343 describe(".name", () => {
1344 it("[[Get]] returns the correct name", () => {
1346 toIntegralNumberOrInfinity
.name
,
1347 "toIntegralNumberOrInfinity",
1353 describe("toNumber", () => {
1354 it("[[Call]] converts to a number", () => {
1355 assertStrictEquals(toNumber(2n
), 2);
1358 it("[[Construct]] throws an error", () => {
1359 assertThrows(() => new toNumber(1));
1362 describe(".length", () => {
1363 it("[[Get]] returns the correct length", () => {
1364 assertStrictEquals(toNumber
.length
, 1);
1368 describe(".name", () => {
1369 it("[[Get]] returns the correct name", () => {
1370 assertStrictEquals(toNumber
.name
, "toNumber");
1375 describe("toNumeric", () => {
1376 it("[[Call]] returns a big·int argument", () => {
1377 assertStrictEquals(toNumeric(231n
), 231n
);
1380 it("[[Call]] converts to a numeric", () => {
1381 assertStrictEquals(toNumeric("231"), 231);
1384 it("[[Call]] prefers `valueOf`", () => {
1398 it("[[Construct]] throws an error", () => {
1399 assertThrows(() => new toNumeric(1));
1402 describe(".length", () => {
1403 it("[[Get]] returns the correct length", () => {
1404 assertStrictEquals(toNumeric
.length
, 1);
1408 describe(".name", () => {
1409 it("[[Get]] returns the correct name", () => {
1410 assertStrictEquals(toNumeric
.name
, "toNumeric");
1415 describe("toUnsignedIntegralNumeric", () => {
1416 it("[[Call]] converts to an int·n", () => {
1417 assertStrictEquals(toUnsignedIntegralNumeric(2, 7n
), 3n
);
1420 it("[[Call]] works with numbers", () => {
1421 assertStrictEquals(toUnsignedIntegralNumeric(2, 7), 3);
1424 it("[[Call]] works with non‐integers", () => {
1425 assertStrictEquals(toUnsignedIntegralNumeric(2, 7.21), 3);
1426 assertStrictEquals(toUnsignedIntegralNumeric(2, Infinity
), 0);
1429 it("[[Construct]] throws an error", () => {
1430 assertThrows(() => new toUnsignedIntegralNumeric(1, 1));
1433 describe(".length", () => {
1434 it("[[Get]] returns the correct length", () => {
1435 assertStrictEquals(toUnsignedIntegralNumeric
.length
, 2);
1439 describe(".name", () => {
1440 it("[[Get]] returns the correct name", () => {
1442 toUnsignedIntegralNumeric
.name
,
1443 "toUnsignedIntegralNumeric",
1449 describe("trunc", () => {
1450 it("[[Call]] returns the trunc", () => {
1451 assertStrictEquals(trunc(1), 1);
1452 assertStrictEquals(trunc(0.5), 0);
1453 assertStrictEquals(trunc(-0.5), -0);
1456 it("[[Call]] throws with big·ints", () => {
1457 assertThrows(() => trunc(1n
));
1460 it("[[Construct]] throws an error", () => {
1461 assertThrows(() => new trunc(1));
1464 describe(".length", () => {
1465 it("[[Get]] returns the correct length", () => {
1466 assertStrictEquals(trunc
.length
, 1);
1470 describe(".name", () => {
1471 it("[[Get]] returns the correct name", () => {
1472 assertStrictEquals(trunc
.name
, "trunc");