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";
49 MAXIMUM_SAFE_INTEGRAL_NUMBER
,
52 MINIMUM_SAFE_INTEGRAL_NUMBER
,
69 toExponentialNotation
,
70 toFixedDecimalNotation
,
73 toIntegralNumberOrInfinity
,
76 toSignedIntegralNumeric
,
77 toUnsignedIntegralNumeric
,
82 } from "./numeric.js";
84 describe("LN10", () => {
85 it("[[Get]] is ln(10)", () => {
86 assertStrictEquals(LN10
, Math
.LN10
);
90 describe("LN2", () => {
91 it("[[Get]] is ln(2)", () => {
92 assertStrictEquals(LN2
, Math
.LN2
);
96 describe("LOG10ℇ", () => {
97 it("[[Get]] is log10(ℇ)", () => {
98 assertStrictEquals(LOG10
ℇ, Math
.LOG10E
);
102 describe("LOG2ℇ", () => {
103 it("[[Get]] is log2(ℇ)", () => {
104 assertStrictEquals(LOG2
ℇ, Math
.LOG2E
);
108 describe("MAXIMUM_NUMBER", () => {
109 it("[[Get]] is the maximum number", () => {
110 assertStrictEquals(MAXIMUM_NUMBER
, Number
.MAX_VALUE
);
114 describe("MAXIMUM_SAFE_INTEGRAL_NUMBER", () => {
115 it("[[Get]] is the maximum safe integral number", () => {
117 MAXIMUM_SAFE_INTEGRAL_NUMBER
,
118 Number
.MAX_SAFE_INTEGER
,
123 describe("MINIMUM_NUMBER", () => {
124 it("[[Get]] is the minimum number", () => {
125 assertStrictEquals(MINIMUM_NUMBER
, Number
.MIN_VALUE
);
129 describe("MINIMUM_SAFE_INTEGRAL_NUMBER", () => {
130 it("[[Get]] is the minimum safe integral number", () => {
132 MINIMUM_SAFE_INTEGRAL_NUMBER
,
133 Number
.MIN_SAFE_INTEGER
,
138 describe("NAN", () => {
139 it("[[Get]] is nan", () => {
140 assertStrictEquals(NAN
, NaN
);
144 describe("NEGATIVE_INFINITY", () => {
145 it("[[Get]] is negative infinity", () => {
146 assertStrictEquals(NEGATIVE_INFINITY
, -Infinity
);
150 describe("NEGATIVE_ZERO", () => {
151 it("[[Get]] is negative zero", () => {
152 assertStrictEquals(NEGATIVE_ZERO
, -0);
156 describe("POSITIVE_INFINITY", () => {
157 it("[[Get]] is negative infinity", () => {
158 assertStrictEquals(POSITIVE_INFINITY
, Infinity
);
162 describe("POSITIVE_ZERO", () => {
163 it("[[Get]] is positive zero", () => {
164 assertStrictEquals(POSITIVE_ZERO
, 0);
168 describe("RECIPROCAL_SQRT2", () => {
169 it("[[Get]] is sqrt(½)", () => {
170 assertStrictEquals(RECIPROCAL_SQRT2
, Math
.SQRT1_2
);
174 describe("SQRT2", () => {
175 it("[[Get]] is sqrt(2)", () => {
176 assertStrictEquals(SQRT2
, Math
.SQRT2
);
180 describe("Ε", () => {
181 it("[[Get]] is ε", () => {
182 assertStrictEquals(Ε, Number
.EPSILON
);
186 describe("Π", () => {
187 it("[[Get]] is π", () => {
188 assertStrictEquals(Π, Math
.PI
);
192 describe("ℇ", () => {
193 it("[[Get]] is ℇ", () => {
194 assertStrictEquals(ℇ, Math
.E
);
198 describe("abs", () => {
199 it("[[Call]] returns the absolute value", () => {
200 assertStrictEquals(abs(-1), 1);
203 it("[[Call]] works with big·ints", () => {
204 const bn
= BigInt(Number
.MAX_SAFE_INTEGER
) + 2n
;
205 assertStrictEquals(abs(-bn
), bn
);
208 it("[[Construct]] throws an error", () => {
209 assertThrows(() => new abs(0));
212 describe(".length", () => {
213 it("[[Get]] returns the correct length", () => {
214 assertStrictEquals(abs
.length
, 1);
218 describe(".name", () => {
219 it("[[Get]] returns the correct name", () => {
220 assertStrictEquals(abs
.name
, "abs");
225 describe("arccos", () => {
226 it("[[Call]] returns the arccos", () => {
227 assertStrictEquals(arccos(1), 0);
228 assertStrictEquals(arccos(0), Math
.PI
/ 2);
231 it("[[Call]] throws with big·ints", () => {
232 assertThrows(() => arccos(1n
));
235 it("[[Construct]] throws an error", () => {
236 assertThrows(() => new arccos(1));
239 describe(".length", () => {
240 it("[[Get]] returns the correct length", () => {
241 assertStrictEquals(arccos
.length
, 1);
245 describe(".name", () => {
246 it("[[Get]] returns the correct name", () => {
247 assertStrictEquals(arccos
.name
, "arccos");
252 describe("arccosh", () => {
253 it("[[Call]] returns the arccosh", () => {
254 assertStrictEquals(arccosh(1), 0);
255 assertStrictEquals(arccosh(0), NaN
);
258 it("[[Call]] throws with big·ints", () => {
259 assertThrows(() => arccosh(1n
));
262 it("[[Construct]] throws an error", () => {
263 assertThrows(() => new arccosh(1));
266 describe(".length", () => {
267 it("[[Get]] returns the correct length", () => {
268 assertStrictEquals(arccosh
.length
, 1);
272 describe(".name", () => {
273 it("[[Get]] returns the correct name", () => {
274 assertStrictEquals(arccosh
.name
, "arccosh");
279 describe("arcsin", () => {
280 it("[[Call]] returns the arcsin", () => {
281 assertStrictEquals(arcsin(1), Math
.PI
/ 2);
282 assertStrictEquals(arcsin(0), 0);
285 it("[[Call]] throws with big·ints", () => {
286 assertThrows(() => arcsin(1n
));
289 it("[[Construct]] throws an error", () => {
290 assertThrows(() => new arcsin(1));
293 describe(".length", () => {
294 it("[[Get]] returns the correct length", () => {
295 assertStrictEquals(arcsin
.length
, 1);
299 describe(".name", () => {
300 it("[[Get]] returns the correct name", () => {
301 assertStrictEquals(arcsin
.name
, "arcsin");
306 describe("arcsinh", () => {
307 it("[[Call]] returns the arcsinh", () => {
308 assertStrictEquals(arcsinh(1), Math
.asinh(1));
309 assertStrictEquals(arcsinh(0), 0);
312 it("[[Call]] throws with big·ints", () => {
313 assertThrows(() => arcsinh(1n
));
316 it("[[Construct]] throws an error", () => {
317 assertThrows(() => new arcsinh(1));
320 describe(".length", () => {
321 it("[[Get]] returns the correct length", () => {
322 assertStrictEquals(arcsinh
.length
, 1);
326 describe(".name", () => {
327 it("[[Get]] returns the correct name", () => {
328 assertStrictEquals(arcsinh
.name
, "arcsinh");
333 describe("arctan", () => {
334 it("[[Call]] returns the arctan", () => {
335 assertStrictEquals(arctan(1), Math
.PI
/ 4);
336 assertStrictEquals(arctan(0), 0);
339 it("[[Call]] throws with big·ints", () => {
340 assertThrows(() => arctan(1n
));
343 it("[[Construct]] throws an error", () => {
344 assertThrows(() => new arctan(1));
347 describe(".length", () => {
348 it("[[Get]] returns the correct length", () => {
349 assertStrictEquals(arctan
.length
, 1);
353 describe(".name", () => {
354 it("[[Get]] returns the correct name", () => {
355 assertStrictEquals(arctan
.name
, "arctan");
360 describe("arctan2", () => {
361 it("[[Call]] returns the arctan2", () => {
362 assertStrictEquals(arctan2(6, 9), Math
.atan2(6, 9));
365 it("[[Call]] works with big·ints", () => {
366 assertStrictEquals(arctan2(6n
, 9n
), Math
.atan2(6, 9));
369 it("[[Construct]] throws an error", () => {
370 assertThrows(() => new arctan2(1, 0));
373 describe(".length", () => {
374 it("[[Get]] returns the correct length", () => {
375 assertStrictEquals(arctan2
.length
, 2);
379 describe(".name", () => {
380 it("[[Get]] returns the correct name", () => {
381 assertStrictEquals(arctan2
.name
, "arctan2");
386 describe("arctanh", () => {
387 it("[[Call]] returns the arctanh", () => {
388 assertStrictEquals(arctanh(1), Infinity
);
389 assertStrictEquals(arctanh(0), 0);
392 it("[[Call]] throws with big·ints", () => {
393 assertThrows(() => arctanh(1n
));
396 it("[[Construct]] throws an error", () => {
397 assertThrows(() => new arctanh(1));
400 describe(".length", () => {
401 it("[[Get]] returns the correct length", () => {
402 assertStrictEquals(arctanh
.length
, 1);
406 describe(".name", () => {
407 it("[[Get]] returns the correct name", () => {
408 assertStrictEquals(arctanh
.name
, "arctanh");
413 describe("cbrt", () => {
414 it("[[Call]] returns the cbrt", () => {
415 assertStrictEquals(cbrt(1), 1);
416 assertStrictEquals(cbrt(2), Math
.cbrt(2));
419 it("[[Call]] throws with big·ints", () => {
420 assertThrows(() => cbrt(1n
));
423 it("[[Construct]] throws an error", () => {
424 assertThrows(() => new cbrt(1));
427 describe(".length", () => {
428 it("[[Get]] returns the correct length", () => {
429 assertStrictEquals(cbrt
.length
, 1);
433 describe(".name", () => {
434 it("[[Get]] returns the correct name", () => {
435 assertStrictEquals(cbrt
.name
, "cbrt");
440 describe("ceil", () => {
441 it("[[Call]] returns the ceil", () => {
442 assertStrictEquals(ceil(1), 1);
443 assertStrictEquals(ceil(1.1), 2);
446 it("[[Call]] throws with big·ints", () => {
447 assertThrows(() => ceil(1n
));
450 it("[[Construct]] throws an error", () => {
451 assertThrows(() => new ceil(1));
454 describe(".length", () => {
455 it("[[Get]] returns the correct length", () => {
456 assertStrictEquals(ceil
.length
, 1);
460 describe(".name", () => {
461 it("[[Get]] returns the correct name", () => {
462 assertStrictEquals(ceil
.name
, "ceil");
467 describe("clz32", () => {
468 it("[[Call]] returns the clz32", () => {
469 assertStrictEquals(clz32(1 << 28), 3);
472 it("[[Call]] works with big·ints", () => {
473 assertStrictEquals(clz32(1n
<< 28n
), 3);
476 it("[[Construct]] throws an error", () => {
477 assertThrows(() => new clz32(1));
480 describe(".length", () => {
481 it("[[Get]] returns the correct length", () => {
482 assertStrictEquals(clz32
.length
, 1);
486 describe(".name", () => {
487 it("[[Get]] returns the correct name", () => {
488 assertStrictEquals(clz32
.name
, "clz32");
493 describe("cos", () => {
494 it("[[Call]] returns the cos", () => {
495 assertStrictEquals(cos(1), Math
.cos(1));
496 assertStrictEquals(cos(0), 1);
499 it("[[Call]] throws with big·ints", () => {
500 assertThrows(() => cos(1n
));
503 it("[[Construct]] throws an error", () => {
504 assertThrows(() => new cos(1));
507 describe(".length", () => {
508 it("[[Get]] returns the correct length", () => {
509 assertStrictEquals(cos
.length
, 1);
513 describe(".name", () => {
514 it("[[Get]] returns the correct name", () => {
515 assertStrictEquals(cos
.name
, "cos");
520 describe("cosh", () => {
521 it("[[Call]] returns the cosh", () => {
522 assertStrictEquals(cosh(1), Math
.cosh(1));
523 assertStrictEquals(cosh(0), 1);
526 it("[[Call]] throws with big·ints", () => {
527 assertThrows(() => cosh(1n
));
530 it("[[Construct]] throws an error", () => {
531 assertThrows(() => new cosh(1));
534 describe(".length", () => {
535 it("[[Get]] returns the correct length", () => {
536 assertStrictEquals(cosh
.length
, 1);
540 describe(".name", () => {
541 it("[[Get]] returns the correct name", () => {
542 assertStrictEquals(cosh
.name
, "cosh");
547 describe("exp", () => {
548 it("[[Call]] returns the exp", () => {
549 assertStrictEquals(exp(1), Math
.E
);
550 assertStrictEquals(exp(0), 1);
553 it("[[Call]] throws with big·ints", () => {
554 assertThrows(() => exp(1n
));
557 it("[[Construct]] throws an error", () => {
558 assertThrows(() => new exp(1));
561 describe(".length", () => {
562 it("[[Get]] returns the correct length", () => {
563 assertStrictEquals(exp
.length
, 1);
567 describe(".name", () => {
568 it("[[Get]] returns the correct name", () => {
569 assertStrictEquals(exp
.name
, "exp");
574 describe("expm1", () => {
575 it("[[Call]] returns the expm1", () => {
576 assertStrictEquals(expm1(1), Math
.E
- 1);
577 assertStrictEquals(expm1(0), 0);
580 it("[[Call]] throws with big·ints", () => {
581 assertThrows(() => expm1(1n
));
584 it("[[Construct]] throws an error", () => {
585 assertThrows(() => new expm1(1));
588 describe(".length", () => {
589 it("[[Get]] returns the correct length", () => {
590 assertStrictEquals(expm1
.length
, 1);
594 describe(".name", () => {
595 it("[[Get]] returns the correct name", () => {
596 assertStrictEquals(expm1
.name
, "expm1");
601 describe("floor", () => {
602 it("[[Call]] returns the floor", () => {
603 assertStrictEquals(floor(1), 1);
604 assertStrictEquals(floor(0.1), 0);
607 it("[[Call]] throws with big·ints", () => {
608 assertThrows(() => floor(1n
));
611 it("[[Construct]] throws an error", () => {
612 assertThrows(() => new floor(1));
615 describe(".length", () => {
616 it("[[Get]] returns the correct length", () => {
617 assertStrictEquals(floor
.length
, 1);
621 describe(".name", () => {
622 it("[[Get]] returns the correct name", () => {
623 assertStrictEquals(floor
.name
, "floor");
628 describe("hypot", () => {
629 it("[[Call]] returns the floor", () => {
630 assertStrictEquals(hypot(1, 0), 1);
631 assertStrictEquals(hypot(3, 4), 5);
634 it("[[Call]] throws with big·ints", () => {
635 assertThrows(() => hypot(1n
, 0n
));
638 it("[[Construct]] throws an error", () => {
639 assertThrows(() => new hypot(1, 0));
642 describe(".length", () => {
643 it("[[Get]] returns the correct length", () => {
644 assertStrictEquals(hypot
.length
, 2);
648 describe(".name", () => {
649 it("[[Get]] returns the correct name", () => {
650 assertStrictEquals(hypot
.name
, "hypot");
655 describe("isFiniteNumber", () => {
656 it("[[Call]] returns true for finite numbers", () => {
657 assertStrictEquals(isFiniteNumber(1), true);
658 assertStrictEquals(isFiniteNumber(Number
.MAX_VALUE
), true);
659 assertStrictEquals(isFiniteNumber(Number
.EPSILON
), true);
662 it("[[Call]] returns false for nonfinite numbers", () => {
663 assertStrictEquals(isFiniteNumber(NaN
), false);
664 assertStrictEquals(isFiniteNumber(Infinity
), false);
667 it("[[Call]] returns false for nonnumbers", () => {
668 assertStrictEquals(isFiniteNumber(1n
), false);
669 assertStrictEquals(isFiniteNumber("1"), false);
672 it("[[Construct]] throws an error", () => {
673 assertThrows(() => new isFiniteNumber(1));
676 describe(".length", () => {
677 it("[[Get]] returns the correct length", () => {
678 assertStrictEquals(isFiniteNumber
.length
, 1);
682 describe(".name", () => {
683 it("[[Get]] returns the correct name", () => {
684 assertStrictEquals(isFiniteNumber
.name
, "isFiniteNumber");
689 describe("isIntegralNumber", () => {
690 it("[[Call]] returns true for integral numbers", () => {
691 assertStrictEquals(isIntegralNumber(1), true);
692 assertStrictEquals(isIntegralNumber(Number
.MAX_VALUE
), true);
695 it("[[Call]] returns false for nonfinite numbers", () => {
696 assertStrictEquals(isIntegralNumber(NaN
), false);
697 assertStrictEquals(isIntegralNumber(Infinity
), false);
700 it("[[Call]] returns false for nonintegral numbers", () => {
701 assertStrictEquals(isIntegralNumber(.1), false);
702 assertStrictEquals(isIntegralNumber(Number
.EPSILON
), false);
705 it("[[Call]] returns false for nonnumbers", () => {
706 assertStrictEquals(isIntegralNumber(1n
), false);
707 assertStrictEquals(isIntegralNumber("1"), false);
710 it("[[Construct]] throws an error", () => {
711 assertThrows(() => new isIntegralNumber(1));
714 describe(".length", () => {
715 it("[[Get]] returns the correct length", () => {
716 assertStrictEquals(isIntegralNumber
.length
, 1);
720 describe(".name", () => {
721 it("[[Get]] returns the correct name", () => {
722 assertStrictEquals(isIntegralNumber
.name
, "isIntegralNumber");
727 describe("isNan", () => {
728 it("[[Call]] returns true for nan", () => {
729 assertStrictEquals(isNan(NaN
), true);
732 it("[[Call]] returns false for infinite numbers", () => {
733 assertStrictEquals(isNan(-Infinity
), false);
734 assertStrictEquals(isNan(Infinity
), false);
737 it("[[Call]] returns false for finite numbers", () => {
738 assertStrictEquals(isNan(1), false);
739 assertStrictEquals(isNan(Number
.MAX_VALUE
), false);
740 assertStrictEquals(isNan(.1), false);
741 assertStrictEquals(isNan(Number
.EPSILON
), false);
744 it("[[Call]] returns false for nonnumbers", () => {
745 assertStrictEquals(isNan(1n
), false);
746 assertStrictEquals(isNan("NaN"), false);
747 assertStrictEquals(isNan({}), false);
748 assertStrictEquals(isNan(new Date(NaN
)), false);
751 it("[[Construct]] throws an error", () => {
752 assertThrows(() => new isNan(1));
755 describe(".length", () => {
756 it("[[Get]] returns the correct length", () => {
757 assertStrictEquals(isNan
.length
, 1);
761 describe(".name", () => {
762 it("[[Get]] returns the correct name", () => {
763 assertStrictEquals(isNan
.name
, "isNan");
768 describe("isSafeIntegralNumber", () => {
769 it("[[Call]] returns true for safe integral numbers", () => {
770 assertStrictEquals(isSafeIntegralNumber(1), true);
772 isSafeIntegralNumber(Number
.MAX_SAFE_INTEGER
),
777 it("[[Call]] returns false for nonfinite numbers", () => {
778 assertStrictEquals(isSafeIntegralNumber(NaN
), false);
779 assertStrictEquals(isSafeIntegralNumber(Infinity
), false);
782 it("[[Call]] returns false for nonintegral numbers", () => {
783 assertStrictEquals(isSafeIntegralNumber(.1), false);
784 assertStrictEquals(isSafeIntegralNumber(Number
.EPSILON
), false);
786 it("[[Call]] returns true for unsafe integral numbers", () => {
787 assertStrictEquals(isSafeIntegralNumber(Number
.MAX_VALUE
), false);
790 it("[[Call]] returns false for nonnumbers", () => {
791 assertStrictEquals(isSafeIntegralNumber(1n
), false);
792 assertStrictEquals(isSafeIntegralNumber("1"), false);
795 it("[[Construct]] throws an error", () => {
796 assertThrows(() => new isSafeIntegralNumber(1));
799 describe(".length", () => {
800 it("[[Get]] returns the correct length", () => {
801 assertStrictEquals(isSafeIntegralNumber
.length
, 1);
805 describe(".name", () => {
806 it("[[Get]] returns the correct name", () => {
808 isSafeIntegralNumber
.name
,
809 "isSafeIntegralNumber",
815 describe("ln", () => {
816 it("[[Call]] returns the ln", () => {
817 assertStrictEquals(ln(1), 0);
818 assertStrictEquals(ln(Math
.E
), 1);
821 it("[[Call]] throws with big·ints", () => {
822 assertThrows(() => ln(1n
));
825 it("[[Construct]] throws an error", () => {
826 assertThrows(() => new ln(1));
829 describe(".length", () => {
830 it("[[Get]] returns the correct length", () => {
831 assertStrictEquals(ln
.length
, 1);
835 describe(".name", () => {
836 it("[[Get]] returns the correct name", () => {
837 assertStrictEquals(ln
.name
, "ln");
842 describe("ln1p", () => {
843 it("[[Call]] returns the ln1p", () => {
844 assertStrictEquals(ln1p(1), Math
.log1p(1));
845 assertStrictEquals(ln1p(Math
.E
- 1), 1);
848 it("[[Call]] throws with big·ints", () => {
849 assertThrows(() => ln1p(1n
));
852 it("[[Construct]] throws an error", () => {
853 assertThrows(() => new ln1p(1));
856 describe(".length", () => {
857 it("[[Get]] returns the correct length", () => {
858 assertStrictEquals(ln1p
.length
, 1);
862 describe(".name", () => {
863 it("[[Get]] returns the correct name", () => {
864 assertStrictEquals(ln1p
.name
, "ln1p");
869 describe("log10", () => {
870 it("[[Call]] returns the log10", () => {
871 assertStrictEquals(log10(1), 0);
872 assertStrictEquals(log10(10), 1);
875 it("[[Call]] throws with big·ints", () => {
876 assertThrows(() => log10(1n
));
879 it("[[Construct]] throws an error", () => {
880 assertThrows(() => new log10(1));
883 describe(".length", () => {
884 it("[[Get]] returns the correct length", () => {
885 assertStrictEquals(log10
.length
, 1);
889 describe(".name", () => {
890 it("[[Get]] returns the correct name", () => {
891 assertStrictEquals(log10
.name
, "log10");
896 describe("log2", () => {
897 it("[[Call]] returns the log2", () => {
898 assertStrictEquals(log2(1), 0);
899 assertStrictEquals(log2(2), 1);
902 it("[[Call]] throws with big·ints", () => {
903 assertThrows(() => log2(1n
));
906 it("[[Construct]] throws an error", () => {
907 assertThrows(() => new log2(1));
910 describe(".length", () => {
911 it("[[Get]] returns the correct length", () => {
912 assertStrictEquals(log2
.length
, 1);
916 describe(".name", () => {
917 it("[[Get]] returns the correct name", () => {
918 assertStrictEquals(log2
.name
, "log2");
923 describe("max", () => {
924 it("[[Call]] returns the largest number", () => {
925 assertStrictEquals(max(1, -6, 92, -Infinity
, 0), 92);
928 it("[[Call]] returns the largest big·int", () => {
929 assertStrictEquals(max(1n
, -6n
, 92n
, 0n
), 92n
);
932 it("[[Call]] returns nan if any argument is nan", () => {
933 assertStrictEquals(max(0, NaN
, 1), NaN
);
936 it("[[Call]] returns -Infinity when called with no arguments", () => {
937 assertStrictEquals(max(), -Infinity
);
940 it("[[Call]] throws if both big·int and number arguments are provided", () => {
941 assertThrows(() => max(-Infinity
, 0n
));
944 it("[[Construct]] throws an error", () => {
945 assertThrows(() => new max(1, 0));
948 describe(".length", () => {
949 it("[[Get]] returns the correct length", () => {
950 assertStrictEquals(max
.length
, 2);
954 describe(".name", () => {
955 it("[[Get]] returns the correct name", () => {
956 assertStrictEquals(max
.name
, "max");
961 describe("min", () => {
962 it("[[Call]] returns the largest number", () => {
963 assertStrictEquals(min(1, -6, 92, Infinity
, 0), -6);
966 it("[[Call]] returns the largest big·int", () => {
967 assertStrictEquals(min(1n
, -6n
, 92n
, 0n
), -6n
);
970 it("[[Call]] returns nan if any argument is nan", () => {
971 assertStrictEquals(min(0, NaN
, 1), NaN
);
974 it("[[Call]] returns Infinity when called with no arguments", () => {
975 assertStrictEquals(min(), Infinity
);
978 it("[[Call]] throws if both big·int and number arguments are provided", () => {
979 assertThrows(() => min(Infinity
, 0n
));
982 it("[[Construct]] throws an error", () => {
983 assertThrows(() => new min(1, 0));
986 describe(".length", () => {
987 it("[[Get]] returns the correct length", () => {
988 assertStrictEquals(min
.length
, 2);
992 describe(".name", () => {
993 it("[[Get]] returns the correct name", () => {
994 assertStrictEquals(min
.name
, "min");
999 describe("rand", () => {
1000 it("[[Call]] returns a random number between 0 and 1", () => {
1001 // Not possible to fully test, obviously.
1003 assert(typeof r
=== "number");
1004 assert(r
>= 0 && r
< 1);
1007 it("[[Construct]] throws an error", () => {
1008 assertThrows(() => new rand());
1011 describe(".length", () => {
1012 it("[[Get]] returns the correct length", () => {
1013 assertStrictEquals(rand
.length
, 0);
1017 describe(".name", () => {
1018 it("[[Get]] returns the correct name", () => {
1019 assertStrictEquals(rand
.name
, "rand");
1024 describe("round", () => {
1025 it("[[Call]] returns the round", () => {
1026 assertStrictEquals(round(1), 1);
1027 assertStrictEquals(round(0.5), 1);
1028 assertStrictEquals(round(-0.5), -0);
1031 it("[[Call]] throws with big·ints", () => {
1032 assertThrows(() => round(1n
));
1035 it("[[Construct]] throws an error", () => {
1036 assertThrows(() => new round(1));
1039 describe(".length", () => {
1040 it("[[Get]] returns the correct length", () => {
1041 assertStrictEquals(round
.length
, 1);
1045 describe(".name", () => {
1046 it("[[Get]] returns the correct name", () => {
1047 assertStrictEquals(round
.name
, "round");
1052 describe("sgn", () => {
1053 it("[[Call]] returns the sign", () => {
1054 assertStrictEquals(sgn(Infinity
), 1);
1055 assertStrictEquals(sgn(-Infinity
), -1);
1056 assertStrictEquals(sgn(0), 0);
1057 assertStrictEquals(sgn(-0), -0);
1058 assertStrictEquals(sgn(NaN
), NaN
);
1061 it("[[Call]] works with big·ints", () => {
1062 assertStrictEquals(sgn(0n
), 0n
);
1063 assertStrictEquals(sgn(92n
), 1n
);
1064 assertStrictEquals(sgn(-92n
), -1n
);
1067 it("[[Construct]] throws an error", () => {
1068 assertThrows(() => new sgn(1));
1071 describe(".length", () => {
1072 it("[[Get]] returns the correct length", () => {
1073 assertStrictEquals(sgn
.length
, 1);
1077 describe(".name", () => {
1078 it("[[Get]] returns the correct name", () => {
1079 assertStrictEquals(sgn
.name
, "sgn");
1084 describe("sin", () => {
1085 it("[[Call]] returns the sin", () => {
1086 assertStrictEquals(sin(1), Math
.sin(1));
1087 assertStrictEquals(sin(0), 0);
1090 it("[[Call]] throws with big·ints", () => {
1091 assertThrows(() => sin(1n
));
1094 it("[[Construct]] throws an error", () => {
1095 assertThrows(() => new sin(1));
1098 describe(".length", () => {
1099 it("[[Get]] returns the correct length", () => {
1100 assertStrictEquals(sin
.length
, 1);
1104 describe(".name", () => {
1105 it("[[Get]] returns the correct name", () => {
1106 assertStrictEquals(sin
.name
, "sin");
1111 describe("sinh", () => {
1112 it("[[Call]] returns the sinh", () => {
1113 assertStrictEquals(sinh(1), Math
.sinh(1));
1114 assertStrictEquals(sinh(0), 0);
1117 it("[[Call]] throws with big·ints", () => {
1118 assertThrows(() => sinh(1n
));
1121 it("[[Construct]] throws an error", () => {
1122 assertThrows(() => new sinh(1));
1125 describe(".length", () => {
1126 it("[[Get]] returns the correct length", () => {
1127 assertStrictEquals(sinh
.length
, 1);
1131 describe(".name", () => {
1132 it("[[Get]] returns the correct name", () => {
1133 assertStrictEquals(sinh
.name
, "sinh");
1138 describe("sqrt", () => {
1139 it("[[Call]] returns the sqrt", () => {
1140 assertStrictEquals(sqrt(1), 1);
1141 assertStrictEquals(sqrt(2), Math
.SQRT2
);
1144 it("[[Call]] throws with big·ints", () => {
1145 assertThrows(() => sqrt(1n
));
1148 it("[[Construct]] throws an error", () => {
1149 assertThrows(() => new sqrt(1));
1152 describe(".length", () => {
1153 it("[[Get]] returns the correct length", () => {
1154 assertStrictEquals(sqrt
.length
, 1);
1158 describe(".name", () => {
1159 it("[[Get]] returns the correct name", () => {
1160 assertStrictEquals(sqrt
.name
, "sqrt");
1165 describe("tan", () => {
1166 it("[[Call]] returns the tan", () => {
1167 assertStrictEquals(tan(1), Math
.tan(1));
1168 assertStrictEquals(tan(0), 0);
1171 it("[[Call]] throws with big·ints", () => {
1172 assertThrows(() => tan(1n
));
1175 it("[[Construct]] throws an error", () => {
1176 assertThrows(() => new tan(1));
1179 describe(".length", () => {
1180 it("[[Get]] returns the correct length", () => {
1181 assertStrictEquals(tan
.length
, 1);
1185 describe(".name", () => {
1186 it("[[Get]] returns the correct name", () => {
1187 assertStrictEquals(tan
.name
, "tan");
1192 describe("tanh", () => {
1193 it("[[Call]] returns the tanh", () => {
1194 assertStrictEquals(tanh(1), Math
.tanh(1));
1195 assertStrictEquals(tanh(0), 0);
1198 it("[[Call]] throws with big·ints", () => {
1199 assertThrows(() => tanh(1n
));
1202 it("[[Construct]] throws an error", () => {
1203 assertThrows(() => new tanh(1));
1206 describe(".length", () => {
1207 it("[[Get]] returns the correct length", () => {
1208 assertStrictEquals(tanh
.length
, 1);
1212 describe(".name", () => {
1213 it("[[Get]] returns the correct name", () => {
1214 assertStrictEquals(tanh
.name
, "tanh");
1219 describe("toBigInt", () => {
1220 it("[[Call]] converts to a big·int", () => {
1221 assertStrictEquals(toBigInt(2), 2n
);
1224 it("[[Construct]] throws an error", () => {
1225 assertThrows(() => new toBigInt(1));
1228 describe(".length", () => {
1229 it("[[Get]] returns the correct length", () => {
1230 assertStrictEquals(toBigInt
.length
, 1);
1234 describe(".name", () => {
1235 it("[[Get]] returns the correct name", () => {
1236 assertStrictEquals(toBigInt
.name
, "toBigInt");
1241 describe("toExponentialNotation", () => {
1242 it("[[Call]] converts to exponential notation", () => {
1243 assertStrictEquals(toExponentialNotation(231), "2.31e+2");
1246 it("[[Call]] works with big·ints", () => {
1248 toExponentialNotation(9007199254740993n
),
1249 "9.007199254740993e+15",
1253 it("[[Call]] respects the specified number of fractional digits", () => {
1255 toExponentialNotation(.00000000642, 3),
1258 assertStrictEquals(toExponentialNotation(.00691, 1), "6.9e-3");
1259 assertStrictEquals(toExponentialNotation(.00685, 1), "6.9e-3");
1260 assertStrictEquals(toExponentialNotation(.004199, 2), "4.20e-3");
1262 toExponentialNotation(6420000000n
, 3),
1265 assertStrictEquals(toExponentialNotation(6910n
, 1), "6.9e+3");
1266 assertStrictEquals(toExponentialNotation(6850n
, 1), "6.9e+3");
1267 assertStrictEquals(toExponentialNotation(4199n
, 2), "4.20e+3");
1270 it("[[Construct]] throws an error", () => {
1271 assertThrows(() => new toExponentialNotation(1, 1));
1274 describe(".length", () => {
1275 it("[[Get]] returns the correct length", () => {
1276 assertStrictEquals(toExponentialNotation
.length
, 2);
1280 describe(".name", () => {
1281 it("[[Get]] returns the correct name", () => {
1283 toExponentialNotation
.name
,
1284 "toExponentialNotation",
1290 describe("toFixedDecimalNotation", () => {
1291 it("[[Call]] converts to fixed decimal notation", () => {
1292 assertStrictEquals(toFixedDecimalNotation(69.4199, 3), "69.420");
1295 it("[[Call]] works with big·ints", () => {
1297 toFixedDecimalNotation(9007199254740993n
),
1301 toFixedDecimalNotation(9007199254740993n
, 2),
1302 "9007199254740993.00",
1306 it("[[Construct]] throws an error", () => {
1307 assertThrows(() => new toFixedDecimalNotation(1, 1));
1310 describe(".length", () => {
1311 it("[[Get]] returns the correct length", () => {
1312 assertStrictEquals(toFixedDecimalNotation
.length
, 2);
1316 describe(".name", () => {
1317 it("[[Get]] returns the correct name", () => {
1319 toFixedDecimalNotation
.name
,
1320 "toFixedDecimalNotation",
1326 describe("toFloat32", () => {
1327 it("[[Call]] returns the 32‐bit floating‐point representation", () => {
1329 toFloat32(562949953421313),
1330 Math
.fround(562949953421313),
1334 it("[[Call]] works with big·ints", () => {
1336 toFloat32(562949953421313n
),
1337 Math
.fround(562949953421313),
1341 it("[[Construct]] throws an error", () => {
1342 assertThrows(() => new toFloat32(1));
1345 describe(".length", () => {
1346 it("[[Get]] returns the correct length", () => {
1347 assertStrictEquals(toFloat32
.length
, 1);
1351 describe(".name", () => {
1352 it("[[Get]] returns the correct name", () => {
1353 assertStrictEquals(toFloat32
.name
, "toFloat32");
1358 describe("toSignedIntegralNumeric", () => {
1359 it("[[Call]] converts to an int·n", () => {
1360 assertStrictEquals(toSignedIntegralNumeric(2, 7n
), -1n
);
1363 it("[[Call]] works with numbers", () => {
1364 assertStrictEquals(toSignedIntegralNumeric(2, 7), -1);
1367 it("[[Call]] works with non‐integers", () => {
1368 assertStrictEquals(toSignedIntegralNumeric(2, 7.21), -1);
1369 assertStrictEquals(toSignedIntegralNumeric(2, Infinity
), 0);
1372 it("[[Construct]] throws an error", () => {
1373 assertThrows(() => new toSignedIntegralNumeric(1, 1));
1376 describe(".length", () => {
1377 it("[[Get]] returns the correct length", () => {
1378 assertStrictEquals(toSignedIntegralNumeric
.length
, 2);
1382 describe(".name", () => {
1383 it("[[Get]] returns the correct name", () => {
1385 toSignedIntegralNumeric
.name
,
1386 "toSignedIntegralNumeric",
1392 describe("toIntegralNumber", () => {
1393 it("[[Call]] converts nan to zero", () => {
1394 assertStrictEquals(toIntegralNumber(NaN
), 0);
1397 it("[[Call]] converts negative zero to positive zero", () => {
1398 assertStrictEquals(toIntegralNumber(-0), 0);
1401 it("[[Call]] drops the fractional part of negative numbers", () => {
1402 assertStrictEquals(toIntegralNumber(-1.79), -1);
1405 it("[[Call]] returns zero for infinity", () => {
1406 assertStrictEquals(toIntegralNumber(Infinity
), 0);
1409 it("[[Call]] returns zero for negative infinity", () => {
1410 assertStrictEquals(toIntegralNumber(-Infinity
), 0);
1413 it("[[Call]] works with big·ints", () => {
1414 assertStrictEquals(toIntegralNumber(2n
), 2);
1417 it("[[Construct]] throws an error", () => {
1418 assertThrows(() => new toIntegralNumber(1));
1421 describe(".length", () => {
1422 it("[[Get]] returns the correct length", () => {
1423 assertStrictEquals(toIntegralNumber
.length
, 1);
1427 describe(".name", () => {
1428 it("[[Get]] returns the correct name", () => {
1429 assertStrictEquals(toIntegralNumber
.name
, "toIntegralNumber");
1434 describe("toIntegralNumberOrInfinity", () => {
1435 it("[[Call]] converts nan to zero", () => {
1436 assertStrictEquals(toIntegralNumberOrInfinity(NaN
), 0);
1439 it("[[Call]] converts negative zero to positive zero", () => {
1440 assertStrictEquals(toIntegralNumberOrInfinity(-0), 0);
1443 it("[[Call]] drops the fractional part of negative numbers", () => {
1444 assertStrictEquals(toIntegralNumberOrInfinity(-1.79), -1);
1447 it("[[Call]] returns infinity for infinity", () => {
1448 assertStrictEquals(toIntegralNumberOrInfinity(Infinity
), Infinity
);
1451 it("[[Call]] returns negative infinity for negative infinity", () => {
1453 toIntegralNumberOrInfinity(-Infinity
),
1458 it("[[Call]] works with big·ints", () => {
1459 assertStrictEquals(toIntegralNumberOrInfinity(2n
), 2);
1462 it("[[Construct]] throws an error", () => {
1463 assertThrows(() => new toIntegralNumberOrInfinity(1));
1466 describe(".length", () => {
1467 it("[[Get]] returns the correct length", () => {
1468 assertStrictEquals(toIntegralNumberOrInfinity
.length
, 1);
1472 describe(".name", () => {
1473 it("[[Get]] returns the correct name", () => {
1475 toIntegralNumberOrInfinity
.name
,
1476 "toIntegralNumberOrInfinity",
1482 describe("toNumber", () => {
1483 it("[[Call]] converts to a number", () => {
1484 assertStrictEquals(toNumber(2n
), 2);
1488 describe("toNumeric", () => {
1489 it("[[Call]] returns a big·int argument", () => {
1490 assertStrictEquals(toNumeric(231n
), 231n
);
1493 it("[[Call]] converts to a numeric", () => {
1494 assertStrictEquals(toNumeric("231"), 231);
1497 it("[[Call]] prefers `valueOf`", () => {
1511 it("[[Construct]] throws an error", () => {
1512 assertThrows(() => new toNumeric(1));
1515 describe(".length", () => {
1516 it("[[Get]] returns the correct length", () => {
1517 assertStrictEquals(toNumeric
.length
, 1);
1521 describe(".name", () => {
1522 it("[[Get]] returns the correct name", () => {
1523 assertStrictEquals(toNumeric
.name
, "toNumeric");
1528 describe("toUnsignedIntegralNumeric", () => {
1529 it("[[Call]] converts to an int·n", () => {
1530 assertStrictEquals(toUnsignedIntegralNumeric(2, 7n
), 3n
);
1533 it("[[Call]] works with numbers", () => {
1534 assertStrictEquals(toUnsignedIntegralNumeric(2, 7), 3);
1537 it("[[Call]] works with non‐integers", () => {
1538 assertStrictEquals(toUnsignedIntegralNumeric(2, 7.21), 3);
1539 assertStrictEquals(toUnsignedIntegralNumeric(2, Infinity
), 0);
1542 it("[[Construct]] throws an error", () => {
1543 assertThrows(() => new toUnsignedIntegralNumeric(1, 1));
1546 describe(".length", () => {
1547 it("[[Get]] returns the correct length", () => {
1548 assertStrictEquals(toUnsignedIntegralNumeric
.length
, 2);
1552 describe(".name", () => {
1553 it("[[Get]] returns the correct name", () => {
1555 toUnsignedIntegralNumeric
.name
,
1556 "toUnsignedIntegralNumeric",
1562 describe("trunc", () => {
1563 it("[[Call]] returns the trunc", () => {
1564 assertStrictEquals(trunc(1), 1);
1565 assertStrictEquals(trunc(0.5), 0);
1566 assertStrictEquals(trunc(-0.5), -0);
1569 it("[[Call]] throws with big·ints", () => {
1570 assertThrows(() => trunc(1n
));
1573 it("[[Construct]] throws an error", () => {
1574 assertThrows(() => new trunc(1));
1577 describe(".length", () => {
1578 it("[[Get]] returns the correct length", () => {
1579 assertStrictEquals(trunc
.length
, 1);
1583 describe(".name", () => {
1584 it("[[Get]] returns the correct name", () => {
1585 assertStrictEquals(trunc
.name
, "trunc");