]> Lady’s Gitweb - Pisces/blob - numeric.test.js
9d0dbd1f93ecf4c530640686a57461442190b960
[Pisces] / numeric.test.js
1 // ♓🌟 Piscēs ∷ numeric.test.js
2 // ====================================================================
3 //
4 // Copyright © 2022–2023 Lady [@ Lady’s Computer].
5 //
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/>.
9
10 import {
11 assert,
12 assertStrictEquals,
13 assertThrows,
14 describe,
15 it,
16 } from "./dev-deps.js";
17 import {
18 abs,
19 arccos,
20 arccosh,
21 arcsin,
22 arcsinh,
23 arctan,
24 arctan2,
25 arctanh,
26 cbrt,
27 ceil,
28 clz32,
29 cos,
30 cosh,
31 exp,
32 expm1,
33 floor,
34 hypot,
35 isFiniteNumber,
36 isIntegralNumber,
37 isNan,
38 isSafeIntegralNumber,
39 ln,
40 LN10,
41 ln1p,
42 LN2,
43 log10,
44 LOG10ℇ,
45 log2,
46 LOG2ℇ,
47 max,
48 MAXIMUM_NUMBER,
49 MAXIMUM_SAFE_INTEGRAL_NUMBER,
50 min,
51 MINIMUM_NUMBER,
52 MINIMUM_SAFE_INTEGRAL_NUMBER,
53 NAN,
54 NEGATIVE_INFINITY,
55 NEGATIVE_ZERO,
56 POSITIVE_INFINITY,
57 POSITIVE_ZERO,
58 rand,
59 RECIPROCAL_SQRT2,
60 round,
61 sgn,
62 sin,
63 sinh,
64 sqrt,
65 SQRT2,
66 tan,
67 tanh,
68 toBigInt,
69 toExponentialNotation,
70 toFixedDecimalNotation,
71 toFloat32,
72 toIntegralNumber,
73 toIntegralNumberOrInfinity,
74 toNumber,
75 toNumeric,
76 toSignedIntegralNumeric,
77 toUnsignedIntegralNumeric,
78 trunc,
79 Ε,
80 Π,
81 ℇ,
82 } from "./numeric.js";
83
84 describe("LN10", () => {
85 it("[[Get]] is ln(10)", () => {
86 assertStrictEquals(LN10, Math.LN10);
87 });
88 });
89
90 describe("LN2", () => {
91 it("[[Get]] is ln(2)", () => {
92 assertStrictEquals(LN2, Math.LN2);
93 });
94 });
95
96 describe("LOG10ℇ", () => {
97 it("[[Get]] is log10(ℇ)", () => {
98 assertStrictEquals(LOG10ℇ, Math.LOG10E);
99 });
100 });
101
102 describe("LOG2ℇ", () => {
103 it("[[Get]] is log2(ℇ)", () => {
104 assertStrictEquals(LOG2ℇ, Math.LOG2E);
105 });
106 });
107
108 describe("MAXIMUM_NUMBER", () => {
109 it("[[Get]] is the maximum number", () => {
110 assertStrictEquals(MAXIMUM_NUMBER, Number.MAX_VALUE);
111 });
112 });
113
114 describe("MAXIMUM_SAFE_INTEGRAL_NUMBER", () => {
115 it("[[Get]] is the maximum safe integral number", () => {
116 assertStrictEquals(
117 MAXIMUM_SAFE_INTEGRAL_NUMBER,
118 Number.MAX_SAFE_INTEGER,
119 );
120 });
121 });
122
123 describe("MINIMUM_NUMBER", () => {
124 it("[[Get]] is the minimum number", () => {
125 assertStrictEquals(MINIMUM_NUMBER, Number.MIN_VALUE);
126 });
127 });
128
129 describe("MINIMUM_SAFE_INTEGRAL_NUMBER", () => {
130 it("[[Get]] is the minimum safe integral number", () => {
131 assertStrictEquals(
132 MINIMUM_SAFE_INTEGRAL_NUMBER,
133 Number.MIN_SAFE_INTEGER,
134 );
135 });
136 });
137
138 describe("NAN", () => {
139 it("[[Get]] is nan", () => {
140 assertStrictEquals(NAN, NaN);
141 });
142 });
143
144 describe("NEGATIVE_INFINITY", () => {
145 it("[[Get]] is negative infinity", () => {
146 assertStrictEquals(NEGATIVE_INFINITY, -Infinity);
147 });
148 });
149
150 describe("NEGATIVE_ZERO", () => {
151 it("[[Get]] is negative zero", () => {
152 assertStrictEquals(NEGATIVE_ZERO, -0);
153 });
154 });
155
156 describe("POSITIVE_INFINITY", () => {
157 it("[[Get]] is negative infinity", () => {
158 assertStrictEquals(POSITIVE_INFINITY, Infinity);
159 });
160 });
161
162 describe("POSITIVE_ZERO", () => {
163 it("[[Get]] is positive zero", () => {
164 assertStrictEquals(POSITIVE_ZERO, 0);
165 });
166 });
167
168 describe("RECIPROCAL_SQRT2", () => {
169 it("[[Get]] is sqrt(½)", () => {
170 assertStrictEquals(RECIPROCAL_SQRT2, Math.SQRT1_2);
171 });
172 });
173
174 describe("SQRT2", () => {
175 it("[[Get]] is sqrt(2)", () => {
176 assertStrictEquals(SQRT2, Math.SQRT2);
177 });
178 });
179
180 describe("Ε", () => {
181 it("[[Get]] is ε", () => {
182 assertStrictEquals(Ε, Number.EPSILON);
183 });
184 });
185
186 describe("Π", () => {
187 it("[[Get]] is π", () => {
188 assertStrictEquals(Π, Math.PI);
189 });
190 });
191
192 describe("ℇ", () => {
193 it("[[Get]] is ℇ", () => {
194 assertStrictEquals(ℇ, Math.E);
195 });
196 });
197
198 describe("abs", () => {
199 it("[[Call]] returns the absolute value", () => {
200 assertStrictEquals(abs(-1), 1);
201 });
202
203 it("[[Call]] works with big·ints", () => {
204 const bn = BigInt(Number.MAX_SAFE_INTEGER) + 2n;
205 assertStrictEquals(abs(-bn), bn);
206 });
207
208 it("[[Construct]] throws an error", () => {
209 assertThrows(() => new abs(0));
210 });
211
212 describe(".length", () => {
213 it("[[Get]] returns the correct length", () => {
214 assertStrictEquals(abs.length, 1);
215 });
216 });
217
218 describe(".name", () => {
219 it("[[Get]] returns the correct name", () => {
220 assertStrictEquals(abs.name, "abs");
221 });
222 });
223 });
224
225 describe("arccos", () => {
226 it("[[Call]] returns the arccos", () => {
227 assertStrictEquals(arccos(1), 0);
228 assertStrictEquals(arccos(0), Math.PI / 2);
229 });
230
231 it("[[Call]] throws with big·ints", () => {
232 assertThrows(() => arccos(1n));
233 });
234
235 it("[[Construct]] throws an error", () => {
236 assertThrows(() => new arccos(1));
237 });
238
239 describe(".length", () => {
240 it("[[Get]] returns the correct length", () => {
241 assertStrictEquals(arccos.length, 1);
242 });
243 });
244
245 describe(".name", () => {
246 it("[[Get]] returns the correct name", () => {
247 assertStrictEquals(arccos.name, "arccos");
248 });
249 });
250 });
251
252 describe("arccosh", () => {
253 it("[[Call]] returns the arccosh", () => {
254 assertStrictEquals(arccosh(1), 0);
255 assertStrictEquals(arccosh(0), NaN);
256 });
257
258 it("[[Call]] throws with big·ints", () => {
259 assertThrows(() => arccosh(1n));
260 });
261
262 it("[[Construct]] throws an error", () => {
263 assertThrows(() => new arccosh(1));
264 });
265
266 describe(".length", () => {
267 it("[[Get]] returns the correct length", () => {
268 assertStrictEquals(arccosh.length, 1);
269 });
270 });
271
272 describe(".name", () => {
273 it("[[Get]] returns the correct name", () => {
274 assertStrictEquals(arccosh.name, "arccosh");
275 });
276 });
277 });
278
279 describe("arcsin", () => {
280 it("[[Call]] returns the arcsin", () => {
281 assertStrictEquals(arcsin(1), Math.PI / 2);
282 assertStrictEquals(arcsin(0), 0);
283 });
284
285 it("[[Call]] throws with big·ints", () => {
286 assertThrows(() => arcsin(1n));
287 });
288
289 it("[[Construct]] throws an error", () => {
290 assertThrows(() => new arcsin(1));
291 });
292
293 describe(".length", () => {
294 it("[[Get]] returns the correct length", () => {
295 assertStrictEquals(arcsin.length, 1);
296 });
297 });
298
299 describe(".name", () => {
300 it("[[Get]] returns the correct name", () => {
301 assertStrictEquals(arcsin.name, "arcsin");
302 });
303 });
304 });
305
306 describe("arcsinh", () => {
307 it("[[Call]] returns the arcsinh", () => {
308 assertStrictEquals(arcsinh(1), Math.asinh(1));
309 assertStrictEquals(arcsinh(0), 0);
310 });
311
312 it("[[Call]] throws with big·ints", () => {
313 assertThrows(() => arcsinh(1n));
314 });
315
316 it("[[Construct]] throws an error", () => {
317 assertThrows(() => new arcsinh(1));
318 });
319
320 describe(".length", () => {
321 it("[[Get]] returns the correct length", () => {
322 assertStrictEquals(arcsinh.length, 1);
323 });
324 });
325
326 describe(".name", () => {
327 it("[[Get]] returns the correct name", () => {
328 assertStrictEquals(arcsinh.name, "arcsinh");
329 });
330 });
331 });
332
333 describe("arctan", () => {
334 it("[[Call]] returns the arctan", () => {
335 assertStrictEquals(arctan(1), Math.PI / 4);
336 assertStrictEquals(arctan(0), 0);
337 });
338
339 it("[[Call]] throws with big·ints", () => {
340 assertThrows(() => arctan(1n));
341 });
342
343 it("[[Construct]] throws an error", () => {
344 assertThrows(() => new arctan(1));
345 });
346
347 describe(".length", () => {
348 it("[[Get]] returns the correct length", () => {
349 assertStrictEquals(arctan.length, 1);
350 });
351 });
352
353 describe(".name", () => {
354 it("[[Get]] returns the correct name", () => {
355 assertStrictEquals(arctan.name, "arctan");
356 });
357 });
358 });
359
360 describe("arctan2", () => {
361 it("[[Call]] returns the arctan2", () => {
362 assertStrictEquals(arctan2(6, 9), Math.atan2(6, 9));
363 });
364
365 it("[[Call]] works with big·ints", () => {
366 assertStrictEquals(arctan2(6n, 9n), Math.atan2(6, 9));
367 });
368
369 it("[[Construct]] throws an error", () => {
370 assertThrows(() => new arctan2(1, 0));
371 });
372
373 describe(".length", () => {
374 it("[[Get]] returns the correct length", () => {
375 assertStrictEquals(arctan2.length, 2);
376 });
377 });
378
379 describe(".name", () => {
380 it("[[Get]] returns the correct name", () => {
381 assertStrictEquals(arctan2.name, "arctan2");
382 });
383 });
384 });
385
386 describe("arctanh", () => {
387 it("[[Call]] returns the arctanh", () => {
388 assertStrictEquals(arctanh(1), Infinity);
389 assertStrictEquals(arctanh(0), 0);
390 });
391
392 it("[[Call]] throws with big·ints", () => {
393 assertThrows(() => arctanh(1n));
394 });
395
396 it("[[Construct]] throws an error", () => {
397 assertThrows(() => new arctanh(1));
398 });
399
400 describe(".length", () => {
401 it("[[Get]] returns the correct length", () => {
402 assertStrictEquals(arctanh.length, 1);
403 });
404 });
405
406 describe(".name", () => {
407 it("[[Get]] returns the correct name", () => {
408 assertStrictEquals(arctanh.name, "arctanh");
409 });
410 });
411 });
412
413 describe("cbrt", () => {
414 it("[[Call]] returns the cbrt", () => {
415 assertStrictEquals(cbrt(1), 1);
416 assertStrictEquals(cbrt(2), Math.cbrt(2));
417 });
418
419 it("[[Call]] throws with big·ints", () => {
420 assertThrows(() => cbrt(1n));
421 });
422
423 it("[[Construct]] throws an error", () => {
424 assertThrows(() => new cbrt(1));
425 });
426
427 describe(".length", () => {
428 it("[[Get]] returns the correct length", () => {
429 assertStrictEquals(cbrt.length, 1);
430 });
431 });
432
433 describe(".name", () => {
434 it("[[Get]] returns the correct name", () => {
435 assertStrictEquals(cbrt.name, "cbrt");
436 });
437 });
438 });
439
440 describe("ceil", () => {
441 it("[[Call]] returns the ceil", () => {
442 assertStrictEquals(ceil(1), 1);
443 assertStrictEquals(ceil(1.1), 2);
444 });
445
446 it("[[Call]] throws with big·ints", () => {
447 assertThrows(() => ceil(1n));
448 });
449
450 it("[[Construct]] throws an error", () => {
451 assertThrows(() => new ceil(1));
452 });
453
454 describe(".length", () => {
455 it("[[Get]] returns the correct length", () => {
456 assertStrictEquals(ceil.length, 1);
457 });
458 });
459
460 describe(".name", () => {
461 it("[[Get]] returns the correct name", () => {
462 assertStrictEquals(ceil.name, "ceil");
463 });
464 });
465 });
466
467 describe("clz32", () => {
468 it("[[Call]] returns the clz32", () => {
469 assertStrictEquals(clz32(1 << 28), 3);
470 });
471
472 it("[[Call]] works with big·ints", () => {
473 assertStrictEquals(clz32(1n << 28n), 3);
474 });
475
476 it("[[Construct]] throws an error", () => {
477 assertThrows(() => new clz32(1));
478 });
479
480 describe(".length", () => {
481 it("[[Get]] returns the correct length", () => {
482 assertStrictEquals(clz32.length, 1);
483 });
484 });
485
486 describe(".name", () => {
487 it("[[Get]] returns the correct name", () => {
488 assertStrictEquals(clz32.name, "clz32");
489 });
490 });
491 });
492
493 describe("cos", () => {
494 it("[[Call]] returns the cos", () => {
495 assertStrictEquals(cos(1), Math.cos(1));
496 assertStrictEquals(cos(0), 1);
497 });
498
499 it("[[Call]] throws with big·ints", () => {
500 assertThrows(() => cos(1n));
501 });
502
503 it("[[Construct]] throws an error", () => {
504 assertThrows(() => new cos(1));
505 });
506
507 describe(".length", () => {
508 it("[[Get]] returns the correct length", () => {
509 assertStrictEquals(cos.length, 1);
510 });
511 });
512
513 describe(".name", () => {
514 it("[[Get]] returns the correct name", () => {
515 assertStrictEquals(cos.name, "cos");
516 });
517 });
518 });
519
520 describe("cosh", () => {
521 it("[[Call]] returns the cosh", () => {
522 assertStrictEquals(cosh(1), Math.cosh(1));
523 assertStrictEquals(cosh(0), 1);
524 });
525
526 it("[[Call]] throws with big·ints", () => {
527 assertThrows(() => cosh(1n));
528 });
529
530 it("[[Construct]] throws an error", () => {
531 assertThrows(() => new cosh(1));
532 });
533
534 describe(".length", () => {
535 it("[[Get]] returns the correct length", () => {
536 assertStrictEquals(cosh.length, 1);
537 });
538 });
539
540 describe(".name", () => {
541 it("[[Get]] returns the correct name", () => {
542 assertStrictEquals(cosh.name, "cosh");
543 });
544 });
545 });
546
547 describe("exp", () => {
548 it("[[Call]] returns the exp", () => {
549 assertStrictEquals(exp(1), Math.E);
550 assertStrictEquals(exp(0), 1);
551 });
552
553 it("[[Call]] throws with big·ints", () => {
554 assertThrows(() => exp(1n));
555 });
556
557 it("[[Construct]] throws an error", () => {
558 assertThrows(() => new exp(1));
559 });
560
561 describe(".length", () => {
562 it("[[Get]] returns the correct length", () => {
563 assertStrictEquals(exp.length, 1);
564 });
565 });
566
567 describe(".name", () => {
568 it("[[Get]] returns the correct name", () => {
569 assertStrictEquals(exp.name, "exp");
570 });
571 });
572 });
573
574 describe("expm1", () => {
575 it("[[Call]] returns the expm1", () => {
576 assertStrictEquals(expm1(1), Math.E - 1);
577 assertStrictEquals(expm1(0), 0);
578 });
579
580 it("[[Call]] throws with big·ints", () => {
581 assertThrows(() => expm1(1n));
582 });
583
584 it("[[Construct]] throws an error", () => {
585 assertThrows(() => new expm1(1));
586 });
587
588 describe(".length", () => {
589 it("[[Get]] returns the correct length", () => {
590 assertStrictEquals(expm1.length, 1);
591 });
592 });
593
594 describe(".name", () => {
595 it("[[Get]] returns the correct name", () => {
596 assertStrictEquals(expm1.name, "expm1");
597 });
598 });
599 });
600
601 describe("floor", () => {
602 it("[[Call]] returns the floor", () => {
603 assertStrictEquals(floor(1), 1);
604 assertStrictEquals(floor(0.1), 0);
605 });
606
607 it("[[Call]] throws with big·ints", () => {
608 assertThrows(() => floor(1n));
609 });
610
611 it("[[Construct]] throws an error", () => {
612 assertThrows(() => new floor(1));
613 });
614
615 describe(".length", () => {
616 it("[[Get]] returns the correct length", () => {
617 assertStrictEquals(floor.length, 1);
618 });
619 });
620
621 describe(".name", () => {
622 it("[[Get]] returns the correct name", () => {
623 assertStrictEquals(floor.name, "floor");
624 });
625 });
626 });
627
628 describe("hypot", () => {
629 it("[[Call]] returns the floor", () => {
630 assertStrictEquals(hypot(1, 0), 1);
631 assertStrictEquals(hypot(3, 4), 5);
632 });
633
634 it("[[Call]] throws with big·ints", () => {
635 assertThrows(() => hypot(1n, 0n));
636 });
637
638 it("[[Construct]] throws an error", () => {
639 assertThrows(() => new hypot(1, 0));
640 });
641
642 describe(".length", () => {
643 it("[[Get]] returns the correct length", () => {
644 assertStrictEquals(hypot.length, 2);
645 });
646 });
647
648 describe(".name", () => {
649 it("[[Get]] returns the correct name", () => {
650 assertStrictEquals(hypot.name, "hypot");
651 });
652 });
653 });
654
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);
660 });
661
662 it("[[Call]] returns false for nonfinite numbers", () => {
663 assertStrictEquals(isFiniteNumber(NaN), false);
664 assertStrictEquals(isFiniteNumber(Infinity), false);
665 });
666
667 it("[[Call]] returns false for nonnumbers", () => {
668 assertStrictEquals(isFiniteNumber(1n), false);
669 assertStrictEquals(isFiniteNumber("1"), false);
670 });
671
672 it("[[Construct]] throws an error", () => {
673 assertThrows(() => new isFiniteNumber(1));
674 });
675
676 describe(".length", () => {
677 it("[[Get]] returns the correct length", () => {
678 assertStrictEquals(isFiniteNumber.length, 1);
679 });
680 });
681
682 describe(".name", () => {
683 it("[[Get]] returns the correct name", () => {
684 assertStrictEquals(isFiniteNumber.name, "isFiniteNumber");
685 });
686 });
687 });
688
689 describe("isIntegralNumber", () => {
690 it("[[Call]] returns true for integral numbers", () => {
691 assertStrictEquals(isIntegralNumber(1), true);
692 assertStrictEquals(isIntegralNumber(Number.MAX_VALUE), true);
693 });
694
695 it("[[Call]] returns false for nonfinite numbers", () => {
696 assertStrictEquals(isIntegralNumber(NaN), false);
697 assertStrictEquals(isIntegralNumber(Infinity), false);
698 });
699
700 it("[[Call]] returns false for nonintegral numbers", () => {
701 assertStrictEquals(isIntegralNumber(.1), false);
702 assertStrictEquals(isIntegralNumber(Number.EPSILON), false);
703 });
704
705 it("[[Call]] returns false for nonnumbers", () => {
706 assertStrictEquals(isIntegralNumber(1n), false);
707 assertStrictEquals(isIntegralNumber("1"), false);
708 });
709
710 it("[[Construct]] throws an error", () => {
711 assertThrows(() => new isIntegralNumber(1));
712 });
713
714 describe(".length", () => {
715 it("[[Get]] returns the correct length", () => {
716 assertStrictEquals(isIntegralNumber.length, 1);
717 });
718 });
719
720 describe(".name", () => {
721 it("[[Get]] returns the correct name", () => {
722 assertStrictEquals(isIntegralNumber.name, "isIntegralNumber");
723 });
724 });
725 });
726
727 describe("isNan", () => {
728 it("[[Call]] returns true for nan", () => {
729 assertStrictEquals(isNan(NaN), true);
730 });
731
732 it("[[Call]] returns false for infinite numbers", () => {
733 assertStrictEquals(isNan(-Infinity), false);
734 assertStrictEquals(isNan(Infinity), false);
735 });
736
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);
742 });
743
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);
749 });
750
751 it("[[Construct]] throws an error", () => {
752 assertThrows(() => new isNan(1));
753 });
754
755 describe(".length", () => {
756 it("[[Get]] returns the correct length", () => {
757 assertStrictEquals(isNan.length, 1);
758 });
759 });
760
761 describe(".name", () => {
762 it("[[Get]] returns the correct name", () => {
763 assertStrictEquals(isNan.name, "isNan");
764 });
765 });
766 });
767
768 describe("isSafeIntegralNumber", () => {
769 it("[[Call]] returns true for safe integral numbers", () => {
770 assertStrictEquals(isSafeIntegralNumber(1), true);
771 assertStrictEquals(
772 isSafeIntegralNumber(Number.MAX_SAFE_INTEGER),
773 true,
774 );
775 });
776
777 it("[[Call]] returns false for nonfinite numbers", () => {
778 assertStrictEquals(isSafeIntegralNumber(NaN), false);
779 assertStrictEquals(isSafeIntegralNumber(Infinity), false);
780 });
781
782 it("[[Call]] returns false for nonintegral numbers", () => {
783 assertStrictEquals(isSafeIntegralNumber(.1), false);
784 assertStrictEquals(isSafeIntegralNumber(Number.EPSILON), false);
785 });
786 it("[[Call]] returns true for unsafe integral numbers", () => {
787 assertStrictEquals(isSafeIntegralNumber(Number.MAX_VALUE), false);
788 });
789
790 it("[[Call]] returns false for nonnumbers", () => {
791 assertStrictEquals(isSafeIntegralNumber(1n), false);
792 assertStrictEquals(isSafeIntegralNumber("1"), false);
793 });
794
795 it("[[Construct]] throws an error", () => {
796 assertThrows(() => new isSafeIntegralNumber(1));
797 });
798
799 describe(".length", () => {
800 it("[[Get]] returns the correct length", () => {
801 assertStrictEquals(isSafeIntegralNumber.length, 1);
802 });
803 });
804
805 describe(".name", () => {
806 it("[[Get]] returns the correct name", () => {
807 assertStrictEquals(
808 isSafeIntegralNumber.name,
809 "isSafeIntegralNumber",
810 );
811 });
812 });
813 });
814
815 describe("ln", () => {
816 it("[[Call]] returns the ln", () => {
817 assertStrictEquals(ln(1), 0);
818 assertStrictEquals(ln(Math.E), 1);
819 });
820
821 it("[[Call]] throws with big·ints", () => {
822 assertThrows(() => ln(1n));
823 });
824
825 it("[[Construct]] throws an error", () => {
826 assertThrows(() => new ln(1));
827 });
828
829 describe(".length", () => {
830 it("[[Get]] returns the correct length", () => {
831 assertStrictEquals(ln.length, 1);
832 });
833 });
834
835 describe(".name", () => {
836 it("[[Get]] returns the correct name", () => {
837 assertStrictEquals(ln.name, "ln");
838 });
839 });
840 });
841
842 describe("ln1p", () => {
843 it("[[Call]] returns the ln1p", () => {
844 assertStrictEquals(ln1p(1), Math.log1p(1));
845 assertStrictEquals(ln1p(Math.E - 1), 1);
846 });
847
848 it("[[Call]] throws with big·ints", () => {
849 assertThrows(() => ln1p(1n));
850 });
851
852 it("[[Construct]] throws an error", () => {
853 assertThrows(() => new ln1p(1));
854 });
855
856 describe(".length", () => {
857 it("[[Get]] returns the correct length", () => {
858 assertStrictEquals(ln1p.length, 1);
859 });
860 });
861
862 describe(".name", () => {
863 it("[[Get]] returns the correct name", () => {
864 assertStrictEquals(ln1p.name, "ln1p");
865 });
866 });
867 });
868
869 describe("log10", () => {
870 it("[[Call]] returns the log10", () => {
871 assertStrictEquals(log10(1), 0);
872 assertStrictEquals(log10(10), 1);
873 });
874
875 it("[[Call]] throws with big·ints", () => {
876 assertThrows(() => log10(1n));
877 });
878
879 it("[[Construct]] throws an error", () => {
880 assertThrows(() => new log10(1));
881 });
882
883 describe(".length", () => {
884 it("[[Get]] returns the correct length", () => {
885 assertStrictEquals(log10.length, 1);
886 });
887 });
888
889 describe(".name", () => {
890 it("[[Get]] returns the correct name", () => {
891 assertStrictEquals(log10.name, "log10");
892 });
893 });
894 });
895
896 describe("log2", () => {
897 it("[[Call]] returns the log2", () => {
898 assertStrictEquals(log2(1), 0);
899 assertStrictEquals(log2(2), 1);
900 });
901
902 it("[[Call]] throws with big·ints", () => {
903 assertThrows(() => log2(1n));
904 });
905
906 it("[[Construct]] throws an error", () => {
907 assertThrows(() => new log2(1));
908 });
909
910 describe(".length", () => {
911 it("[[Get]] returns the correct length", () => {
912 assertStrictEquals(log2.length, 1);
913 });
914 });
915
916 describe(".name", () => {
917 it("[[Get]] returns the correct name", () => {
918 assertStrictEquals(log2.name, "log2");
919 });
920 });
921 });
922
923 describe("max", () => {
924 it("[[Call]] returns the largest number", () => {
925 assertStrictEquals(max(1, -6, 92, -Infinity, 0), 92);
926 });
927
928 it("[[Call]] returns the largest big·int", () => {
929 assertStrictEquals(max(1n, -6n, 92n, 0n), 92n);
930 });
931
932 it("[[Call]] returns nan if any argument is nan", () => {
933 assertStrictEquals(max(0, NaN, 1), NaN);
934 });
935
936 it("[[Call]] returns -Infinity when called with no arguments", () => {
937 assertStrictEquals(max(), -Infinity);
938 });
939
940 it("[[Call]] throws if both big·int and number arguments are provided", () => {
941 assertThrows(() => max(-Infinity, 0n));
942 });
943
944 it("[[Construct]] throws an error", () => {
945 assertThrows(() => new max(1, 0));
946 });
947
948 describe(".length", () => {
949 it("[[Get]] returns the correct length", () => {
950 assertStrictEquals(max.length, 2);
951 });
952 });
953
954 describe(".name", () => {
955 it("[[Get]] returns the correct name", () => {
956 assertStrictEquals(max.name, "max");
957 });
958 });
959 });
960
961 describe("min", () => {
962 it("[[Call]] returns the largest number", () => {
963 assertStrictEquals(min(1, -6, 92, Infinity, 0), -6);
964 });
965
966 it("[[Call]] returns the largest big·int", () => {
967 assertStrictEquals(min(1n, -6n, 92n, 0n), -6n);
968 });
969
970 it("[[Call]] returns nan if any argument is nan", () => {
971 assertStrictEquals(min(0, NaN, 1), NaN);
972 });
973
974 it("[[Call]] returns Infinity when called with no arguments", () => {
975 assertStrictEquals(min(), Infinity);
976 });
977
978 it("[[Call]] throws if both big·int and number arguments are provided", () => {
979 assertThrows(() => min(Infinity, 0n));
980 });
981
982 it("[[Construct]] throws an error", () => {
983 assertThrows(() => new min(1, 0));
984 });
985
986 describe(".length", () => {
987 it("[[Get]] returns the correct length", () => {
988 assertStrictEquals(min.length, 2);
989 });
990 });
991
992 describe(".name", () => {
993 it("[[Get]] returns the correct name", () => {
994 assertStrictEquals(min.name, "min");
995 });
996 });
997 });
998
999 describe("rand", () => {
1000 it("[[Call]] returns a random number between 0 and 1", () => {
1001 // Not possible to fully test, obviously.
1002 const r = rand();
1003 assert(typeof r === "number");
1004 assert(r >= 0 && r < 1);
1005 });
1006
1007 it("[[Construct]] throws an error", () => {
1008 assertThrows(() => new rand());
1009 });
1010
1011 describe(".length", () => {
1012 it("[[Get]] returns the correct length", () => {
1013 assertStrictEquals(rand.length, 0);
1014 });
1015 });
1016
1017 describe(".name", () => {
1018 it("[[Get]] returns the correct name", () => {
1019 assertStrictEquals(rand.name, "rand");
1020 });
1021 });
1022 });
1023
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);
1029 });
1030
1031 it("[[Call]] throws with big·ints", () => {
1032 assertThrows(() => round(1n));
1033 });
1034
1035 it("[[Construct]] throws an error", () => {
1036 assertThrows(() => new round(1));
1037 });
1038
1039 describe(".length", () => {
1040 it("[[Get]] returns the correct length", () => {
1041 assertStrictEquals(round.length, 1);
1042 });
1043 });
1044
1045 describe(".name", () => {
1046 it("[[Get]] returns the correct name", () => {
1047 assertStrictEquals(round.name, "round");
1048 });
1049 });
1050 });
1051
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);
1059 });
1060
1061 it("[[Call]] works with big·ints", () => {
1062 assertStrictEquals(sgn(0n), 0n);
1063 assertStrictEquals(sgn(92n), 1n);
1064 assertStrictEquals(sgn(-92n), -1n);
1065 });
1066
1067 it("[[Construct]] throws an error", () => {
1068 assertThrows(() => new sgn(1));
1069 });
1070
1071 describe(".length", () => {
1072 it("[[Get]] returns the correct length", () => {
1073 assertStrictEquals(sgn.length, 1);
1074 });
1075 });
1076
1077 describe(".name", () => {
1078 it("[[Get]] returns the correct name", () => {
1079 assertStrictEquals(sgn.name, "sgn");
1080 });
1081 });
1082 });
1083
1084 describe("sin", () => {
1085 it("[[Call]] returns the sin", () => {
1086 assertStrictEquals(sin(1), Math.sin(1));
1087 assertStrictEquals(sin(0), 0);
1088 });
1089
1090 it("[[Call]] throws with big·ints", () => {
1091 assertThrows(() => sin(1n));
1092 });
1093
1094 it("[[Construct]] throws an error", () => {
1095 assertThrows(() => new sin(1));
1096 });
1097
1098 describe(".length", () => {
1099 it("[[Get]] returns the correct length", () => {
1100 assertStrictEquals(sin.length, 1);
1101 });
1102 });
1103
1104 describe(".name", () => {
1105 it("[[Get]] returns the correct name", () => {
1106 assertStrictEquals(sin.name, "sin");
1107 });
1108 });
1109 });
1110
1111 describe("sinh", () => {
1112 it("[[Call]] returns the sinh", () => {
1113 assertStrictEquals(sinh(1), Math.sinh(1));
1114 assertStrictEquals(sinh(0), 0);
1115 });
1116
1117 it("[[Call]] throws with big·ints", () => {
1118 assertThrows(() => sinh(1n));
1119 });
1120
1121 it("[[Construct]] throws an error", () => {
1122 assertThrows(() => new sinh(1));
1123 });
1124
1125 describe(".length", () => {
1126 it("[[Get]] returns the correct length", () => {
1127 assertStrictEquals(sinh.length, 1);
1128 });
1129 });
1130
1131 describe(".name", () => {
1132 it("[[Get]] returns the correct name", () => {
1133 assertStrictEquals(sinh.name, "sinh");
1134 });
1135 });
1136 });
1137
1138 describe("sqrt", () => {
1139 it("[[Call]] returns the sqrt", () => {
1140 assertStrictEquals(sqrt(1), 1);
1141 assertStrictEquals(sqrt(2), Math.SQRT2);
1142 });
1143
1144 it("[[Call]] throws with big·ints", () => {
1145 assertThrows(() => sqrt(1n));
1146 });
1147
1148 it("[[Construct]] throws an error", () => {
1149 assertThrows(() => new sqrt(1));
1150 });
1151
1152 describe(".length", () => {
1153 it("[[Get]] returns the correct length", () => {
1154 assertStrictEquals(sqrt.length, 1);
1155 });
1156 });
1157
1158 describe(".name", () => {
1159 it("[[Get]] returns the correct name", () => {
1160 assertStrictEquals(sqrt.name, "sqrt");
1161 });
1162 });
1163 });
1164
1165 describe("tan", () => {
1166 it("[[Call]] returns the tan", () => {
1167 assertStrictEquals(tan(1), Math.tan(1));
1168 assertStrictEquals(tan(0), 0);
1169 });
1170
1171 it("[[Call]] throws with big·ints", () => {
1172 assertThrows(() => tan(1n));
1173 });
1174
1175 it("[[Construct]] throws an error", () => {
1176 assertThrows(() => new tan(1));
1177 });
1178
1179 describe(".length", () => {
1180 it("[[Get]] returns the correct length", () => {
1181 assertStrictEquals(tan.length, 1);
1182 });
1183 });
1184
1185 describe(".name", () => {
1186 it("[[Get]] returns the correct name", () => {
1187 assertStrictEquals(tan.name, "tan");
1188 });
1189 });
1190 });
1191
1192 describe("tanh", () => {
1193 it("[[Call]] returns the tanh", () => {
1194 assertStrictEquals(tanh(1), Math.tanh(1));
1195 assertStrictEquals(tanh(0), 0);
1196 });
1197
1198 it("[[Call]] throws with big·ints", () => {
1199 assertThrows(() => tanh(1n));
1200 });
1201
1202 it("[[Construct]] throws an error", () => {
1203 assertThrows(() => new tanh(1));
1204 });
1205
1206 describe(".length", () => {
1207 it("[[Get]] returns the correct length", () => {
1208 assertStrictEquals(tanh.length, 1);
1209 });
1210 });
1211
1212 describe(".name", () => {
1213 it("[[Get]] returns the correct name", () => {
1214 assertStrictEquals(tanh.name, "tanh");
1215 });
1216 });
1217 });
1218
1219 describe("toBigInt", () => {
1220 it("[[Call]] converts to a big·int", () => {
1221 assertStrictEquals(toBigInt(2), 2n);
1222 });
1223
1224 it("[[Construct]] throws an error", () => {
1225 assertThrows(() => new toBigInt(1));
1226 });
1227
1228 describe(".length", () => {
1229 it("[[Get]] returns the correct length", () => {
1230 assertStrictEquals(toBigInt.length, 1);
1231 });
1232 });
1233
1234 describe(".name", () => {
1235 it("[[Get]] returns the correct name", () => {
1236 assertStrictEquals(toBigInt.name, "toBigInt");
1237 });
1238 });
1239 });
1240
1241 describe("toExponentialNotation", () => {
1242 it("[[Call]] converts to exponential notation", () => {
1243 assertStrictEquals(toExponentialNotation(231), "2.31e+2");
1244 });
1245
1246 it("[[Call]] works with big·ints", () => {
1247 assertStrictEquals(
1248 toExponentialNotation(9007199254740993n),
1249 "9.007199254740993e+15",
1250 );
1251 });
1252
1253 it("[[Call]] respects the specified number of fractional digits", () => {
1254 assertStrictEquals(
1255 toExponentialNotation(.00000000642, 3),
1256 "6.420e-9",
1257 );
1258 assertStrictEquals(toExponentialNotation(.00691, 1), "6.9e-3");
1259 assertStrictEquals(toExponentialNotation(.00685, 1), "6.9e-3");
1260 assertStrictEquals(toExponentialNotation(.004199, 2), "4.20e-3");
1261 assertStrictEquals(
1262 toExponentialNotation(6420000000n, 3),
1263 "6.420e+9",
1264 );
1265 assertStrictEquals(toExponentialNotation(6910n, 1), "6.9e+3");
1266 assertStrictEquals(toExponentialNotation(6850n, 1), "6.9e+3");
1267 assertStrictEquals(toExponentialNotation(4199n, 2), "4.20e+3");
1268 });
1269
1270 it("[[Construct]] throws an error", () => {
1271 assertThrows(() => new toExponentialNotation(1, 1));
1272 });
1273
1274 describe(".length", () => {
1275 it("[[Get]] returns the correct length", () => {
1276 assertStrictEquals(toExponentialNotation.length, 2);
1277 });
1278 });
1279
1280 describe(".name", () => {
1281 it("[[Get]] returns the correct name", () => {
1282 assertStrictEquals(
1283 toExponentialNotation.name,
1284 "toExponentialNotation",
1285 );
1286 });
1287 });
1288 });
1289
1290 describe("toFixedDecimalNotation", () => {
1291 it("[[Call]] converts to fixed decimal notation", () => {
1292 assertStrictEquals(toFixedDecimalNotation(69.4199, 3), "69.420");
1293 });
1294
1295 it("[[Call]] works with big·ints", () => {
1296 assertStrictEquals(
1297 toFixedDecimalNotation(9007199254740993n),
1298 "9007199254740993",
1299 );
1300 assertStrictEquals(
1301 toFixedDecimalNotation(9007199254740993n, 2),
1302 "9007199254740993.00",
1303 );
1304 });
1305
1306 it("[[Construct]] throws an error", () => {
1307 assertThrows(() => new toFixedDecimalNotation(1, 1));
1308 });
1309
1310 describe(".length", () => {
1311 it("[[Get]] returns the correct length", () => {
1312 assertStrictEquals(toFixedDecimalNotation.length, 2);
1313 });
1314 });
1315
1316 describe(".name", () => {
1317 it("[[Get]] returns the correct name", () => {
1318 assertStrictEquals(
1319 toFixedDecimalNotation.name,
1320 "toFixedDecimalNotation",
1321 );
1322 });
1323 });
1324 });
1325
1326 describe("toFloat32", () => {
1327 it("[[Call]] returns the 32‐bit floating‐point representation", () => {
1328 assertStrictEquals(
1329 toFloat32(562949953421313),
1330 Math.fround(562949953421313),
1331 );
1332 });
1333
1334 it("[[Call]] works with big·ints", () => {
1335 assertStrictEquals(
1336 toFloat32(562949953421313n),
1337 Math.fround(562949953421313),
1338 );
1339 });
1340
1341 it("[[Construct]] throws an error", () => {
1342 assertThrows(() => new toFloat32(1));
1343 });
1344
1345 describe(".length", () => {
1346 it("[[Get]] returns the correct length", () => {
1347 assertStrictEquals(toFloat32.length, 1);
1348 });
1349 });
1350
1351 describe(".name", () => {
1352 it("[[Get]] returns the correct name", () => {
1353 assertStrictEquals(toFloat32.name, "toFloat32");
1354 });
1355 });
1356 });
1357
1358 describe("toSignedIntegralNumeric", () => {
1359 it("[[Call]] converts to an int·n", () => {
1360 assertStrictEquals(toSignedIntegralNumeric(2, 7n), -1n);
1361 });
1362
1363 it("[[Call]] works with numbers", () => {
1364 assertStrictEquals(toSignedIntegralNumeric(2, 7), -1);
1365 });
1366
1367 it("[[Call]] works with non‐integers", () => {
1368 assertStrictEquals(toSignedIntegralNumeric(2, 7.21), -1);
1369 assertStrictEquals(toSignedIntegralNumeric(2, Infinity), 0);
1370 });
1371
1372 it("[[Construct]] throws an error", () => {
1373 assertThrows(() => new toSignedIntegralNumeric(1, 1));
1374 });
1375
1376 describe(".length", () => {
1377 it("[[Get]] returns the correct length", () => {
1378 assertStrictEquals(toSignedIntegralNumeric.length, 2);
1379 });
1380 });
1381
1382 describe(".name", () => {
1383 it("[[Get]] returns the correct name", () => {
1384 assertStrictEquals(
1385 toSignedIntegralNumeric.name,
1386 "toSignedIntegralNumeric",
1387 );
1388 });
1389 });
1390 });
1391
1392 describe("toIntegralNumber", () => {
1393 it("[[Call]] converts nan to zero", () => {
1394 assertStrictEquals(toIntegralNumber(NaN), 0);
1395 });
1396
1397 it("[[Call]] converts negative zero to positive zero", () => {
1398 assertStrictEquals(toIntegralNumber(-0), 0);
1399 });
1400
1401 it("[[Call]] drops the fractional part of negative numbers", () => {
1402 assertStrictEquals(toIntegralNumber(-1.79), -1);
1403 });
1404
1405 it("[[Call]] returns zero for infinity", () => {
1406 assertStrictEquals(toIntegralNumber(Infinity), 0);
1407 });
1408
1409 it("[[Call]] returns zero for negative infinity", () => {
1410 assertStrictEquals(toIntegralNumber(-Infinity), 0);
1411 });
1412
1413 it("[[Call]] works with big·ints", () => {
1414 assertStrictEquals(toIntegralNumber(2n), 2);
1415 });
1416
1417 it("[[Construct]] throws an error", () => {
1418 assertThrows(() => new toIntegralNumber(1));
1419 });
1420
1421 describe(".length", () => {
1422 it("[[Get]] returns the correct length", () => {
1423 assertStrictEquals(toIntegralNumber.length, 1);
1424 });
1425 });
1426
1427 describe(".name", () => {
1428 it("[[Get]] returns the correct name", () => {
1429 assertStrictEquals(toIntegralNumber.name, "toIntegralNumber");
1430 });
1431 });
1432 });
1433
1434 describe("toIntegralNumberOrInfinity", () => {
1435 it("[[Call]] converts nan to zero", () => {
1436 assertStrictEquals(toIntegralNumberOrInfinity(NaN), 0);
1437 });
1438
1439 it("[[Call]] converts negative zero to positive zero", () => {
1440 assertStrictEquals(toIntegralNumberOrInfinity(-0), 0);
1441 });
1442
1443 it("[[Call]] drops the fractional part of negative numbers", () => {
1444 assertStrictEquals(toIntegralNumberOrInfinity(-1.79), -1);
1445 });
1446
1447 it("[[Call]] returns infinity for infinity", () => {
1448 assertStrictEquals(toIntegralNumberOrInfinity(Infinity), Infinity);
1449 });
1450
1451 it("[[Call]] returns negative infinity for negative infinity", () => {
1452 assertStrictEquals(
1453 toIntegralNumberOrInfinity(-Infinity),
1454 -Infinity,
1455 );
1456 });
1457
1458 it("[[Call]] works with big·ints", () => {
1459 assertStrictEquals(toIntegralNumberOrInfinity(2n), 2);
1460 });
1461
1462 it("[[Construct]] throws an error", () => {
1463 assertThrows(() => new toIntegralNumberOrInfinity(1));
1464 });
1465
1466 describe(".length", () => {
1467 it("[[Get]] returns the correct length", () => {
1468 assertStrictEquals(toIntegralNumberOrInfinity.length, 1);
1469 });
1470 });
1471
1472 describe(".name", () => {
1473 it("[[Get]] returns the correct name", () => {
1474 assertStrictEquals(
1475 toIntegralNumberOrInfinity.name,
1476 "toIntegralNumberOrInfinity",
1477 );
1478 });
1479 });
1480 });
1481
1482 describe("toNumber", () => {
1483 it("[[Call]] converts to a number", () => {
1484 assertStrictEquals(toNumber(2n), 2);
1485 });
1486 });
1487
1488 describe("toNumeric", () => {
1489 it("[[Call]] returns a big·int argument", () => {
1490 assertStrictEquals(toNumeric(231n), 231n);
1491 });
1492
1493 it("[[Call]] converts to a numeric", () => {
1494 assertStrictEquals(toNumeric("231"), 231);
1495 });
1496
1497 it("[[Call]] prefers `valueOf`", () => {
1498 assertStrictEquals(
1499 toNumeric({
1500 toString() {
1501 return 0;
1502 },
1503 valueOf() {
1504 return 231n;
1505 },
1506 }),
1507 231n,
1508 );
1509 });
1510
1511 it("[[Construct]] throws an error", () => {
1512 assertThrows(() => new toNumeric(1));
1513 });
1514
1515 describe(".length", () => {
1516 it("[[Get]] returns the correct length", () => {
1517 assertStrictEquals(toNumeric.length, 1);
1518 });
1519 });
1520
1521 describe(".name", () => {
1522 it("[[Get]] returns the correct name", () => {
1523 assertStrictEquals(toNumeric.name, "toNumeric");
1524 });
1525 });
1526 });
1527
1528 describe("toUnsignedIntegralNumeric", () => {
1529 it("[[Call]] converts to an int·n", () => {
1530 assertStrictEquals(toUnsignedIntegralNumeric(2, 7n), 3n);
1531 });
1532
1533 it("[[Call]] works with numbers", () => {
1534 assertStrictEquals(toUnsignedIntegralNumeric(2, 7), 3);
1535 });
1536
1537 it("[[Call]] works with non‐integers", () => {
1538 assertStrictEquals(toUnsignedIntegralNumeric(2, 7.21), 3);
1539 assertStrictEquals(toUnsignedIntegralNumeric(2, Infinity), 0);
1540 });
1541
1542 it("[[Construct]] throws an error", () => {
1543 assertThrows(() => new toUnsignedIntegralNumeric(1, 1));
1544 });
1545
1546 describe(".length", () => {
1547 it("[[Get]] returns the correct length", () => {
1548 assertStrictEquals(toUnsignedIntegralNumeric.length, 2);
1549 });
1550 });
1551
1552 describe(".name", () => {
1553 it("[[Get]] returns the correct name", () => {
1554 assertStrictEquals(
1555 toUnsignedIntegralNumeric.name,
1556 "toUnsignedIntegralNumeric",
1557 );
1558 });
1559 });
1560 });
1561
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);
1567 });
1568
1569 it("[[Call]] throws with big·ints", () => {
1570 assertThrows(() => trunc(1n));
1571 });
1572
1573 it("[[Construct]] throws an error", () => {
1574 assertThrows(() => new trunc(1));
1575 });
1576
1577 describe(".length", () => {
1578 it("[[Get]] returns the correct length", () => {
1579 assertStrictEquals(trunc.length, 1);
1580 });
1581 });
1582
1583 describe(".name", () => {
1584 it("[[Get]] returns the correct name", () => {
1585 assertStrictEquals(trunc.name, "trunc");
1586 });
1587 });
1588 });
This page took 0.221493 seconds and 3 git commands to generate.