1 // ♓🌟 Piscēs ∷ numeric.test.js
2 // ====================================================================
4 // Copyright © 2022–2023 Lady [@ Lady’s Computer].
6 // This Source Code Form is subject to the terms of the Mozilla Public
7 // License, v. 2.0. If a copy of the MPL was not distributed with this
8 // file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
16 } from "./dev-deps.js";
54 toExponentialNotation
,
55 toFixedDecimalNotation
,
58 toIntegralNumberOrInfinity
,
61 toSignedIntegralNumeric
,
62 toUnsignedIntegralNumeric
,
64 } from "./numeric.js";
66 describe("abs", () => {
67 it("[[Call]] returns the absolute value", () => {
68 assertStrictEquals(abs(-1), 1);
71 it("[[Call]] works with big·ints", () => {
72 const bn
= BigInt(Number
.MAX_SAFE_INTEGER
) + 2n
;
73 assertStrictEquals(abs(-bn
), bn
);
76 it("[[Construct]] throws an error", () => {
77 assertThrows(() => new abs(0));
80 describe(".length", () => {
81 it("[[Get]] returns the correct length", () => {
82 assertStrictEquals(abs
.length
, 1);
86 describe(".name", () => {
87 it("[[Get]] returns the correct name", () => {
88 assertStrictEquals(abs
.name
, "abs");
93 describe("arccos", () => {
94 it("[[Call]] returns the arccos", () => {
95 assertStrictEquals(arccos(1), 0);
96 assertStrictEquals(arccos(0), Math
.PI
/ 2);
99 it("[[Call]] throws with big·ints", () => {
100 assertThrows(() => arccos(1n
));
103 it("[[Construct]] throws an error", () => {
104 assertThrows(() => new arccos(1));
107 describe(".length", () => {
108 it("[[Get]] returns the correct length", () => {
109 assertStrictEquals(arccos
.length
, 1);
113 describe(".name", () => {
114 it("[[Get]] returns the correct name", () => {
115 assertStrictEquals(arccos
.name
, "arccos");
120 describe("arccosh", () => {
121 it("[[Call]] returns the arccosh", () => {
122 assertStrictEquals(arccosh(1), 0);
123 assertStrictEquals(arccosh(0), NaN
);
126 it("[[Call]] throws with big·ints", () => {
127 assertThrows(() => arccosh(1n
));
130 it("[[Construct]] throws an error", () => {
131 assertThrows(() => new arccosh(1));
134 describe(".length", () => {
135 it("[[Get]] returns the correct length", () => {
136 assertStrictEquals(arccosh
.length
, 1);
140 describe(".name", () => {
141 it("[[Get]] returns the correct name", () => {
142 assertStrictEquals(arccosh
.name
, "arccosh");
147 describe("arcsin", () => {
148 it("[[Call]] returns the arcsin", () => {
149 assertStrictEquals(arcsin(1), Math
.PI
/ 2);
150 assertStrictEquals(arcsin(0), 0);
153 it("[[Call]] throws with big·ints", () => {
154 assertThrows(() => arcsin(1n
));
157 it("[[Construct]] throws an error", () => {
158 assertThrows(() => new arcsin(1));
161 describe(".length", () => {
162 it("[[Get]] returns the correct length", () => {
163 assertStrictEquals(arcsin
.length
, 1);
167 describe(".name", () => {
168 it("[[Get]] returns the correct name", () => {
169 assertStrictEquals(arcsin
.name
, "arcsin");
174 describe("arcsinh", () => {
175 it("[[Call]] returns the arcsinh", () => {
176 assertStrictEquals(arcsinh(1), Math
.asinh(1));
177 assertStrictEquals(arcsinh(0), 0);
180 it("[[Call]] throws with big·ints", () => {
181 assertThrows(() => arcsinh(1n
));
184 it("[[Construct]] throws an error", () => {
185 assertThrows(() => new arcsinh(1));
188 describe(".length", () => {
189 it("[[Get]] returns the correct length", () => {
190 assertStrictEquals(arcsinh
.length
, 1);
194 describe(".name", () => {
195 it("[[Get]] returns the correct name", () => {
196 assertStrictEquals(arcsinh
.name
, "arcsinh");
201 describe("arctan", () => {
202 it("[[Call]] returns the arctan", () => {
203 assertStrictEquals(arctan(1), Math
.PI
/ 4);
204 assertStrictEquals(arctan(0), 0);
207 it("[[Call]] throws with big·ints", () => {
208 assertThrows(() => arctan(1n
));
211 it("[[Construct]] throws an error", () => {
212 assertThrows(() => new arctan(1));
215 describe(".length", () => {
216 it("[[Get]] returns the correct length", () => {
217 assertStrictEquals(arctan
.length
, 1);
221 describe(".name", () => {
222 it("[[Get]] returns the correct name", () => {
223 assertStrictEquals(arctan
.name
, "arctan");
228 describe("arctan2", () => {
229 it("[[Call]] returns the arctan2", () => {
230 assertStrictEquals(arctan2(6, 9), Math
.atan2(6, 9));
233 it("[[Call]] works with big·ints", () => {
234 assertStrictEquals(arctan2(6n
, 9n
), Math
.atan2(6, 9));
237 it("[[Construct]] throws an error", () => {
238 assertThrows(() => new arctan2(1, 0));
241 describe(".length", () => {
242 it("[[Get]] returns the correct length", () => {
243 assertStrictEquals(arctan2
.length
, 2);
247 describe(".name", () => {
248 it("[[Get]] returns the correct name", () => {
249 assertStrictEquals(arctan2
.name
, "arctan2");
254 describe("arctanh", () => {
255 it("[[Call]] returns the arctanh", () => {
256 assertStrictEquals(arctanh(1), Infinity
);
257 assertStrictEquals(arctanh(0), 0);
260 it("[[Call]] throws with big·ints", () => {
261 assertThrows(() => arctanh(1n
));
264 it("[[Construct]] throws an error", () => {
265 assertThrows(() => new arctanh(1));
268 describe(".length", () => {
269 it("[[Get]] returns the correct length", () => {
270 assertStrictEquals(arctanh
.length
, 1);
274 describe(".name", () => {
275 it("[[Get]] returns the correct name", () => {
276 assertStrictEquals(arctanh
.name
, "arctanh");
281 describe("cbrt", () => {
282 it("[[Call]] returns the cbrt", () => {
283 assertStrictEquals(cbrt(1), 1);
284 assertStrictEquals(cbrt(2), Math
.cbrt(2));
287 it("[[Call]] throws with big·ints", () => {
288 assertThrows(() => cbrt(1n
));
291 it("[[Construct]] throws an error", () => {
292 assertThrows(() => new cbrt(1));
295 describe(".length", () => {
296 it("[[Get]] returns the correct length", () => {
297 assertStrictEquals(cbrt
.length
, 1);
301 describe(".name", () => {
302 it("[[Get]] returns the correct name", () => {
303 assertStrictEquals(cbrt
.name
, "cbrt");
308 describe("ceil", () => {
309 it("[[Call]] returns the ceil", () => {
310 assertStrictEquals(ceil(1), 1);
311 assertStrictEquals(ceil(1.1), 2);
314 it("[[Call]] throws with big·ints", () => {
315 assertThrows(() => ceil(1n
));
318 it("[[Construct]] throws an error", () => {
319 assertThrows(() => new ceil(1));
322 describe(".length", () => {
323 it("[[Get]] returns the correct length", () => {
324 assertStrictEquals(ceil
.length
, 1);
328 describe(".name", () => {
329 it("[[Get]] returns the correct name", () => {
330 assertStrictEquals(ceil
.name
, "ceil");
335 describe("clz32", () => {
336 it("[[Call]] returns the clz32", () => {
337 assertStrictEquals(clz32(1 << 28), 3);
340 it("[[Call]] works with big·ints", () => {
341 assertStrictEquals(clz32(1n
<< 28n
), 3);
344 it("[[Construct]] throws an error", () => {
345 assertThrows(() => new clz32(1));
348 describe(".length", () => {
349 it("[[Get]] returns the correct length", () => {
350 assertStrictEquals(clz32
.length
, 1);
354 describe(".name", () => {
355 it("[[Get]] returns the correct name", () => {
356 assertStrictEquals(clz32
.name
, "clz32");
361 describe("cos", () => {
362 it("[[Call]] returns the cos", () => {
363 assertStrictEquals(cos(1), Math
.cos(1));
364 assertStrictEquals(cos(0), 1);
367 it("[[Call]] throws with big·ints", () => {
368 assertThrows(() => cos(1n
));
371 it("[[Construct]] throws an error", () => {
372 assertThrows(() => new cos(1));
375 describe(".length", () => {
376 it("[[Get]] returns the correct length", () => {
377 assertStrictEquals(cos
.length
, 1);
381 describe(".name", () => {
382 it("[[Get]] returns the correct name", () => {
383 assertStrictEquals(cos
.name
, "cos");
388 describe("cosh", () => {
389 it("[[Call]] returns the cosh", () => {
390 assertStrictEquals(cosh(1), Math
.cosh(1));
391 assertStrictEquals(cosh(0), 1);
394 it("[[Call]] throws with big·ints", () => {
395 assertThrows(() => cosh(1n
));
398 it("[[Construct]] throws an error", () => {
399 assertThrows(() => new cosh(1));
402 describe(".length", () => {
403 it("[[Get]] returns the correct length", () => {
404 assertStrictEquals(cosh
.length
, 1);
408 describe(".name", () => {
409 it("[[Get]] returns the correct name", () => {
410 assertStrictEquals(cosh
.name
, "cosh");
415 describe("exp", () => {
416 it("[[Call]] returns the exp", () => {
417 assertStrictEquals(exp(1), Math
.E
);
418 assertStrictEquals(exp(0), 1);
421 it("[[Call]] throws with big·ints", () => {
422 assertThrows(() => exp(1n
));
425 it("[[Construct]] throws an error", () => {
426 assertThrows(() => new exp(1));
429 describe(".length", () => {
430 it("[[Get]] returns the correct length", () => {
431 assertStrictEquals(exp
.length
, 1);
435 describe(".name", () => {
436 it("[[Get]] returns the correct name", () => {
437 assertStrictEquals(exp
.name
, "exp");
442 describe("expm1", () => {
443 it("[[Call]] returns the expm1", () => {
444 assertStrictEquals(expm1(1), Math
.E
- 1);
445 assertStrictEquals(expm1(0), 0);
448 it("[[Call]] throws with big·ints", () => {
449 assertThrows(() => expm1(1n
));
452 it("[[Construct]] throws an error", () => {
453 assertThrows(() => new expm1(1));
456 describe(".length", () => {
457 it("[[Get]] returns the correct length", () => {
458 assertStrictEquals(expm1
.length
, 1);
462 describe(".name", () => {
463 it("[[Get]] returns the correct name", () => {
464 assertStrictEquals(expm1
.name
, "expm1");
469 describe("floor", () => {
470 it("[[Call]] returns the floor", () => {
471 assertStrictEquals(floor(1), 1);
472 assertStrictEquals(floor(0.1), 0);
475 it("[[Call]] throws with big·ints", () => {
476 assertThrows(() => floor(1n
));
479 it("[[Construct]] throws an error", () => {
480 assertThrows(() => new floor(1));
483 describe(".length", () => {
484 it("[[Get]] returns the correct length", () => {
485 assertStrictEquals(floor
.length
, 1);
489 describe(".name", () => {
490 it("[[Get]] returns the correct name", () => {
491 assertStrictEquals(floor
.name
, "floor");
496 describe("hypot", () => {
497 it("[[Call]] returns the floor", () => {
498 assertStrictEquals(hypot(1, 0), 1);
499 assertStrictEquals(hypot(3, 4), 5);
502 it("[[Call]] throws with big·ints", () => {
503 assertThrows(() => hypot(1n
, 0n
));
506 it("[[Construct]] throws an error", () => {
507 assertThrows(() => new hypot(1, 0));
510 describe(".length", () => {
511 it("[[Get]] returns the correct length", () => {
512 assertStrictEquals(hypot
.length
, 2);
516 describe(".name", () => {
517 it("[[Get]] returns the correct name", () => {
518 assertStrictEquals(hypot
.name
, "hypot");
523 describe("isFiniteNumber", () => {
524 it("[[Call]] returns true for finite numbers", () => {
525 assertStrictEquals(isFiniteNumber(1), true);
526 assertStrictEquals(isFiniteNumber(Number
.MAX_VALUE
), true);
527 assertStrictEquals(isFiniteNumber(Number
.EPSILON
), true);
530 it("[[Call]] returns false for nonfinite numbers", () => {
531 assertStrictEquals(isFiniteNumber(NaN
), false);
532 assertStrictEquals(isFiniteNumber(Infinity
), false);
535 it("[[Call]] returns false for nonnumbers", () => {
536 assertStrictEquals(isFiniteNumber(1n
), false);
537 assertStrictEquals(isFiniteNumber("1"), false);
540 it("[[Construct]] throws an error", () => {
541 assertThrows(() => new isFiniteNumber(1));
544 describe(".length", () => {
545 it("[[Get]] returns the correct length", () => {
546 assertStrictEquals(isFiniteNumber
.length
, 1);
550 describe(".name", () => {
551 it("[[Get]] returns the correct name", () => {
552 assertStrictEquals(isFiniteNumber
.name
, "isFiniteNumber");
557 describe("isIntegralNumber", () => {
558 it("[[Call]] returns true for integral numbers", () => {
559 assertStrictEquals(isIntegralNumber(1), true);
560 assertStrictEquals(isIntegralNumber(Number
.MAX_VALUE
), true);
563 it("[[Call]] returns false for nonfinite numbers", () => {
564 assertStrictEquals(isIntegralNumber(NaN
), false);
565 assertStrictEquals(isIntegralNumber(Infinity
), false);
568 it("[[Call]] returns false for nonintegral numbers", () => {
569 assertStrictEquals(isIntegralNumber(.1), false);
570 assertStrictEquals(isIntegralNumber(Number
.EPSILON
), false);
573 it("[[Call]] returns false for nonnumbers", () => {
574 assertStrictEquals(isIntegralNumber(1n
), false);
575 assertStrictEquals(isIntegralNumber("1"), false);
578 it("[[Construct]] throws an error", () => {
579 assertThrows(() => new isIntegralNumber(1));
582 describe(".length", () => {
583 it("[[Get]] returns the correct length", () => {
584 assertStrictEquals(isIntegralNumber
.length
, 1);
588 describe(".name", () => {
589 it("[[Get]] returns the correct name", () => {
590 assertStrictEquals(isIntegralNumber
.name
, "isIntegralNumber");
595 describe("isNan", () => {
596 it("[[Call]] returns true for nan", () => {
597 assertStrictEquals(isNan(NaN
), true);
600 it("[[Call]] returns false for infinite numbers", () => {
601 assertStrictEquals(isNan(-Infinity
), false);
602 assertStrictEquals(isNan(Infinity
), false);
605 it("[[Call]] returns false for finite numbers", () => {
606 assertStrictEquals(isNan(1), false);
607 assertStrictEquals(isNan(Number
.MAX_VALUE
), false);
608 assertStrictEquals(isNan(.1), false);
609 assertStrictEquals(isNan(Number
.EPSILON
), false);
612 it("[[Call]] returns false for nonnumbers", () => {
613 assertStrictEquals(isNan(1n
), false);
614 assertStrictEquals(isNan("NaN"), false);
615 assertStrictEquals(isNan({}), false);
616 assertStrictEquals(isNan(new Date(NaN
)), false);
619 it("[[Construct]] throws an error", () => {
620 assertThrows(() => new isNan(1));
623 describe(".length", () => {
624 it("[[Get]] returns the correct length", () => {
625 assertStrictEquals(isNan
.length
, 1);
629 describe(".name", () => {
630 it("[[Get]] returns the correct name", () => {
631 assertStrictEquals(isNan
.name
, "isNan");
636 describe("isSafeIntegralNumber", () => {
637 it("[[Call]] returns true for safe integral numbers", () => {
638 assertStrictEquals(isSafeIntegralNumber(1), true);
640 isSafeIntegralNumber(Number
.MAX_SAFE_INTEGER
),
645 it("[[Call]] returns false for nonfinite numbers", () => {
646 assertStrictEquals(isSafeIntegralNumber(NaN
), false);
647 assertStrictEquals(isSafeIntegralNumber(Infinity
), false);
650 it("[[Call]] returns false for nonintegral numbers", () => {
651 assertStrictEquals(isSafeIntegralNumber(.1), false);
652 assertStrictEquals(isSafeIntegralNumber(Number
.EPSILON
), false);
654 it("[[Call]] returns true for unsafe integral numbers", () => {
655 assertStrictEquals(isSafeIntegralNumber(Number
.MAX_VALUE
), false);
658 it("[[Call]] returns false for nonnumbers", () => {
659 assertStrictEquals(isSafeIntegralNumber(1n
), false);
660 assertStrictEquals(isSafeIntegralNumber("1"), false);
663 it("[[Construct]] throws an error", () => {
664 assertThrows(() => new isSafeIntegralNumber(1));
667 describe(".length", () => {
668 it("[[Get]] returns the correct length", () => {
669 assertStrictEquals(isSafeIntegralNumber
.length
, 1);
673 describe(".name", () => {
674 it("[[Get]] returns the correct name", () => {
676 isSafeIntegralNumber
.name
,
677 "isSafeIntegralNumber",
683 describe("ln", () => {
684 it("[[Call]] returns the ln", () => {
685 assertStrictEquals(ln(1), 0);
686 assertStrictEquals(ln(Math
.E
), 1);
689 it("[[Call]] throws with big·ints", () => {
690 assertThrows(() => ln(1n
));
693 it("[[Construct]] throws an error", () => {
694 assertThrows(() => new ln(1));
697 describe(".length", () => {
698 it("[[Get]] returns the correct length", () => {
699 assertStrictEquals(ln
.length
, 1);
703 describe(".name", () => {
704 it("[[Get]] returns the correct name", () => {
705 assertStrictEquals(ln
.name
, "ln");
710 describe("ln1p", () => {
711 it("[[Call]] returns the ln1p", () => {
712 assertStrictEquals(ln1p(1), Math
.log1p(1));
713 assertStrictEquals(ln1p(Math
.E
- 1), 1);
716 it("[[Call]] throws with big·ints", () => {
717 assertThrows(() => ln1p(1n
));
720 it("[[Construct]] throws an error", () => {
721 assertThrows(() => new ln1p(1));
724 describe(".length", () => {
725 it("[[Get]] returns the correct length", () => {
726 assertStrictEquals(ln1p
.length
, 1);
730 describe(".name", () => {
731 it("[[Get]] returns the correct name", () => {
732 assertStrictEquals(ln1p
.name
, "ln1p");
737 describe("log10", () => {
738 it("[[Call]] returns the log10", () => {
739 assertStrictEquals(log10(1), 0);
740 assertStrictEquals(log10(10), 1);
743 it("[[Call]] throws with big·ints", () => {
744 assertThrows(() => log10(1n
));
747 it("[[Construct]] throws an error", () => {
748 assertThrows(() => new log10(1));
751 describe(".length", () => {
752 it("[[Get]] returns the correct length", () => {
753 assertStrictEquals(log10
.length
, 1);
757 describe(".name", () => {
758 it("[[Get]] returns the correct name", () => {
759 assertStrictEquals(log10
.name
, "log10");
764 describe("log2", () => {
765 it("[[Call]] returns the log2", () => {
766 assertStrictEquals(log2(1), 0);
767 assertStrictEquals(log2(2), 1);
770 it("[[Call]] throws with big·ints", () => {
771 assertThrows(() => log2(1n
));
774 it("[[Construct]] throws an error", () => {
775 assertThrows(() => new log2(1));
778 describe(".length", () => {
779 it("[[Get]] returns the correct length", () => {
780 assertStrictEquals(log2
.length
, 1);
784 describe(".name", () => {
785 it("[[Get]] returns the correct name", () => {
786 assertStrictEquals(log2
.name
, "log2");
791 describe("max", () => {
792 it("[[Call]] returns the largest number", () => {
793 assertStrictEquals(max(1, -6, 92, -Infinity
, 0), 92);
796 it("[[Call]] returns the largest big·int", () => {
797 assertStrictEquals(max(1n
, -6n
, 92n
, 0n
), 92n
);
800 it("[[Call]] returns nan if any argument is nan", () => {
801 assertStrictEquals(max(0, NaN
, 1), NaN
);
804 it("[[Call]] returns -Infinity when called with no arguments", () => {
805 assertStrictEquals(max(), -Infinity
);
808 it("[[Call]] throws if both big·int and number arguments are provided", () => {
809 assertThrows(() => max(-Infinity
, 0n
));
812 it("[[Construct]] throws an error", () => {
813 assertThrows(() => new max(1, 0));
816 describe(".length", () => {
817 it("[[Get]] returns the correct length", () => {
818 assertStrictEquals(max
.length
, 2);
822 describe(".name", () => {
823 it("[[Get]] returns the correct name", () => {
824 assertStrictEquals(max
.name
, "max");
829 describe("min", () => {
830 it("[[Call]] returns the largest number", () => {
831 assertStrictEquals(min(1, -6, 92, Infinity
, 0), -6);
834 it("[[Call]] returns the largest big·int", () => {
835 assertStrictEquals(min(1n
, -6n
, 92n
, 0n
), -6n
);
838 it("[[Call]] returns nan if any argument is nan", () => {
839 assertStrictEquals(min(0, NaN
, 1), NaN
);
842 it("[[Call]] returns Infinity when called with no arguments", () => {
843 assertStrictEquals(min(), Infinity
);
846 it("[[Call]] throws if both big·int and number arguments are provided", () => {
847 assertThrows(() => min(Infinity
, 0n
));
850 it("[[Construct]] throws an error", () => {
851 assertThrows(() => new min(1, 0));
854 describe(".length", () => {
855 it("[[Get]] returns the correct length", () => {
856 assertStrictEquals(min
.length
, 2);
860 describe(".name", () => {
861 it("[[Get]] returns the correct name", () => {
862 assertStrictEquals(min
.name
, "min");
867 describe("rand", () => {
868 it("[[Call]] returns a random number between 0 and 1", () => {
869 // Not possible to fully test, obviously.
871 assert(typeof r
=== "number");
872 assert(r
>= 0 && r
< 1);
875 it("[[Construct]] throws an error", () => {
876 assertThrows(() => new rand());
879 describe(".length", () => {
880 it("[[Get]] returns the correct length", () => {
881 assertStrictEquals(rand
.length
, 0);
885 describe(".name", () => {
886 it("[[Get]] returns the correct name", () => {
887 assertStrictEquals(rand
.name
, "rand");
892 describe("round", () => {
893 it("[[Call]] returns the round", () => {
894 assertStrictEquals(round(1), 1);
895 assertStrictEquals(round(0.5), 1);
896 assertStrictEquals(round(-0.5), -0);
899 it("[[Call]] throws with big·ints", () => {
900 assertThrows(() => round(1n
));
903 it("[[Construct]] throws an error", () => {
904 assertThrows(() => new round(1));
907 describe(".length", () => {
908 it("[[Get]] returns the correct length", () => {
909 assertStrictEquals(round
.length
, 1);
913 describe(".name", () => {
914 it("[[Get]] returns the correct name", () => {
915 assertStrictEquals(round
.name
, "round");
920 describe("sgn", () => {
921 it("[[Call]] returns the sign", () => {
922 assertStrictEquals(sgn(Infinity
), 1);
923 assertStrictEquals(sgn(-Infinity
), -1);
924 assertStrictEquals(sgn(0), 0);
925 assertStrictEquals(sgn(-0), -0);
926 assertStrictEquals(sgn(NaN
), NaN
);
929 it("[[Call]] works with big·ints", () => {
930 assertStrictEquals(sgn(0n
), 0n
);
931 assertStrictEquals(sgn(92n
), 1n
);
932 assertStrictEquals(sgn(-92n
), -1n
);
935 it("[[Construct]] throws an error", () => {
936 assertThrows(() => new sgn(1));
939 describe(".length", () => {
940 it("[[Get]] returns the correct length", () => {
941 assertStrictEquals(sgn
.length
, 1);
945 describe(".name", () => {
946 it("[[Get]] returns the correct name", () => {
947 assertStrictEquals(sgn
.name
, "sgn");
952 describe("sin", () => {
953 it("[[Call]] returns the sin", () => {
954 assertStrictEquals(sin(1), Math
.sin(1));
955 assertStrictEquals(sin(0), 0);
958 it("[[Call]] throws with big·ints", () => {
959 assertThrows(() => sin(1n
));
962 it("[[Construct]] throws an error", () => {
963 assertThrows(() => new sin(1));
966 describe(".length", () => {
967 it("[[Get]] returns the correct length", () => {
968 assertStrictEquals(sin
.length
, 1);
972 describe(".name", () => {
973 it("[[Get]] returns the correct name", () => {
974 assertStrictEquals(sin
.name
, "sin");
979 describe("sinh", () => {
980 it("[[Call]] returns the sinh", () => {
981 assertStrictEquals(sinh(1), Math
.sinh(1));
982 assertStrictEquals(sinh(0), 0);
985 it("[[Call]] throws with big·ints", () => {
986 assertThrows(() => sinh(1n
));
989 it("[[Construct]] throws an error", () => {
990 assertThrows(() => new sinh(1));
993 describe(".length", () => {
994 it("[[Get]] returns the correct length", () => {
995 assertStrictEquals(sinh
.length
, 1);
999 describe(".name", () => {
1000 it("[[Get]] returns the correct name", () => {
1001 assertStrictEquals(sinh
.name
, "sinh");
1006 describe("sqrt", () => {
1007 it("[[Call]] returns the sqrt", () => {
1008 assertStrictEquals(sqrt(1), 1);
1009 assertStrictEquals(sqrt(2), Math
.SQRT2
);
1012 it("[[Call]] throws with big·ints", () => {
1013 assertThrows(() => sqrt(1n
));
1016 it("[[Construct]] throws an error", () => {
1017 assertThrows(() => new sqrt(1));
1020 describe(".length", () => {
1021 it("[[Get]] returns the correct length", () => {
1022 assertStrictEquals(sqrt
.length
, 1);
1026 describe(".name", () => {
1027 it("[[Get]] returns the correct name", () => {
1028 assertStrictEquals(sqrt
.name
, "sqrt");
1033 describe("tan", () => {
1034 it("[[Call]] returns the tan", () => {
1035 assertStrictEquals(tan(1), Math
.tan(1));
1036 assertStrictEquals(tan(0), 0);
1039 it("[[Call]] throws with big·ints", () => {
1040 assertThrows(() => tan(1n
));
1043 it("[[Construct]] throws an error", () => {
1044 assertThrows(() => new tan(1));
1047 describe(".length", () => {
1048 it("[[Get]] returns the correct length", () => {
1049 assertStrictEquals(tan
.length
, 1);
1053 describe(".name", () => {
1054 it("[[Get]] returns the correct name", () => {
1055 assertStrictEquals(tan
.name
, "tan");
1060 describe("tanh", () => {
1061 it("[[Call]] returns the tanh", () => {
1062 assertStrictEquals(tanh(1), Math
.tanh(1));
1063 assertStrictEquals(tanh(0), 0);
1066 it("[[Call]] throws with big·ints", () => {
1067 assertThrows(() => tanh(1n
));
1070 it("[[Construct]] throws an error", () => {
1071 assertThrows(() => new tanh(1));
1074 describe(".length", () => {
1075 it("[[Get]] returns the correct length", () => {
1076 assertStrictEquals(tanh
.length
, 1);
1080 describe(".name", () => {
1081 it("[[Get]] returns the correct name", () => {
1082 assertStrictEquals(tanh
.name
, "tanh");
1087 describe("toBigInt", () => {
1088 it("[[Call]] converts to a big·int", () => {
1089 assertStrictEquals(toBigInt(2), 2n
);
1092 it("[[Construct]] throws an error", () => {
1093 assertThrows(() => new toBigInt(1));
1096 describe(".length", () => {
1097 it("[[Get]] returns the correct length", () => {
1098 assertStrictEquals(toBigInt
.length
, 1);
1102 describe(".name", () => {
1103 it("[[Get]] returns the correct name", () => {
1104 assertStrictEquals(toBigInt
.name
, "toBigInt");
1109 describe("toExponentialNotation", () => {
1110 it("[[Call]] converts to exponential notation", () => {
1111 assertStrictEquals(toExponentialNotation(231), "2.31e+2");
1114 it("[[Call]] works with big·ints", () => {
1116 toExponentialNotation(9007199254740993n
),
1117 "9.007199254740993e+15",
1121 it("[[Call]] respects the specified number of fractional digits", () => {
1123 toExponentialNotation(.00000000642, 3),
1126 assertStrictEquals(toExponentialNotation(.00691, 1), "6.9e-3");
1127 assertStrictEquals(toExponentialNotation(.00685, 1), "6.9e-3");
1128 assertStrictEquals(toExponentialNotation(.004199, 2), "4.20e-3");
1130 toExponentialNotation(6420000000n
, 3),
1133 assertStrictEquals(toExponentialNotation(6910n
, 1), "6.9e+3");
1134 assertStrictEquals(toExponentialNotation(6850n
, 1), "6.9e+3");
1135 assertStrictEquals(toExponentialNotation(4199n
, 2), "4.20e+3");
1138 it("[[Construct]] throws an error", () => {
1139 assertThrows(() => new toExponentialNotation(1, 1));
1142 describe(".length", () => {
1143 it("[[Get]] returns the correct length", () => {
1144 assertStrictEquals(toExponentialNotation
.length
, 2);
1148 describe(".name", () => {
1149 it("[[Get]] returns the correct name", () => {
1151 toExponentialNotation
.name
,
1152 "toExponentialNotation",
1158 describe("toFixedDecimalNotation", () => {
1159 it("[[Call]] converts to fixed decimal notation", () => {
1160 assertStrictEquals(toFixedDecimalNotation(69.4199, 3), "69.420");
1163 it("[[Call]] works with big·ints", () => {
1165 toFixedDecimalNotation(9007199254740993n
),
1169 toFixedDecimalNotation(9007199254740993n
, 2),
1170 "9007199254740993.00",
1174 it("[[Construct]] throws an error", () => {
1175 assertThrows(() => new toFixedDecimalNotation(1, 1));
1178 describe(".length", () => {
1179 it("[[Get]] returns the correct length", () => {
1180 assertStrictEquals(toFixedDecimalNotation
.length
, 2);
1184 describe(".name", () => {
1185 it("[[Get]] returns the correct name", () => {
1187 toFixedDecimalNotation
.name
,
1188 "toFixedDecimalNotation",
1194 describe("toFloat32", () => {
1195 it("[[Call]] returns the 32‐bit floating‐point representation", () => {
1197 toFloat32(562949953421313),
1198 Math
.fround(562949953421313),
1202 it("[[Call]] works with big·ints", () => {
1204 toFloat32(562949953421313n
),
1205 Math
.fround(562949953421313),
1209 it("[[Construct]] throws an error", () => {
1210 assertThrows(() => new toFloat32(1));
1213 describe(".length", () => {
1214 it("[[Get]] returns the correct length", () => {
1215 assertStrictEquals(toFloat32
.length
, 1);
1219 describe(".name", () => {
1220 it("[[Get]] returns the correct name", () => {
1221 assertStrictEquals(toFloat32
.name
, "toFloat32");
1226 describe("toSignedIntegralNumeric", () => {
1227 it("[[Call]] converts to an int·n", () => {
1228 assertStrictEquals(toSignedIntegralNumeric(2, 7n
), -1n
);
1231 it("[[Call]] works with numbers", () => {
1232 assertStrictEquals(toSignedIntegralNumeric(2, 7), -1);
1235 it("[[Call]] works with non‐integers", () => {
1236 assertStrictEquals(toSignedIntegralNumeric(2, 7.21), -1);
1237 assertStrictEquals(toSignedIntegralNumeric(2, Infinity
), 0);
1240 it("[[Construct]] throws an error", () => {
1241 assertThrows(() => new toSignedIntegralNumeric(1, 1));
1244 describe(".length", () => {
1245 it("[[Get]] returns the correct length", () => {
1246 assertStrictEquals(toSignedIntegralNumeric
.length
, 2);
1250 describe(".name", () => {
1251 it("[[Get]] returns the correct name", () => {
1253 toSignedIntegralNumeric
.name
,
1254 "toSignedIntegralNumeric",
1260 describe("toIntegralNumber", () => {
1261 it("[[Call]] converts nan to zero", () => {
1262 assertStrictEquals(toIntegralNumber(NaN
), 0);
1265 it("[[Call]] converts negative zero to positive zero", () => {
1266 assertStrictEquals(toIntegralNumber(-0), 0);
1269 it("[[Call]] drops the fractional part of negative numbers", () => {
1270 assertStrictEquals(toIntegralNumber(-1.79), -1);
1273 it("[[Call]] returns zero for infinity", () => {
1274 assertStrictEquals(toIntegralNumber(Infinity
), 0);
1277 it("[[Call]] returns zero for negative infinity", () => {
1278 assertStrictEquals(toIntegralNumber(-Infinity
), 0);
1281 it("[[Call]] works with big·ints", () => {
1282 assertStrictEquals(toIntegralNumber(2n
), 2);
1285 it("[[Construct]] throws an error", () => {
1286 assertThrows(() => new toIntegralNumber(1));
1289 describe(".length", () => {
1290 it("[[Get]] returns the correct length", () => {
1291 assertStrictEquals(toIntegralNumber
.length
, 1);
1295 describe(".name", () => {
1296 it("[[Get]] returns the correct name", () => {
1297 assertStrictEquals(toIntegralNumber
.name
, "toIntegralNumber");
1302 describe("toIntegralNumberOrInfinity", () => {
1303 it("[[Call]] converts nan to zero", () => {
1304 assertStrictEquals(toIntegralNumberOrInfinity(NaN
), 0);
1307 it("[[Call]] converts negative zero to positive zero", () => {
1308 assertStrictEquals(toIntegralNumberOrInfinity(-0), 0);
1311 it("[[Call]] drops the fractional part of negative numbers", () => {
1312 assertStrictEquals(toIntegralNumberOrInfinity(-1.79), -1);
1315 it("[[Call]] returns infinity for infinity", () => {
1316 assertStrictEquals(toIntegralNumberOrInfinity(Infinity
), Infinity
);
1319 it("[[Call]] returns negative infinity for negative infinity", () => {
1321 toIntegralNumberOrInfinity(-Infinity
),
1326 it("[[Call]] works with big·ints", () => {
1327 assertStrictEquals(toIntegralNumberOrInfinity(2n
), 2);
1330 it("[[Construct]] throws an error", () => {
1331 assertThrows(() => new toIntegralNumberOrInfinity(1));
1334 describe(".length", () => {
1335 it("[[Get]] returns the correct length", () => {
1336 assertStrictEquals(toIntegralNumberOrInfinity
.length
, 1);
1340 describe(".name", () => {
1341 it("[[Get]] returns the correct name", () => {
1343 toIntegralNumberOrInfinity
.name
,
1344 "toIntegralNumberOrInfinity",
1350 describe("toNumber", () => {
1351 it("[[Call]] converts to a number", () => {
1352 assertStrictEquals(toNumber(2n
), 2);
1356 describe("toNumeric", () => {
1357 it("[[Call]] returns a big·int argument", () => {
1358 assertStrictEquals(toNumeric(231n
), 231n
);
1361 it("[[Call]] converts to a numeric", () => {
1362 assertStrictEquals(toNumeric("231"), 231);
1365 it("[[Call]] prefers `valueOf`", () => {
1379 it("[[Construct]] throws an error", () => {
1380 assertThrows(() => new toNumeric(1));
1383 describe(".length", () => {
1384 it("[[Get]] returns the correct length", () => {
1385 assertStrictEquals(toNumeric
.length
, 1);
1389 describe(".name", () => {
1390 it("[[Get]] returns the correct name", () => {
1391 assertStrictEquals(toNumeric
.name
, "toNumeric");
1396 describe("toUnsignedIntegralNumeric", () => {
1397 it("[[Call]] converts to an int·n", () => {
1398 assertStrictEquals(toUnsignedIntegralNumeric(2, 7n
), 3n
);
1401 it("[[Call]] works with numbers", () => {
1402 assertStrictEquals(toUnsignedIntegralNumeric(2, 7), 3);
1405 it("[[Call]] works with non‐integers", () => {
1406 assertStrictEquals(toUnsignedIntegralNumeric(2, 7.21), 3);
1407 assertStrictEquals(toUnsignedIntegralNumeric(2, Infinity
), 0);
1410 it("[[Construct]] throws an error", () => {
1411 assertThrows(() => new toUnsignedIntegralNumeric(1, 1));
1414 describe(".length", () => {
1415 it("[[Get]] returns the correct length", () => {
1416 assertStrictEquals(toUnsignedIntegralNumeric
.length
, 2);
1420 describe(".name", () => {
1421 it("[[Get]] returns the correct name", () => {
1423 toUnsignedIntegralNumeric
.name
,
1424 "toUnsignedIntegralNumeric",
1430 describe("trunc", () => {
1431 it("[[Call]] returns the trunc", () => {
1432 assertStrictEquals(trunc(1), 1);
1433 assertStrictEquals(trunc(0.5), 0);
1434 assertStrictEquals(trunc(-0.5), -0);
1437 it("[[Call]] throws with big·ints", () => {
1438 assertThrows(() => trunc(1n
));
1441 it("[[Construct]] throws an error", () => {
1442 assertThrows(() => new trunc(1));
1445 describe(".length", () => {
1446 it("[[Get]] returns the correct length", () => {
1447 assertStrictEquals(trunc
.length
, 1);
1451 describe(".name", () => {
1452 it("[[Get]] returns the correct name", () => {
1453 assertStrictEquals(trunc
.name
, "trunc");