-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fishing.html
4898 lines (4454 loc) · 450 KB
/
fishing.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<title>Fishing Incremental</title>
<meta charset="utf-8">
<meta name="author" content="Leo Zhang">
<meta name="description" content="Start fishing and keep fishing in this wacky incremental game.">
<meta name="keywords" content="incremental game, clicker game, fishing, fish, rods, bait, game, entertainment">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="icon" type="image/png"
href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMAAAADACAYAAABS3GwHAAAIVElEQVR4Xu2dP6udRRCHb8DKr6CF+BGsba3SKH4BsVKJYitYCraiQa3EwjaYJpWVYG1vIxbBP2gjaiWiEUOi5uw7dya/mbOz+6SenZ19Zh7e++495+bKBf8gsDGBKxufnaND4AIBGIKtCSDA1u3n8AjADGxNAAG2bj+HRwBmYGsCCLB1+zk8AjADWxNAgK3bz+ERgBnYmgACbN1+Do8AzMDWBBBg6/ZzeARgBrYmgABbt5/DIwAzsDUBBNi6/RweAZiBrQkgwNbt5/AIwAxsTQABtm4/h0cAZmBrAgiwdfs5PALYM/CnHfJQEfTgofA93GLg2/wQwGbUNgIB7NYhgM2obQQC2K1DAJtR2wgEsFuHADajthEIYLcOAWxGbSN2FEAy0F/cuulq+tNXn3XFHwTv2DMVuwfy7AgTAdLGqV9iBAj2jCdAENxkyxAg2BAECIKbbBkCBBuCAEFwky1DgGBDECAIbrJlKwvgetn1DnR2HwO3Riv3Mg33ytAQIG1s1kmMAHd7yRNgnaH2nAQBEMAzL8vFIgACLDfUngMhAAJ45mW52O0EmO1nfe9EBW6HvFuM4peclSUPdbeDJ2+BECDsw5KzsuShECA85EcLl5yVJQ+FAAhwWQIIcFlSk8TxDqBtBAJoeaZnQwAtYgTQ8kzPNhLg1s0bkr2vPvu8JM9BkqlmbqpixOS3ugVCgNj0IECM29lW8QTQokcALc/0bAigRYwAWp7p2RBAixgBtDzTsyGAFjECaHkOs/38+x9FO9Vu8+P3P5zc8IWXXlEVkjqjqclVBIJ5proFQoBgFy8uUmc0NXn4yJqFCKDheJiFJ0AB5OAWCBAE51mGAB5atbEIUMAbAQogB7dAgCA4zzIE8NDKiXX9+ZNRCaqPEuQcsS7raKDrKvjvToHbJNd7rSv4XBCMfRFA2BgEEMIsSoUAQtAIIIRZlAoBhKARQAizKBUCCEEjgBBmUSoEEIJGACFMcSoGXQz0VLrZBBgdWXU71OkWCAEQ4B4BBAgOA/f9x+B4AgQHq2AZT4ACyAhQADm4BQIEwXmWIYCHVm0sAhTwRgAbsmQQ72wzegF35ednerthngiVAN6X1I8/fN9T5jD2YN+T8xa5BXIN6MGpEEDScm0SBLB5IoDNqG0EAtitQwCbUdsIBLBbhwA2o7YRCGC3DgFsRm0jEOB+61yD/uVn755s+lPPvCYZBm57JBjvJVEN+qiqCW+BTpZ6dAuEANqZmyobAvzTDgSYaizrikEABKibtgl3QgAEmHAs60pCAASom7YJd0KA+wJIXna9PR7dDnHb4yUZi88WIFZV3qrRrdTfL8EIkMd92swIwBNg2uGsKAwBEKBizqbdAwEQYNrhrCgMARCgYs6m3QMBDAFGn+1RdfS73x5TpSJPgAACIEBgbNZZggAIsM40B06CAAgQGJt1liAAAqwzzYGTIAACBMZmnSUIYAjw6fU3Urv9+Ve/pOYn+TGBn769vRWiT27cPHne4WeBEGDt+UAAngBrT7hxOgRAAATYiAA/Am3U7MsclScAT4DLzMmyMQhgCDDqvOrl+Llrb5/c4vVXry07dDMdDAEQYKZ5LK8FARCgfOhm2hABEGCmeSyvBQEQoHzoZtoQARBgpnksrwUB7gswgu/6cymj26HRbY+349wOeYkdx68qwOgXXiMasj+OiwDaAc3OhgA8AbJnbOr8CIAAUw9odnEIgADZMzZ1fgRAgKkHNLs4BLAFkNwOHTRS8h9lczukVUUlxu1vvj5Z2ONPPKkt+H/ZDm6B1vyf4hFAO08IYPN0/X6AJ4ANdKYIBLC7gQA2o7YRCGC3DgFsRm0jEMBuHQLYjNpGIMC8rZOIx0vzcYNVAox2Gd0OjeJHt0bez/zcyS+7BTqXIghQQB4BCiAHt0CAIDjPMgTw0KqNRYAC3ghQADm4BQIEwXmWIYCHVm0sAhTwRoACyOItEEMINFsAb6mq257RvkffCPPWeq54BBCSRwAhzKJUCCAEjQBCmEWpEEAIGgGEMItSIYAQNAIIYRalQgAhaAQQwjxzqpNivPnyi2cp69dHHj3LvtmbjoQJ3N6c5aJmhVugETgEyJ7+O/kRoABycAsECILzLEMAD63aWAQo4I0ABZCDWyBAEJxnGQJ4aNXGIkABbwQogBzcYioBgmd4YNlbH3x0MpXqm27vvHddVepZbnW8xXML5CV25ngE0DYAAbQ807MhgBYxAmh5pmdDAC1iBNDyTM+GAFrECKDlmZ4NAbSIEUDLMz3bSID0jQd/V6dg39QtECAVrz45AmiZIoCWZ3o2BNAiRgAtz/RsCKBFjABanunZEECLGAG0PNOzIYAW8XYCjPCd65tio3oCg75yL7VT/69sK0NzfVcYAdJmbOrECHC3PQgw9ZymFYcACJA2XB0SIwACdJjTtBoRAAHShqtD4pUFGPF3vRyrbo0CtzqjrXfsWZpLO8JEgLRx6pcYAYI9894a8QQIgk5ehgBBwAgQBDfZMgQINgQBguAmW4YAwYYgQBDcZMt2FMDbAslL88Gm9MDbEWE88G2YCGAzahuBAHbrEMBm1DYCAezWIYDNqG0EAtitQwCbUdsIBLBbhwA2o7YRCNC2dRSuIIAACorkaEsAAdq2jsIVBBBAQZEcbQkgQNvWUbiCAAIoKJKjLQEEaNs6ClcQQAAFRXK0JYAAbVtH4QoCCKCgSI62BBCgbesoXEEAARQUydGWAAK0bR2FKwgggIIiOdoSQIC2raNwBQEEUFAkR1sCCNC2dRSuIIAACorkaEsAAdq2jsIVBBBAQZEcbQkgQNvWUbiCAAIoKJKjLQEEaNs6ClcQQAAFRXK0JfAX2SkO2bg5QOcAAAAASUVORK5CYII=">
<!--
The HyperNumber system was created by me! It's a high-performance AND high-precision system because I'm insane enough to create my own system to reach 10^^(10^50).
For performance reasons, the game uses HyperNumber for most values.
ExpantaNum was created by Naruyoko, a large number system supporting up to a HUGE f_{w+1}(9e15)!
MIT License
Copyright (c) 2020 Naruyoko
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-->
<script id="bigScript">
// ExpantaNum.min.js
!function (r) { "use strict"; var e = { maxOps: 1e3, serializeMode: 0, debug: 0 }, t = "[ExpantaNumError] ", n = t + "Invalid argument: ", a = /^[-\+]*(Infinity|NaN|(J+|J\^\d+ )?(10(\^+|\{[1-9]\d*\})|\(10(\^+|\{[1-9]\d*\})\)\^[1-9]\d* )*((\d+(\.\d*)?|\d*\.\d+)?([Ee][-\+]*))*(0|\d+(\.\d*)?|\d*\.\d+))$/, i = Math.log10(9007199254740991), o = {}, s = {}, u = { ZERO: 0, ONE: 1 }; u.E = Math.E, u.LN2 = Math.LN2, u.LN10 = Math.LN10, u.LOG2E = Math.LOG2E, u.LOG10E = Math.LOG10E, u.PI = Math.PI, u.SQRT1_2 = Math.SQRT1_2, u.SQRT2 = Math.SQRT2, u.MAX_SAFE_INTEGER = 9007199254740991, u.MIN_SAFE_INTEGER = Number.MIN_SAFE_INTEGER, u.NaN = Number.NaN, u.NEGATIVE_INFINITY = Number.NEGATIVE_INFINITY, u.POSITIVE_INFINITY = Number.POSITIVE_INFINITY, u.E_MAX_SAFE_INTEGER = "e9007199254740991", u.EE_MAX_SAFE_INTEGER = "ee9007199254740991", u.TETRATED_MAX_SAFE_INTEGER = "10^^9007199254740991", u.GRAHAMS_NUMBER = "J^63 10^^^(10^)^7625597484984 3638334640023.7783", o.absoluteValue = o.abs = function () { var r = this.clone(); return r.sign = 1, r }, s.absoluteValue = s.abs = function (r) { return new e(r).abs() }, o.negate = o.neg = function () { var r = this.clone(); return r.sign = -1 * r.sign, r }, s.negate = s.neg = function (r) { return new e(r).neg() }, o.compareTo = o.cmp = function (r) { if (r instanceof e || (r = new e(r)), isNaN(this.array[0][1]) || isNaN(r.array[0][1])) return NaN; if (this.array[0][1] == 1 / 0 && r.array[0][1] != 1 / 0) return this.sign; if (this.array[0][1] != 1 / 0 && r.array[0][1] == 1 / 0) return -r.sign; if (1 == this.array.length && 0 === this.array[0][1] && 1 == r.array.length && 0 === r.array[0][1]) return 0; if (this.sign != r.sign) return this.sign; var t, n = this.sign; if (this.layer > r.layer) t = 1; else if (this.layer < r.layer) t = -1; else { for (var a, i, o = 0, s = Math.min(this.array.length, r.array.length); o < s; ++o) { if (a = this.array[this.array.length - 1 - o], i = r.array[r.array.length - 1 - o], a[0] > i[0] || a[0] == i[0] && a[1] > i[1]) { t = 1; break } if (a[0] < i[0] || a[0] == i[0] && a[1] < i[1]) { t = -1; break } } void 0 === t && (t = this.array.length == r.array.length ? 0 : this.array.length > r.array.length ? (a = this.array[this.array.length - s])[0] >= 1 || a[1] > 10 ? 1 : -1 : (a = r.array[r.array.length - s])[0] >= 1 || a[1] > 10 ? -1 : 1) } return t * n }, s.compare = s.cmp = function (r, t) { return new e(r).cmp(t) }, o.greaterThan = o.gt = function (r) { return this.cmp(r) > 0 }, s.greaterThan = s.gt = function (r, t) { return new e(r).gt(t) }, o.greaterThanOrEqualTo = o.gte = function (r) { return this.cmp(r) >= 0 }, s.greaterThanOrEqualTo = s.gte = function (r, t) { return new e(r).gte(t) }, o.lessThan = o.lt = function (r) { return this.cmp(r) < 0 }, s.lessThan = s.lt = function (r, t) { return new e(r).lt(t) }, o.lessThanOrEqualTo = o.lte = function (r) { return this.cmp(r) <= 0 }, s.lessThanOrEqualTo = s.lte = function (r, t) { return new e(r).lte(t) }, o.equalsTo = o.equal = o.eq = function (r) { return 0 === this.cmp(r) }, s.equalsTo = s.equal = s.eq = function (r, t) { return new e(r).eq(t) }, o.notEqualsTo = o.notEqual = o.neq = function (r) { return 0 !== this.cmp(r) }, s.notEqualsTo = s.notEqual = s.neq = function (r, t) { return new e(r).neq(t) }, o.minimum = o.min = function (r) { return this.lt(r) ? this.clone() : new e(r) }, s.minimum = s.min = function (r, t) { return new e(r).min(t) }, o.maximum = o.max = function (r) { return this.gt(r) ? this.clone() : new e(r) }, s.maximum = s.max = function (r, t) { return new e(r).max(t) }, o.compareTo_tolerance = o.cmp_tolerance = function (r, t) { return r instanceof e || (r = new e(r)), this.eq_tolerance(r, t) ? 0 : this.cmp(r) }, s.compare_tolerance = s.cmp_tolerance = function (r, t, n) { return new e(r).cmp_tolerance(t, n) }, o.greaterThan_tolerance = o.gt_tolerance = function (r, t) { return r instanceof e || (r = new e(r)), !this.eq_tolerance(r, t) && this.gt(r) }, s.greaterThan_tolerance = s.gt_tolerance = function (r, t, n) { return new e(r).gt_tolerance(t, n) }, o.greaterThanOrEqualTo_tolerance = o.gte_tolerance = function (r, t) { return r instanceof e || (r = new e(r)), this.eq_tolerance(r, t) || this.gt(r) }, s.greaterThanOrEqualTo_tolerance = s.gte_tolerance = function (r, t, n) { return new e(r).gte_tolerance(t, n) }, o.lessThan_tolerance = o.lt_tolerance = function (r, t) { return r instanceof e || (r = new e(r)), !this.eq_tolerance(r, t) && this.lt(r) }, s.lessThan_tolerance = s.lt_tolerance = function (r, t, n) { return new e(r).lt_tolerance(t, n) }, o.lessThanOrEqualTo_tolerance = o.lte_tolerance = function (r, t) { return r instanceof e || (r = new e(r)), this.eq_tolerance(r, t) || this.lt(r) }, s.lessThanOrEqualTo_tolerance = s.lte_tolerance = function (r, t, n) { return new e(r).lte_tolerance(t, n) }, o.equalsTo_tolerance = o.equal_tolerance = o.eq_tolerance = function (r, t) { if (r instanceof e || (r = new e(r)), null == t && (t = 1e-7), this.isNaN() || r.isNaN() || this.isFinite() != r.isFinite()) return !1; if (this.sign != r.sign) return !1; if (Math.abs(this.layer - r.layer) > 1) return !1; var n, a; if (this.layer != r.layer) { if (this.layer > r.layer ? (o = this, s = r) : (o = r, s = this), 2 != o.array.length || 0 !== o.array[0][0] || 1 != o.array[1][0] || 1 != o.array[1][1]) return !1; n = o.array[0][1], a = s.array[s.array.length - 1][1] >= 10 ? Math.log10(s.array[s.array.length - 1][0] + 1) : Math.log10(s.array[s.array.length - 1][0]) } else { if (Math.abs(this.array[this.array.length - 1][0] - r.array[r.array.length - 1][0]) > 1) return !1; for (var i = 1; Math.max(this.array.length, r.array.length) - i >= 0; ++i) { var o, s, u, l, f = this.array[this.array.length - i][0], h = r.array[r.array.length - i][0]; if (f != h) f > h ? (o = this, s = r) : (o = r, s = this, f = h), u = o.array[o.array.length - i][1], l = 0; else if (s = r, u = (o = this).array[o.array.length - i][1], l = s.array[s.array.length - i][1], o.array.length - i == 0) { n = u, a = l; break } if (Math.abs(u - l) > 1) return !1; if (u != l) { if (!(o.array.length - i < 2 || o.array.length - i == 2 && 0 === o.array[0][0] && 1 == o.array[1][0] && 1 == o.array[1][1])) return !1; n = o.array[0][1], a = 1 == f ? Math.log10(s.operator(0)) : 2 == f && s.operator(0) >= 1e10 ? Math.log10(s.operator(1) + 2) : s.operator(f - 2) >= 10 ? Math.log10(s.operator(f - 1) + 1) : Math.log10(s.operator(f - 1)); break } } } return Math.abs(n - a) <= t * Math.max(Math.abs(n), Math.abs(a)) }, s.equalsTo_tolerance = s.equal_tolerance = s.eq_tolerance = function (r, t, n) { return new e(r).eq_tolerance(t, n) }, o.notEqualsTo_tolerance = o.notEqual_tolerance = o.neq_tolerance = function (r, e) { return !this.eq_tolerance(r, e) }, s.notEqualsTo_tolerance = s.notEqual_tolerance = s.neq_tolerance = function (r, t, n) { return new e(r).neq_tolerance(t, n) }, o.isPositive = o.ispos = function () { return this.gt(e.ZERO) }, s.isPositive = s.ispos = function (r) { return new e(r).ispos() }, o.isNegative = o.isneg = function () { return this.lt(e.ZERO) }, s.isNegative = s.isneg = function (r) { return new e(r).isneg() }, o.isNaN = function () { return isNaN(this.array[0][1]) }, s.isNaN = function (r) { return new e(r).isNaN() }, o.isFinite = function () { return isFinite(this.array[0][1]) }, s.isFinite = function (r) { return new e(r).isFinite() }, o.isInfinite = function () { return this.array[0][1] == 1 / 0 }, s.isInfinite = function (r) { return new e(r).isInfinite() }, o.isInteger = o.isint = function () { return -1 == this.sign ? this.abs().isint() : !!this.gt(e.MAX_SAFE_INTEGER) || Number.isInteger(this.toNumber()) }, s.isInteger = s.isint = function (r) { return new e(r).isint() }, o.floor = function () { return this.isInteger() ? this.clone() : new e(Math.floor(this.toNumber())) }, s.floor = function (r) { return new e(r).floor() }, o.ceiling = o.ceil = function () { return this.isInteger() ? this.clone() : new e(Math.ceil(this.toNumber())) }, s.ceiling = s.ceil = function (r) { return new e(r).ceil() }, o.round = function () { return this.isInteger() ? this.clone() : new e(Math.round(this.toNumber())) }, s.round = function (r) { return new e(r).round() }; var l = !1; o.plus = o.add = function (r) { var n = this.clone(); if (r = new e(r), e.debug >= e.NORMAL && (console.log(this + "+" + r), l || (console.warn(t + "Debug output via 'debug' is being deprecated and will be removed in the future!"), l = !0)), -1 == n.sign) return n.neg().add(r.neg()).neg(); if (-1 == r.sign) return n.sub(r.neg()); if (n.eq(e.ZERO)) return r; if (r.eq(e.ZERO)) return n; if (n.isNaN() || r.isNaN() || n.isInfinite() && r.isInfinite() && n.eq(r.neg())) return e.NaN.clone(); if (n.isInfinite()) return n; if (r.isInfinite()) return r; var a, i = n.min(r), o = n.max(r), s = o.operator(0), u = o.operator(1); if (o.gt(e.E_MAX_SAFE_INTEGER) || o.div(i).gt(e.MAX_SAFE_INTEGER)) a = o; else if (u) { if (1 == u) { var f = i.operator(1) ? i.operator(0) : Math.log10(i.operator(0)); a = new e([f + Math.log10(Math.pow(10, s - f) + 1), 1]) } } else a = new e(n.toNumber() + r.toNumber()); return i = o = null, a }, s.plus = s.add = function (r, t) { return new e(r).add(t) }, o.minus = o.sub = function (r) { var t = this.clone(); if (r = new e(r), e.debug >= e.NORMAL && console.log(t + "-" + r), -1 == t.sign) return t.neg().sub(r.neg()).neg(); if (-1 == r.sign) return t.add(r.neg()); if (t.eq(r)) return e.ZERO.clone(); if (r.eq(e.ZERO)) return t; if (t.isNaN() || r.isNaN() || t.isInfinite() && r.isInfinite()) return e.NaN.clone(); if (t.isInfinite()) return t; if (r.isInfinite()) return r.neg(); var n, a = t.min(r), i = t.max(r), o = r.gt(t), s = i.operator(0), u = i.operator(1); if (i.gt(e.E_MAX_SAFE_INTEGER) || i.div(a).gt(e.MAX_SAFE_INTEGER)) n = i, n = o ? n.neg() : n; else if (u) { if (1 == u) { var l = a.operator(1) ? a.operator(0) : Math.log10(a.operator(0)); n = new e([l + Math.log10(Math.pow(10, s - l) - 1), 1]), n = o ? n.neg() : n } } else n = new e(t.toNumber() - r.toNumber()); return a = i = null, n }, s.minus = s.sub = function (r, t) { return new e(r).sub(t) }, o.times = o.mul = function (r) { var t = this.clone(); if (r = new e(r), e.debug >= e.NORMAL && console.log(t + "*" + r), t.sign * r.sign == -1) return t.abs().mul(r.abs()).neg(); if (-1 == t.sign) return t.abs().mul(r.abs()); if (t.isNaN() || r.isNaN() || t.eq(e.ZERO) && r.isInfinite() || t.isInfinite() && r.abs().eq(e.ZERO)) return e.NaN.clone(); if (r.eq(e.ZERO)) return e.ZERO.clone(); if (r.eq(e.ONE)) return t.clone(); if (t.isInfinite()) return t; if (r.isInfinite()) return r; if (t.max(r).gt(e.EE_MAX_SAFE_INTEGER)) return t.max(r); var n = t.toNumber() * r.toNumber(); return n <= 9007199254740991 ? new e(n) : e.pow(10, t.log10().add(r.log10())) }, s.times = s.mul = function (r, t) { return new e(r).mul(t) }, o.divide = o.div = function (r) { var t = this.clone(); if (r = new e(r), e.debug >= e.NORMAL && console.log(t + "/" + r), t.sign * r.sign == -1) return t.abs().div(r.abs()).neg(); if (-1 == t.sign) return t.abs().div(r.abs()); if (t.isNaN() || r.isNaN() || t.isInfinite() && r.isInfinite() || t.eq(e.ZERO) && r.eq(e.ZERO)) return e.NaN.clone(); if (r.eq(e.ZERO)) return e.POSITIVE_INFINITY.clone(); if (r.eq(e.ONE)) return t.clone(); if (t.eq(r)) return e.ONE.clone(); if (t.isInfinite()) return t; if (r.isInfinite()) return e.ZERO.clone(); if (t.max(r).gt(e.EE_MAX_SAFE_INTEGER)) return t.gt(r) ? t.clone() : e.ZERO.clone(); var n = t.toNumber() / r.toNumber(); if (n <= 9007199254740991) return new e(n); var a = e.pow(10, t.log10().sub(r.log10())), i = a.floor(); return a.sub(i).lt(new e(1e-9)) ? i : a }, s.divide = s.div = function (r, t) { return new e(r).div(t) }, o.reciprocate = o.rec = function () { return e.debug >= e.NORMAL && console.log(this + "^-1"), this.isNaN() || this.eq(e.ZERO) ? e.NaN.clone() : this.abs().gt("2e323") ? e.ZERO.clone() : new e(1 / this) }, s.reciprocate = s.rec = function (r) { return new e(r).rec() }, o.modular = o.mod = function (r) { return (r = new e(r)).eq(e.ZERO) ? e.ZERO.clone() : this.sign * r.sign == -1 ? this.abs().mod(r.abs()).neg() : -1 == this.sign ? this.abs().mod(r.abs()) : this.sub(this.div(r).floor().mul(r)) }, s.modular = s.mod = function (r, t) { return new e(r).mod(t) }; o.gamma = function () { var r = this.clone(); if (r.gt(e.TETRATED_MAX_SAFE_INTEGER)) return r; if (r.gt(e.E_MAX_SAFE_INTEGER)) return e.exp(r); if (r.gt(e.MAX_SAFE_INTEGER)) return e.exp(e.mul(r, e.ln(r).sub(1))); var t = r.operator(0); if (t > 1) { if (t < 24) return new e(function (r) { if (!isFinite(r)) return r; if (r < -50) return r == Math.trunc(r) ? Number.NEGATIVE_INFINITY : 0; for (var e = 1; r < 10;)e *= r, ++r; var t = .9189385332046727; t += (.5 + (r -= 1)) * Math.log(r), t -= r; var n = r * r, a = r; return t += 1 / (12 * a), t -= 1 / (360 * (a *= n)), t += 1 / (1260 * (a *= a * n)), t -= 1 / (1680 * (a *= n)), t += 1 / (1188 * (a *= n)), t -= 691 / (360360 * (a *= n)), t += 7 / (1092 * (a *= n)), t -= 3617 / (122400 * (a *= n)), Math.exp(t) / e }(r.sign * t)); var n = t - 1, a = .9189385332046727; a += (n + .5) * Math.log(n); var i = n * n, o = n, s = 12 * o, u = 1 / s, l = (a -= n) + u; if (l == a) return e.exp(a); if ((l = (a = l) - (u = 1 / (s = 360 * (o *= i)))) == a) return e.exp(a); a = l; var f = 1 / (s = 1260 * (o *= i)); return a += f, a -= f = 1 / (s = 1680 * (o *= i)), e.exp(a) } return this.rec() }, s.gamma = function (r) { return new e(r).gamma() }, s.factorials = [1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800, 479001600, 6227020800, 87178291200, 1307674368e3, 20922789888e3, 355687428096e3, 6402373705728e3, 0x1b02b9306890000, 243290200817664e4, 5109094217170944e4, 0x3ceea4c2b3e0d80000, 2.585201673888498e22, 6.204484017332394e23, 1.5511210043330986e25, 4.0329146112660565e26, 1.0888869450418352e28, 3.0488834461171387e29, 8.841761993739702e30, 2.6525285981219107e32, 8.222838654177922e33, 2.631308369336935e35, 8.683317618811886e36, 2.9523279903960416e38, 1.0333147966386145e40, 3.7199332678990125e41, 1.3763753091226346e43, 5.230226174666011e44, 2.0397882081197444e46, 8.159152832478977e47, 3.345252661316381e49, 1.40500611775288e51, 6.041526306337383e52, 2.658271574788449e54, 1.1962222086548019e56, 5.502622159812089e57, 2.5862324151116818e59, 1.2413915592536073e61, 6.082818640342675e62, 3.0414093201713376e64, 1.5511187532873822e66, 8.065817517094388e67, 4.2748832840600255e69, 2.308436973392414e71, 1.2696403353658276e73, 7.109985878048635e74, 4.0526919504877214e76, 2.3505613312828785e78, 1.3868311854568984e80, 8.32098711274139e81, 5.075802138772248e83, 3.146997326038794e85, 1.98260831540444e87, 1.2688693218588417e89, 8.247650592082472e90, 5.443449390774431e92, 3.647111091818868e94, 2.4800355424368305e96, 1.711224524281413e98, 1.1978571669969892e100, 8.504785885678623e101, 6.1234458376886085e103, 4.4701154615126844e105, 3.307885441519386e107, 2.48091408113954e109, 1.8854947016660504e111, 1.4518309202828587e113, 1.1324281178206297e115, 8.946182130782976e116, 7.156945704626381e118, 5.797126020747368e120, 4.753643337012842e122, 3.945523969720659e124, 3.314240134565353e126, 2.81710411438055e128, 2.4227095383672734e130, 2.107757298379528e132, 1.8548264225739844e134, 1.650795516090846e136, 1.4857159644817615e138, 1.352001527678403e140, 1.2438414054641308e142, 1.1567725070816416e144, 1.087366156656743e146, 1.032997848823906e148, 9.916779348709496e149, 9.619275968248212e151, 9.426890448883248e153, 9.332621544394415e155, 9.332621544394415e157, 9.42594775983836e159, 9.614466715035127e161, 9.90290071648618e163, 1.0299016745145628e166, 1.081396758240291e168, 1.1462805637347084e170, 1.226520203196138e172, 1.324641819451829e174, 1.4438595832024937e176, 1.588245541522743e178, 1.7629525510902446e180, 1.974506857221074e182, 2.2311927486598138e184, 2.5435597334721877e186, 2.925093693493016e188, 3.393108684451898e190, 3.969937160808721e192, 4.684525849754291e194, 5.574585761207606e196, 6.689502913449127e198, 8.094298525273444e200, 9.875044200833601e202, 1.214630436702533e205, 1.506141741511141e207, 1.882677176888926e209, 2.372173242880047e211, 3.0126600184576594e213, 3.856204823625804e215, 4.974504222477287e217, 6.466855489220474e219, 8.47158069087882e221, 1.1182486511960043e224, 1.4872707060906857e226, 1.9929427461615188e228, 2.6904727073180504e230, 3.659042881952549e232, 5.012888748274992e234, 6.917786472619489e236, 9.615723196941089e238, 1.3462012475717526e241, 1.898143759076171e243, 2.695364137888163e245, 3.854370717180073e247, 5.5502938327393044e249, 8.047926057471992e251, 1.1749972043909107e254, 1.727245890454639e256, 2.5563239178728654e258, 3.80892263763057e260, 5.713383956445855e262, 8.62720977423324e264, 1.3113358856834524e267, 2.0063439050956823e269, 3.0897696138473508e271, 4.789142901463394e273, 7.471062926282894e275, 1.1729568794264145e278, 1.853271869493735e280, 2.9467022724950384e282, 4.7147236359920616e284, 7.590705053947219e286, 1.2296942187394494e289, 2.0044015765453026e291, 3.287218585534296e293, 5.423910666131589e295, 9.003691705778438e297, 1.503616514864999e300, 2.5260757449731984e302, 4.269068009004705e304, 7.257415615307999e306], o.factorial = o.fact = function () { var r = this.clone(), t = e.factorials; if (r.lt(e.ZERO) || !r.isint()) return r.add(1).gamma(); if (r.lte(170)) return new e(t[+r]); var n = +r; return n < 500 && (n += 163879 / 209018880 * Math.pow(n, 5)), n < 1e3 && (n += -571 / 2488320 * Math.pow(n, 4)), n < 5e4 && (n += -139 / 51840 * Math.pow(n, 3)), n < 1e7 && (n += 1 / 288 * Math.pow(n, 2)), n < 1e20 && (n += 1 / 12 * n), r.div(e.E).pow(r).mul(r.mul(e.PI).mul(2).sqrt()).times(1) }, s.factorial = s.fact = function (r) { return new e(r).fact() }, o.toPower = o.pow = function (r) { if (r = new e(r), e.debug >= e.NORMAL && console.log(this + "^" + r), r.eq(e.ZERO)) return e.ONE.clone(); if (r.eq(e.ONE)) return this.clone(); if (r.lt(e.ZERO)) return this.pow(r.neg()).rec(); if (this.lt(e.ZERO) && r.isint()) return r.mod(2).lt(e.ONE) ? this.abs().pow(r) : this.abs().pow(r).neg(); if (this.lt(e.ZERO)) return e.NaN.clone(); if (this.eq(e.ONE)) return e.ONE.clone(); if (this.eq(e.ZERO)) return e.ZERO.clone(); if (this.max(r).gt(e.TETRATED_MAX_SAFE_INTEGER)) return this.max(r); if (this.eq(10)) return r.gt(e.ZERO) ? (r.operator(1, r.operator(1) + 1 || 1), r.normalize(), r) : new e(Math.pow(10, r.toNumber())); if (r.lt(e.ONE)) return this.root(r.rec()); var t = Math.pow(this.toNumber(), r.toNumber()); return t <= 9007199254740991 ? new e(t) : e.pow(10, this.log10().mul(r)) }, s.toPower = s.pow = function (r, t) { return new e(r).pow(t) }, o.exponential = o.exp = function () { return e.pow(Math.E, this) }, s.exponential = s.exp = function (r) { return e.pow(Math.E, r) }, o.squareRoot = o.sqrt = function () { return this.root(2) }, s.squareRoot = s.sqrt = function (r) { return new e(r).root(2) }, o.cubeRoot = o.cbrt = function () { return this.root(3) }, s.cubeRoot = s.cbrt = function (r) { return new e(r).root(3) }, o.root = function (r) { return r = new e(r), e.debug >= e.NORMAL && console.log(this + "root" + r), r.eq(e.ONE) ? this.clone() : r.lt(e.ZERO) ? this.root(r.neg()).rec() : r.lt(e.ONE) ? this.pow(r.rec()) : this.lt(e.ZERO) && r.isint() && r.mod(2).eq(e.ONE) ? this.neg().root(r).neg() : this.lt(e.ZERO) ? e.NaN.clone() : this.eq(e.ONE) ? e.ONE.clone() : this.eq(e.ZERO) ? e.ZERO.clone() : this.max(r).gt(e.TETRATED_MAX_SAFE_INTEGER) ? this.gt(r) ? this.clone() : e.ZERO.clone() : e.pow(10, this.log10().div(r)) }, s.root = function (r, t) { return new e(r).root(t) }, o.generalLogarithm = o.log10 = function () { var r = this.clone(); return e.debug >= e.NORMAL && console.log("log" + this), r.lt(e.ZERO) ? e.NaN.clone() : r.eq(e.ZERO) ? e.NEGATIVE_INFINITY.clone() : r.lte(e.MAX_SAFE_INTEGER) ? new e(Math.log10(r.toNumber())) : r.isFinite() ? r.gt(e.TETRATED_MAX_SAFE_INTEGER) ? r : (r.operator(1, r.operator(1) - 1), r.normalize()) : r }, s.generalLogarithm = s.log10 = function (r) { return new e(r).log10() }, o.logarithm = o.logBase = function (r) { return void 0 === r && (r = Math.E), this.log10().div(e.log10(r)) }, s.logarithm = s.logBase = function (r, t) { return new e(r).logBase(t) }, o.naturalLogarithm = o.log = o.ln = function () { return this.logBase(Math.E) }, s.naturalLogarithm = s.log = s.ln = function (r) { return new e(r).ln() }; var f = function (r, e, t) { var n; if (void 0 === e && (e = 1e-10), void 0 === t && (t = !0), !Number.isFinite(r)) return r; if (t) { if (0 === r) return r; if (1 === r) return .5671432904097838; n = r < 10 ? 0 : Math.log(r) - Math.log(Math.log(r)) } else { if (0 === r) return -1 / 0; n = r <= -.1 ? -2 : Math.log(-r) - Math.log(-Math.log(-r)) } for (var a = 0; a < 100; ++a) { var i = (r * Math.exp(-n) + n * n) / (n + 1); if (Math.abs(i - n) < e * Math.abs(i)) return i; n = i } throw Error("Iteration failed to converge: " + r) }, h = function (r, t, n) { var a; if (void 0 === t && (t = 1e-10), void 0 === n && (n = !0), !(r = new e(r)).isFinite()) return r; if (n) { if (r.eq(e.ZERO)) return r; if (r.eq(e.ONE)) return new e(.5671432904097838); a = e.ln(r) } else { if (r.eq(e.ZERO)) return e.NEGATIVE_INFINITY.clone(); a = e.ln(r.neg()) } for (var i = 0; i < 100; ++i) { var o = a.neg().exp(), s = a.sub(r.mul(o)), u = a.add(e.ONE).sub(a.add(2).mul(s).div(e.mul(2, a).add(2))); if (u.eq(e.ZERO)) return a; var l = a.sub(s.div(u)); if (e.abs(l.sub(a)).lt(e.abs(l).mul(t))) return l; a = l } throw Error("Iteration failed to converge: " + r) }; o.lambertw = function (r) { void 0 === r && (r = !0); var t = this.clone(); return t.isNaN() ? t : t.lt(-.3678794411710499) ? e.NaN.clone() : r ? t.gt(e.TETRATED_MAX_SAFE_INTEGER) ? t : t.gt(e.EE_MAX_SAFE_INTEGER) ? (t.operator(1, t.operator(1) - 1), t) : t.gt(e.MAX_SAFE_INTEGER) ? h(t) : new e(f(t.sign * t.operator(0))) : t.ispos() ? e.NaN.clone() : t.abs().gt(e.EE_MAX_SAFE_INTEGER) ? t.neg().recip().lambertw().neg() : t.abs().gt(e.MAX_SAFE_INTEGER) ? h(t, 1e-10, !1) : new e(f(t.sign * t.operator(0), 1e-10, !1)) }, s.lambertw = function (r, t) { return new e(r).lambertw(t) }, o.tetrate = o.tetr = function (r, t) { void 0 === t && (t = e.ONE); var n, a = this.clone(); if (r = new e(r), (t = new e(t)).neq(e.ONE) && (r = r.add(t.slog(a))), e.debug >= e.NORMAL && console.log(a + "^^" + r), a.isNaN() || r.isNaN() || t.isNaN()) return e.NaN.clone(); if (r.isInfinite() && r.sign > 0) return a.gte(Math.exp(1 / Math.E)) ? e.POSITIVE_INFINITY.clone() : (n = a.ln().neg()).lambertw().div(n); if (r.lte(-2)) return e.NaN.clone(); if (a.eq(e.ZERO)) return r.eq(e.ZERO) ? e.NaN.clone() : r.mod(2).eq(e.ZERO) ? e.ZERO.clone() : e.ONE.clone(); if (a.eq(e.ONE)) return r.eq(e.ONE.neg()) ? e.NaN.clone() : e.ONE.clone(); if (r.eq(e.ONE.neg())) return e.ZERO.clone(); if (r.eq(e.ZERO)) return e.ONE.clone(); if (r.eq(e.ONE)) return a; if (r.eq(2)) return a.pow(a); if (a.eq(2)) { if (r.eq(3)) return new e(16); if (r.eq(4)) return new e(65536) } var i = a.max(r); if (i.gt("10^^^9007199254740991")) return i; if (i.gt(e.TETRATED_MAX_SAFE_INTEGER) || r.gt(e.MAX_SAFE_INTEGER)) { if (this.lt(Math.exp(1 / Math.E))) return (n = a.ln().neg()).lambertw().div(n); var o = a.slog(10).add(r); return o.operator(2, (o.operator(2) || 0) + 1), o.normalize(), o } for (var s = r.toNumber(), u = Math.floor(s), l = a.pow(s - u), f = e.NaN, h = 0, c = new e(e.E_MAX_SAFE_INTEGER); 0 !== u && l.lt(c) && h < 100; ++h)if (u > 0) { if (l = a.pow(l), f.eq(l)) { u = 0; break } f = l, --u } else { if (l = l.logBase(a), f.eq(l)) { u = 0; break } f = l, ++u } return (100 == h || this.lt(Math.exp(1 / Math.E))) && (u = 0), l.operator(1, l.operator(1) + u || u), l.normalize(), l }, s.tetrate = s.tetr = function (r, t, n) { return new e(r).tetr(t, n) }, o.iteratedexp = function (r, e) { return this.tetr(r, e) }, s.iteratedexp = function (r, t, n) { return new e(r).iteratedexp(t, n) }, o.iteratedlog = function (r, t) { void 0 === r && (r = 10), void 0 === t && (t = e.ONE.clone()); var n = this.clone(); return r = new e(r), (t = new e(t)).eq(e.ZERO) ? n : t.eq(e.ONE) ? n.logBase(r) : r.tetr(n.slog(r).sub(t)) }, s.iteratedlog = function (r, t, n) { return new e(r).iteratedlog(t, n) }, o.layeradd = function (r, t) { void 0 === t && (t = 10), void 0 === r && (r = e.ONE.clone()); var n = this.clone(); return t = new e(t), r = new e(r), t.tetr(n.slog(t).add(r)) }, s.layeradd = function (r, t, n) { return new e(r).layeradd(t, n) }, o.layeradd10 = function (r) { return this.layeradd(r) }, s.layeradd10 = function (r, t) { return new e(r).layeradd10(t) }, o.ssqrt = o.ssrt = function () { var r = this.clone(); if (r.lt(Math.exp(-1 / Math.E))) return e.NaN.clone(); if (!r.isFinite()) return r; if (r.gt(e.TETRATED_MAX_SAFE_INTEGER)) return r; if (r.gt(e.EE_MAX_SAFE_INTEGER)) return r.operator(1, r.operator(1) - 1), r; var t = r.ln(); return t.div(t.lambertw()) }, s.ssqrt = s.ssrt = function (r) { return new e(r).ssqrt() }, o.slog = function (r) { void 0 === r && (r = 10); var t = new e(this); if (r = new e(r), t.isNaN() || r.isNaN() || t.isInfinite() && r.isInfinite()) return e.NaN.clone(); if (t.isInfinite()) return t; if (r.isInfinite()) return e.ZERO.clone(); if (t.lt(e.ZERO)) return e.ONE.neg(); if (t.eq(e.ONE)) return e.ZERO.clone(); if (t.eq(r)) return e.ONE.clone(); if (r.lt(Math.exp(1 / Math.E))) { var n = e.tetr(r, 1 / 0); if (t.eq(n)) return e.POSITIVE_INFINITY.clone(); if (t.gt(n)) return e.NaN.clone() } if (t.max(r).gt("10^^^9007199254740991")) return t.gt(r) ? t : e.ZERO.clone(); if (t.max(r).gt(e.TETRATED_MAX_SAFE_INTEGER)) return t.gt(r) ? (t.operator(2, t.operator(2) - 1), t.normalize(), t.sub(t.operator(1))) : e.ZERO.clone(); var a = 0, i = (t.operator(1) || 0) - (r.operator(1) || 0); if (i > 3) { var o = i - 3; a += o, t.operator(1, t.operator(1) - o) } for (var s = 0; s < 100; ++s)if (t.lt(e.ZERO)) t = e.pow(r, t), --a; else { if (t.lte(1)) return new e(a + t.toNumber() - 1); ++a, t = e.logBase(t, r) } return t.gt(10) ? new e(a) : void 0 }, s.slog = function (r, t) { return new e(r).slog(t) }, o.pentate = o.pent = function (r) { return this.arrow(3)(r) }, s.pentate = s.pent = function (r, t) { return e.arrow(r, 3, t) }, o.arrow = function (r) { var t = this.clone(); return !(r = new e(r)).isint() || r.lt(e.ZERO) ? function (r) { return e.NaN.clone() } : r.eq(e.ZERO) ? function (r) { return t.mul(r) } : r.eq(e.ONE) ? function (r) { return t.pow(r) } : r.eq(2) ? function (r) { return t.tetr(r) } : function (n) { var a, i; if (a = 2 == arguments.length ? arguments[1] : 0, n = new e(n), e.debug >= e.NORMAL && console.log(t + "{" + r + "}" + n), t.isNaN() || n.isNaN()) return e.NaN.clone(); if (n.lt(e.ZERO)) return e.NaN.clone(); if (t.eq(e.ZERO)) return n.eq(e.ONE) ? e.ZERO.clone() : e.NaN.clone(); if (t.eq(e.ONE)) return e.ONE.clone(); if (n.eq(e.ZERO)) return e.ONE.clone(); if (n.eq(e.ONE)) return t.clone(); if (r.gt(e.MAX_SAFE_INTEGER)) return (i = r.clone()).layer++, i; var o = r.toNumber(); if (n.eq(2)) return t.arrow(o - 1)(t, a + 1); if (t.max(n).gt("10{" + (o + 1) + "}9007199254740991")) return t.max(n); if (t.gt("10{" + o + "}9007199254740991") || n.gt(e.MAX_SAFE_INTEGER)) { t.gt("10{" + o + "}9007199254740991") ? ((i = t.clone()).operator(o, i.operator(o) - 1), i.normalize()) : i = t.gt("10{" + (o - 1) + "}9007199254740991") ? new e(t.operator(o - 1)) : e.ZERO; var s = i.add(n); return s.operator(o, (s.operator(o) || 0) + 1), s.normalize(), s } if (a >= e.maxOps + 10) return new e([[0, 10], [o, 1]]); var u = n.toNumber(), l = Math.floor(u), f = r.sub(e.ONE); i = t.arrow(f)(u - l, a + 1); for (var h = 0, c = new e("10{" + (o - 1) + "}9007199254740991"); 0 !== l && i.lt(c) && h < 100; ++h)l > 0 && (i = t.arrow(f)(i, a + 1), --l); return 100 == h && (l = 0), i.operator(o - 1, i.operator(o - 1) + l || l), i.normalize(), i } }, o.chain = function (r, e) { return this.arrow(e)(r) }, s.arrow = function (r, t, n) { return new e(r).arrow(t)(n) }, s.chain = function (r, t, n) { return new e(r).arrow(n)(t) }, s.hyper = function (r) { return (r = new e(r)).eq(e.ZERO) ? function (r, t) { return new e(t).eq(e.ZERO) ? new e(r) : new e(r).add(e.ONE) } : r.eq(e.ONE) ? function (r, t) { return e.add(r, t) } : function (t, n) { return new e(t).arrow(r.sub(2))(n) } }, o.expansion = function (r) { var t, n = this.clone(); if (r = new e(r), e.debug >= e.NORMAL && console.log("{" + n + "," + r + ",1,2}"), r.lte(e.ZERO) || !r.isint()) return e.NaN.clone(); if (r.eq(e.ONE)) return n.clone(); if (!n.isint()) return e.NaN.clone(); if (n.eq(2)) return new e(4); if (r.gt(e.MAX_SAFE_INTEGER)) return e.POSITIVE_INFINITY.clone(); var a = r.toNumber() - 1; t = n; for (var i = 0; 0 !== a && t.lt(e.MAX_SAFE_INTEGER) && i < 100; ++i)a > 0 && (t = n.arrow(t)(n), --a); return 100 == i && (a = 0), t.layer += a, t.normalize(), t }, s.expansion = function (r, t) { return new e(r).expansion(t) }, s.affordGeometricSeries = function (r, t, n, a) { r = new e(r), t = new e(t), n = new e(n); var i = t.mul(n.pow(a)); return e.floor(r.div(i).mul(n.sub(e.ONE)).add(e.ONE).log10().div(n.log10())) }, s.affordArithmeticSeries = function (r, t, n, a) { r = new e(r), t = new e(t), n = new e(n), a = new e(a); var i = t.add(a.mul(n)).sub(n.div(2)), o = i.pow(2); return i.neg().add(o.add(n.mul(r).mul(2)).sqrt()).div(n).floor() }, s.sumGeometricSeries = function (r, t, n, a) { return t = new e(t), n = new e(n), t.mul(n.pow(a)).mul(e.sub(e.ONE, n.pow(r))).div(e.sub(e.ONE, n)) }, s.sumArithmeticSeries = function (r, t, n, a) { r = new e(r), t = new e(t), a = new e(a); var i = t.add(a.mul(n)); return r.div(2).mul(i.mul(2).plus(r.sub(e.ONE).mul(n))) }, s.choose = function (r, t) { return new e(r).factorial().div(new e(t).factorial().mul(new e(r).sub(new e(t)).factorial())) }, o.choose = function (r) { return e.choose(this, r) }, o.normalize = function () { var r, t = this; if (e.debug >= e.ALL && console.log(t.toString()), t.array && t.array.length || (t.array = [[0, 0]]), 1 != t.sign && -1 != t.sign && ("number" != typeof t.sign && (t.sign = Number(t.sign)), t.sign = t.sign < 0 ? -1 : 1), t.layer > 9007199254740991) return t.array = [[0, 1 / 0]], t.layer = 0, t; Number.isInteger(t.layer) && (t.layer = Math.floor(t.layer)); for (var n = 0; n < t.array.length; ++n) { var a = t.array[n]; if (null !== a[0] && void 0 !== a[0] || (a[0] = 0), 0 === a[0] || 0 !== a[1] && null !== a[1] && void 0 !== a[1]) { if (isNaN(a[0]) || isNaN(a[1])) return t.array = [[0, NaN]], t; if (!isFinite(a[0]) || !isFinite(a[1])) return t.array = [[0, 1 / 0]], t; Number.isInteger(a[0]) || (a[0] = Math.floor(a[0])), 0 === a[0] || Number.isInteger(a[1]) || (a[1] = Math.floor(a[1])) } else t.array.splice(n, 1), --n } do { for (e.debug >= e.ALL && console.log(t.toString()), r = !1, t.array.sort(function (r, e) { return r[0] > e[0] ? 1 : r[0] < e[0] ? -1 : 0 }), t.array.length > e.maxOps && t.array.splice(0, t.array.length - e.maxOps), t.array.length || (t.array = [[0, 0]]), t.array[t.array.length - 1][0] > 9007199254740991 ? (t.layer++, t.array = [[0, t.array[t.array.length - 1][0]]], r = !0) : t.layer && 1 == t.array.length && 0 === t.array[0][0] && (t.layer--, 0 === t.array[0][1] ? t.array = [[0, 10]] : t.array = [[0, 10], [Math.round(t.array[0][1]), 1]], r = !0), t.array.length < e.maxOps && 0 !== t.array[0][0] && t.array.unshift([0, 10]), n = 0; n < t.array.length - 1; ++n)t.array[n][0] == t.array[n + 1][0] && (t.array[n][1] += t.array[n + 1][1], t.array.splice(n + 1, 1), --n, r = !0); for (0 === t.array[0][0] && t.array[0][1] > 9007199254740991 && (t.array.length >= 2 && 1 == t.array[1][0] ? t.array[1][1]++ : t.array.splice(1, 0, [1, 1]), t.array[0][1] = Math.log10(t.array[0][1]), r = !0); t.array.length >= 2 && 0 === t.array[0][0] && t.array[0][1] < i && 1 == t.array[1][0] && t.array[1][1];)t.array[0][1] = Math.pow(10, t.array[0][1]), t.array[1][1] > 1 ? t.array[1][1]-- : t.array.splice(1, 1), r = !0; for (; t.array.length >= 2 && 0 === t.array[0][0] && 1 == t.array[0][1] && t.array[1][1];)t.array[1][1] > 1 ? t.array[1][1]-- : t.array.splice(1, 1), t.array[0][1] = 10; for (t.array.length >= 2 && 0 === t.array[0][0] && 1 != t.array[1][0] && (t.array[0][1] && t.array.splice(1, 0, [t.array[1][0] - 1, t.array[0][1]]), t.array[0][1] = 1, t.array[2][1] > 1 ? t.array[2][1]-- : t.array.splice(2, 1), r = !0), n = 1; n < t.array.length; ++n)t.array[n][1] > 9007199254740991 && (n != t.array.length - 1 && t.array[n + 1][0] == t.array[n][0] + 1 ? t.array[n + 1][1]++ : t.array.splice(n + 1, 0, [t.array[n][0] + 1, 1]), 0 === t.array[0][0] ? t.array[0][1] = t.array[n][1] + 1 : t.array.splice(0, 0, [0, t.array[n][1] + 1]), t.array.splice(1, n), r = !0) } while (r); return t.array.length || (t.array = [[0, 0]]), t }; var c = !1; o.standardize = function () { return c || (console.warn(t + "'standardize' method is being deprecated in favor of 'normalize' and will be removed in the future!"), c = !0), this.normalize() }, o.toNumber = function () { return -1 == this.sign ? -1 * this.abs() : this.array.length >= 2 && (this.array[1][0] >= 2 || this.array[1][1] >= 2 || 1 == this.array[1][1] && this.array[0][1] > Math.log10(Number.MAX_VALUE)) ? 1 / 0 : this.array.length >= 2 && 1 == this.array[1][1] ? Math.pow(10, this.array[0][1]) : this.array[0][1] }, o.toString = function () { if (-1 == this.sign) return "-" + this.abs(); if (isNaN(this.array[0][1])) return "NaN"; if (!isFinite(this.array[0][1])) return "Infinity"; var r = ""; if (this.layer ? this.layer < 3 ? r += "J".repeat(this.layer) : r += "J^" + this.layer + " " : r += "", this.array.length >= 3 || 2 == this.array.length && this.array[1][0] >= 2) for (var e = this.array.length - 1; e >= 2; --e) { var t = this.array[e], n = t[0] >= 5 ? "{" + t[0] + "}" : "^".repeat(t[0]); t[1] > 1 ? r += "(10" + n + ")^" + t[1] + " " : 1 == t[1] && (r += "10" + n) } var a = this.operator(0), i = this.operator(1); return r += i ? i < 3 ? "e".repeat(i - 1) + Math.pow(10, a - Math.floor(a)) + "e" + Math.floor(a) : i < 8 ? "e".repeat(i) + a : "(10^)^" + i + " " + a : String(a) }; var g = function (r, e) { var t = e + 1, n = Math.ceil(Math.log10(Math.abs(r))); n < 100 && (n = 0); var a = Math.round(r * Math.pow(10, t - n)) * Math.pow(10, n - t); return parseFloat(a.toFixed(Math.max(t - n, 0))) }; o.toStringWithDecimalPlaces = function (r, e) { if (-1 == this.sign) return "-" + this.abs(); if (isNaN(this.array[0][1])) return "NaN"; if (!isFinite(this.array[0][1])) return "Infinity"; var t = 0, n = "", a = Math.pow(10, r); if (this.layer ? this.layer < 3 ? n += "J".repeat(this.layer) : n += "J^" + this.layer + " " : n += "", this.array.length >= 3 || 2 == this.array.length && this.array[1][0] >= 2) for (var i = this.array.length - 1; !t && i >= 2; --i) { var o = this.array[i], s = o[0], u = o[1]; e && u >= a ? (++s, t = u, u = 1) : e && this.array[i - 1][0] == s - 1 && this.array[i - 1][1] >= a && (++u, t = this.array[i - 1][1]); var l = s >= 5 ? "{" + s + "}" : "^".repeat(s); u > 1 ? n += "(10" + l + ")^" + u + " " : 1 == u && (n += "10" + l) } var f = this.operator(0), h = this.operator(1); return f > a && (f = Math.log10(f), ++h), n += t ? g(t, r) : h ? h < 3 ? "e".repeat(h - 1) + g(Math.pow(10, f - Math.floor(f)), r) + "e" + g(Math.floor(f), r) : h < 8 ? "e".repeat(h) + g(f, r) : e ? "(10^)^" + g(h, r) + " " + g(f, r) : "(10^)^" + h + " " + g(f, r) : String(g(f, r)) }, o.toExponential = function (r, e) { return 1 == this.array.length ? (this.sign * this.array[0][1]).toExponential(r) : this.toStringWithDecimalPlaces(r, e) }, o.toFixed = function (r, e) { return 1 == this.array.length ? (this.sign * this.array[0][1]).toFixed(r) : this.toStringWithDecimalPlaces(r, e) }, o.toPrecision = function (r, e) { return 0 === this.array[0][1] ? (this.sign * this.array[0][1]).toFixed(r - 1, e) : 1 == this.array.length && this.array[0][1] < 1e-6 ? this.toExponential(r - 1, e) : 1 == this.array.length && r > Math.log10(this.array[0][1]) ? this.toFixed(r - Math.floor(Math.log10(this.array[0][1])) - 1, e) : this.toExponential(r - 1, e) }, o.valueOf = function () { return this.toString() }, o.toJSON = function () { if (e.serializeMode == e.JSON) { for (var r = [], t = 0; t < this.array.length; ++t)r.push([this.array[t][0], this.array[t][1]]); return { array: r, layer: this.layer, sign: this.sign } } if (e.serializeMode == e.STRING) return this.toString() }, o.toHyperE = function () { if (this.layer) throw Error(t + "Sorry, but this prototype doesn't support correct Hyper-E notation for numbers larger than 10{MSI}10"); if (-1 == this.sign) return "-" + this.abs().toHyperE(); if (isNaN(this.array[0][1])) return "NaN"; if (!isFinite(this.array[0][1])) return "Infinity"; if (this.lt(e.MAX_SAFE_INTEGER)) return String(this.array[0][1]); if (this.lt(e.E_MAX_SAFE_INTEGER)) return "E" + this.array[0][1]; for (var r = "E" + this.operator(0) + "#" + this.operator(1), n = 1, a = Math.ceil(this.getOperatorIndex(2)); a < this.array.length; ++a)n + 1 < this.array[a][0] && (r += "#1".repeat(this.array[a][0] - n - 1)), n = this.array[a][0], r += "#" + (this.array[a][1] + 1); return r = this.layer ? this.layer < 3 ? "J".repeat(this.layer) + r : "J^" + this.layer + " " + r : "" + r }, s.fromNumber = function (r) { if ("number" != typeof r) throw Error(n + "Expected Number"); var t = new e; return t.array[0][1] = Math.abs(r), t.sign = r < 0 ? -1 : 1, t.normalize(), t }; s.fromBigInt = function (r) { if ("bigint" != typeof r) throw Error(n + "Expected BigInt"); var t = new e, a = r < BigInt(0) ? -r : r; return t.sign = r < BigInt(0) ? -1 : 1, a <= 9007199254740991 ? t.array[0][1] = Number(a) : t.array = [[0, function (r) { for (var e = BigInt(64); r >= BigInt(1) << e;)e *= BigInt(2); for (var t = e / BigInt(2); t > BigInt(0);)r >= BigInt(1) << e ? e += t : e -= t, t /= BigInt(2); var n = e - BigInt(54), a = r >> n; return Math.log10(Number(a)) + Math.LOG10E / Math.LOG2E * Number(n) }(a)], [1, 1]], t.normalize(), t }; var y = function (r) { return Math.log10(Number(r.substring(0, 17))) + (r.length - 17) }; function E(r) { if (!r || "object" != typeof r) throw Error(t + "Object expected"); var e, a, i, o = ["maxOps", 1, Number.MAX_SAFE_INTEGER, "serializeMode", 0, 1, "debug", 0, 2]; for (e = 0; e < o.length; e += 3)if (void 0 !== (i = r[a = o[e]])) { if (!(Math.floor(i) === i && i >= o[e + 1] && i <= o[e + 2])) throw Error(n + a + ": " + i); this[a] = i } return this } s.fromString = function (r) { if ("string" != typeof r) throw Error(n + "Expected String"); var o = !1; if ("string" == typeof r && ("[" == r[0] || "{" == r[0])) try { JSON.parse(r) } finally { o = !0 } if (o) return e.fromJSON(r); var s = new e; if (s.array = [[0, 0]], !a.test(r)) return console.warn(t + "Malformed input: " + r), s.array = [[0, NaN]], s; var u = !1; if ("-" == r[0] || "+" == r[0]) { var l = r.search(/[^-\+]/); u = r.substring(0, l).match(/-/g).length % 2 == 1, r = r.substring(l) } if ("NaN" == r) s.array = [[0, NaN]]; else if ("Infinity" == r) s.array = [[0, 1 / 0]]; else { var f, h, c, g, E; for ("J" == r[0] && ("^" == r[1] ? (f = r.substring(2).search(/[^0-9]/) + 2, s.layer = Number(r.substring(2, f)), r = r.substring(f + 1)) : (f = r.search(/[^J]/), s.layer = f, r = r.substring(f))); r && /^\(?10[\^\{]/.test(r);) { var N; "(" == r[0] && (r = r.substring(1)), "^" == r[2] ? (N = f = r.substring(2).search(/[^\^]/), h = f + 2) : (f = r.indexOf("}"), N = Number(r.substring(3, f)), h = f + 1), ")" == (r = r.substring(h))[0] ? (f = r.indexOf(" "), c = Number(r.substring(2, f)), r = r.substring(f + 1)) : c = 1, 1 == N ? s.array.length >= 2 && 1 == s.array[1][0] ? s.array[1][1] += c : s.array.splice(1, 0, [1, c]) : 2 == N ? (f = s.array.length >= 2 && 1 == s.array[1][0] ? s.array[1][1] : 0, (h = s.array[0][1]) >= 1e10 && ++f, h >= 10 && ++f, s.array[0][1] = f, s.array.length >= 2 && 1 == s.array[1][0] && s.array.splice(1, 1), g = s.getOperatorIndex(2), Number.isInteger(g) ? s.array[g][1] += c : s.array.splice(Math.ceil(g), 0, [2, c])) : (f = s.operator(N - 1), (h = s.operator(N - 2)) >= 10 && ++f, g = s.getOperatorIndex(N), s.array.splice(1, Math.ceil(g) - 1), s.array[0][1] = f, Number.isInteger(g) ? s.array[1][1] += c : s.array.splice(1, 0, [N, c])) } for (f = r.split(/[Ee]/), h = [s.array[0][1], 0], c = 1, E = f.length - 1; E >= 0; --E) { h[0] < i && 0 === h[1] ? h[0] = Math.pow(10, c * h[0]) : -1 == c ? (0 === h[1] ? h[0] = Math.pow(10, c * h[0]) : 1 == h[1] && h[0] <= Math.log10(Number.MAX_VALUE) ? h[0] = Math.pow(10, c * Math.pow(10, h[0])) : h[0] = 0, h[1] = 0) : h[1]++; var p = f[E].indexOf("."), m = -1 == p ? f[E].length : p; 0 === h[1] ? m >= 17 ? (h[0] = Math.log10(h[0]) + y(f[E].substring(0, m)), h[1] = 1) : f[E] && (h[0] *= Number(f[E])) : (g = m >= 17 ? y(f[E].substring(0, m)) : f[E] ? Math.log10(Number(f[E])) : 0, 1 == h[1] ? h[0] += g : 2 == h[1] && h[0] < i + Math.log10(g) && (h[0] += Math.log10(1 + Math.pow(10, Math.log10(g) - h[0])))), h[0] < i && h[1] ? (h[0] = Math.pow(10, h[0]), h[1]--) : h[0] > 9007199254740991 && (h[0] = Math.log10(h[0]), h[1]++) } s.array[0][1] = h[0], h[1] && (s.array.length >= 2 && 1 == s.array[1][0] ? s.array[1][1] += h[1] : s.array.splice(1, 0, [1, h[1]])) } return u && (s.sign *= -1), s.normalize(), s }, s.fromArray = function (r, t, a) { var i, o; if (!(r instanceof Array) || void 0 !== t && "number" != typeof t || void 0 !== a && "number" != typeof a) if ("number" == typeof r && t instanceof Array && (void 0 === a || "number" == typeof a)) i = t, o = r, a || 0; else { if (!("number" == typeof r && "number" == typeof t && a instanceof Array)) throw Error(n + "Expected an Array [and 1 or 2 Number]"); i = a, o = r, t } else i = r, o = t, a || 0; var s, u = new e; if (i.length) if ("number" == typeof i[0]) for (u.array = [], s = 0; s < i.length; s++) { if ("number" != typeof i[s]) throw Error(n + "Expected Array of Number"); u.array.push([s, i[s]]) } else { if (!(i[0] instanceof Array)) throw Error(n + "Expected Array of Number or Array of pair of Number"); for (u.array = [], s = 0; s < i.length; s++) { if (!(i[s] instanceof Array) || "number" != typeof i[s][0] || "number" != typeof i[s][1]) throw Error(n + "Expected Array of pair of Number"); u.array.push([i[s][0], i[s][1]]) } } else u.array = [[0, 0]]; return u.sign = o ? Number(o) : 1, u.normalize(), u }, s.fromObject = function (r) { if ("object" != typeof r) throw Error(n + "Expected Object"); if (null === r) return e.ZERO.clone(); if (r instanceof Array) return e.fromArray(r); if (r instanceof e) return new e(r); if (!(r.array instanceof Array)) throw Error(n + "Expected that property 'array' exists"); if (void 0 !== r.sign && "number" != typeof r.sign) throw Error(n + "Expected that property 'sign' is Number"); if (void 0 !== r.layer && "number" != typeof r.layer) throw Error(n + "Expected that property 'layer' is Number"); return e.fromArray(r.array, r.sign, r.layer) }, s.fromJSON = function (r) { if ("object" == typeof r) return e.fromObject(t); if ("string" != typeof r) throw Error(n + "Expected String"); var t, a; try { t = JSON.parse(r) } catch (r) { throw t = null, r } finally { a = e.fromObject(t) } return t = null, a }, s.fromHyperE = function (r) { if ("string" != typeof r) throw Error(n + "Expected String"); var a = new e; if (a.array = [[0, 0]], !/^[-\+]*(0|[1-9]\d*(\.\d*)?|Infinity|NaN|E[1-9]\d*(\.\d*)?(#[1-9]\d*)*)$/.test(r)) return console.warn(t + "Malformed input: " + r), a.array = [[0, NaN]], a; var i = !1; if ("-" == r[0] || "+" == r[0]) { var o = r.search(/[^-\+]/); i = r.substring(0, o).match(/-/g).length % 2 == 0, r = r.substring(o) } if ("NaN" == r) a.array = [[0, NaN]]; else if ("Infinity" == r) a.array = [[0, 1 / 0]]; else if ("E" != r[0]) a.array[0][1] = Number(r); else if (-1 == r.indexOf("#")) a.array[0][1] = Number(r.substring(1)), a.array[1] = [1, 1]; else for (var s = r.substring(1).split("#"), u = 0; u < s.length; ++u) { var l = Number(s[u]); u >= 2 && --l, a.array[u] = [u, l] } return i && (a.sign *= -1), a.normalize(), a }, o.getOperatorIndex = function (r) { if ("number" != typeof r && (r = Number(r)), !isFinite(r)) throw Error(n + "Index out of range."); var e = this.array, t = 0, a = e.length - 1; if (e[a][0] < r) return a + .5; if (e[t][0] > r) return -.5; for (; t != a;) { if (e[t][0] == r) return t; if (e[a][0] == r) return a; var i = Math.floor((t + a) / 2); if (t == i || e[i][0] == r) { t = i; break } e[i][0] < r && (t = i), e[i][0] > r && (a = i) } return e[t][0] == r ? t : t + .5 }, o.getOperator = function (r) { if ("number" != typeof r && (r = Number(r)), !isFinite(r)) throw Error(n + "Index out of range."); var e = this.getOperatorIndex(r); return Number.isInteger(e) ? this.array[e][1] : 0 === r ? 10 : 0 }, o.setOperator = function (r, e) { if ("number" != typeof r && (r = Number(r)), !isFinite(r)) throw Error(n + "Index out of range."); var t = this.getOperatorIndex(r); Number.isInteger(t) ? this.array[t][1] = e : (t = Math.ceil(t), this.array.splice(t, 0, [r, e])), this.normalize() }, o.operator = function (r, e) { if (void 0 === e) return this.getOperator(r); this.setOperator(r, e) }, o.clone = function () { for (var r = new e, t = [], n = 0; n < this.array.length; ++n)t.push([this.array[n][0], this.array[n][1]]); return r.array = t, r.sign = this.sign, r.layer = this.layer, r }, (e = function (r) { for (var t in u) u.hasOwnProperty(t) && (Object.defineProperty ? Object.defineProperty(r, t, { configurable: !1, enumerable: !0, writable: !1, value: new e(u[t]) }) : r[t] = new e(u[t])); return r }(e = function r(e) { var t, n, a; function i(r, e) { var t = this; if (!(t instanceof i)) return new i(r, e); t.constructor = i; var n, a, o, s = null; if ("string" == typeof r && ("[" == r[0] || "{" == r[0])) try { s = JSON.parse(r) } catch (r) { } if ("number" != typeof r || e instanceof Array) if ("bigint" == typeof r) n = i.fromBigInt(r); else if (s) n = i.fromObject(s); else if ("string" == typeof r && "E" == r[0]) n = i.fromHyperE(r); else if ("string" == typeof r) n = i.fromString(r); else if (r instanceof Array || e instanceof Array) n = i.fromArray(r, e); else if (r instanceof i) { n = []; for (var u = 0; u < r.array.length; ++u)n.push([r.array[u][0], r.array[u][1]]); a = r.sign, o = r.layer } else "object" == typeof r ? n = i.fromObject(r) : (n = [[0, NaN]], a = 1, o = 0); else n = i.fromNumber(r); return void 0 === a ? (t.array = n.array, t.sign = n.sign, t.layer = n.layer) : (t.array = n, t.sign = a, t.layer = o), t } for (var u in i.prototype = o, i.JSON = 0, i.STRING = 1, i.NONE = 0, i.NORMAL = 1, i.ALL = 2, i.clone = r, i.config = i.set = E, s) s.hasOwnProperty(u) && (i[u] = s[u]); if (void 0 === e && (e = {}), e) for (a = ["maxOps", "serializeMode", "debug"], t = 0; t < a.length;)e.hasOwnProperty(n = a[t++]) || (e[n] = this[n]); return i.config(e), i }(e))).default = e.ExpantaNum = e, "function" == typeof define && define.amd ? define(function () { return e }) : "undefined" != typeof module && module.exports ? module.exports = e : (r || (r = "undefined" != typeof self && self && self.self == self ? self : Function("return this")()), r.ExpantaNum = e) }(this);
/*
MIT License
Copyright (c) 2021 Bo-gyu Jeong
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
// format-expantanum.js by cloudytheconqueror
// Code snippets from NumberFormating.js of ducdat0507's The Communitree,
// which is based on The Modding Tree by Acamaeda (and ported to OmegaNum by upvoid),
// in turn based on The Prestige Tree by Jacorb and Aarex
// Maximum number of times you can apply 1+log10(x) to number < 10 until the result is
// indistinguishable from 1. I calculated it myself and got 45, though I set it to 48 to be safe.
// Reducing this will speed up formatting, but may lead to inaccurate results.
var MAX_LOGP1_REPEATS = 48
// Base 5 logarithm of e, used to calculate log base 5, which is used in the definition of J.
var LOG5E = 0.6213349345596119 // 1 / Math.log(5)
var i = 0
function commaFormat(num, precision) {
if (num === null || num === undefined) return "???"
let zeroCheck = num.array ? num.array[0][1] : num
if (zeroCheck < 0.001) return (0).toFixed(precision)
let init = num.toString()
let portions = init.split(".")
portions[0] = portions[0].replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,")
return portions[0]
}
function regularFormat(num, precision) {
if (isNaN(num)) return "???"
let zeroCheck = num.array ? num.array[0][1] : num
if (zeroCheck < 0.001) return (0).toFixed(precision)
let fmt = num.toString()
let f = fmt.split(".")
if (precision == 0) return commaFormat(num.floor ? num.floor() : Math.floor(num))
else if (f.length == 1) return fmt + "." + "0".repeat(precision)
else if (f[1].length < precision) return fmt + "0".repeat(precision - f[1].length)
else return f[0] + "." + f[1].substring(0, precision)
}
// Basically does the opposite of what standardize in ExpantaNum does
// Set smallTop to true to force the top value in the result below 10
function polarize(array, smallTop = false) {
if (array.length == 0) array = [[0, 0]]
let bottom = array[0][0] == 0 ? array[0][1] : 10, top = 0, height = 0
if (!Number.isFinite(bottom)) { }
else if (array.length <= 1 && array[0][0] == 0) {
while (smallTop && bottom >= 10) {
bottom = Math.log10(bottom)
top++
height = 1
}
}
else {
let elem = array[0][0] == 0 ? 1 : 0
top = array[elem][1]
height = array[elem][0]
while (bottom >= 10 || elem < array.length || (smallTop && top >= 10)) {
if (bottom >= 10) { // Bottom mode: the bottom number "climbs" to the top
if (height == 1) {
// Apply one increment
bottom = Math.log10(bottom)
if (bottom >= 10) { // Apply increment again if necessary
bottom = Math.log10(bottom)
top++
}
}
else if (height < MAX_LOGP1_REPEATS) {
// Apply the first two increments (one or two logs on first, one log on second)
if (bottom >= 1e10) bottom = Math.log10(Math.log10(Math.log10(bottom))) + 2
else bottom = Math.log10(Math.log10(bottom)) + 1
// Apply the remaining increments
for (i = 2; i < height; i++) bottom = Math.log10(bottom) + 1
}
else bottom = 1 // The increment result is indistinguishable from 1
top++
}
else { // Top mode: height is increased by one, or until the next nonzero value
// Prevent running top mode more times than necessary
if (elem == array.length - 1 && array[elem][0] == height && !(smallTop && top >= 10)) break
bottom = Math.log10(bottom) + top
height++
if (elem < array.length && height > array[elem][0]) elem++
if (elem < array.length) {
if (height == array[elem][0]) top = array[elem][1] + 1
else if (bottom < 10) { // Apply top mode multiple times
let diff = array[elem][0] - height
if (diff < MAX_LOGP1_REPEATS) {
for (i = 0; i < diff; i++) bottom = Math.log10(bottom) + 1
}
else bottom = 1 // The increment result is indistinguishable from 1
height = array[elem][0]
top = array[elem][1] + 1
}
else top = 1
}
else top = 1
}
}
}
return { bottom: bottom, top: top, height: height }
}
// Search for the value at the requested height of an ExpantaNum array,
// and return the value if it exists; otherwise return a default value.
function arraySearch(array, height) {
for (i = 0; i < array.length; i++) {
if (array[i][0] == height) return array[i][1]
else if (array[i][0] > height) break
}
return height > 0 ? 0 : 10
}
// Search for the value at the requested height of an ExpantaNum array,
// and set it to zero if it exists.
function setToZero(array, height) {
for (i = 0; i < array.length; i++) {
if (array[i][0] == height) break
}
if (i < array.length) array[i][1] = 0
}
function formatExpanta(num, precision = 2, small = false) {
if (ExpantaNum.isNaN(num)) return "???"
let precision2 = Math.max(3, precision) // for e
let precision3 = Math.max(6, precision) // for F, G, H, J, and K
num = new ExpantaNum(num)
let array = num.array
if (num.abs().lt(1e-308)) return (0).toFixed(precision)
else if (num.sign < 0) return "-" + formatExpanta(num.neg(), precision)
else if (num.isInfinite()) return "Infinity"
else if (num.lt("1e50")) { return formatValue(num.toNumber(), precision) }
else if (num.lt("(10^)^5 7")) { // 1e50 ~ eeee1e7
let bottom = arraySearch(array, 0)
let rep = arraySearch(array, 1) - 1
if (bottom >= 1e50) {
bottom = Math.log10(bottom)
rep++
}
let m = Math.pow(10, bottom - Math.floor(bottom))
let e = Math.floor(bottom)
let p = bottom < 1000 ? precision2 : 0
return "e".repeat(rep) + regularFormat(m, p) + "e" + formatValue(e)
}
else if (num.lt("10^^10000000")) { // 1F5 ~ F10,000,000
let pol = polarize(array)
return regularFormat(pol.bottom, precision3) + "F" + commaFormat(pol.top)
}
else if (num.lt("10^^^5")) { // F10,000,000 ~ 1G5
let rep = arraySearch(array, 2)
if (rep >= 1) {
setToZero(array, 2)
return "F".repeat(rep) + formatExpanta(array, precision)
}
let n = arraySearch(array, 1) + 1
if (num.gte("10^^" + (n + 1))) n++
return "F" + formatExpanta(n, precision)
}
else if (num.lt("10^^^10000000")) { // 1G5 ~ G10,000,000
let pol = polarize(array)
return regularFormat(pol.bottom, precision3) + "G" + commaFormat(pol.top)
}
else if (num.lt("10^^^^5")) { // G10,000,000 ~ 1H5
let rep = arraySearch(array, 3)
if (rep >= 1) {
setToZero(array, 3)
return "G".repeat(rep) + formatExpanta(array, precision)
}
let n = arraySearch(array, 2) + 1
if (num.gte("10^^^" + (n + 1))) n++
return "G" + formatExpanta(n, precision)
}
else if (num.lt("10^^^^10000000")) { // 1H5 ~ H10,000,000
let pol = polarize(array)
return regularFormat(pol.bottom, precision3) + "H" + commaFormat(pol.top)
}
else if (num.lt("10^^^^^5")) { // H10,000,000 ~ 5J4
let rep = arraySearch(array, 4)
if (rep >= 1) {
setToZero(array, 4)
return "H".repeat(rep) + formatExpanta(array, precision)
}
let n = arraySearch(array, 3) + 1
if (num.gte("10^^^^" + (n + 1))) n++
return "H" + formatExpanta(n, precision)
}
else if (num.lt("J10000000")) { // 5J4 ~ J10,000,000
let pol = polarize(array, true)
return regularFormat(Math.log10(pol.bottom) + pol.top, precision3) + "J" + commaFormat(pol.height)
}
else if (num.lt("J^4 10")) { // J10,000,000 ~ 1K5
let rep = num.layer
if (rep >= 1) return "J".repeat(rep) + formatExpanta(array, precision)
let n = array[array.length - 1][0]
if (num.gte("J" + (n + 1))) n++
return "J" + formatExpanta(n, precision)
}
else if (num.lt("J^9999999 10")) { // 1K5 ~ K10,000,000
// https://googology.wikia.org/wiki/User_blog:PsiCubed2/Letter_Notation_Part_II
// PsiCubed2 defined Jx as Gx for x < 2, resulting in J1 = 10 rather than 10^10, to
// prevent issues when defining K and beyond. Therefore, there should be separate
// cases for when the "top value" is below 2, and above 2.
// ExpantaNum.js considers J1 to be equal to 1e10 rather than 10,
// hence num.lt("J^9999999 10") rather than num.lt("J^10000000 1").
let pol = polarize(array, true)
let layerLess = new ExpantaNum(array)
let layer = num.layer
let topJ
if (layerLess.lt("10^^10")) { // Below J2: use Jx = Gx
// layerLess is equal to (10^)^top bottom here, so calculate x in Gx directly.
topJ = 1 + Math.log10(Math.log10(pol.bottom) + pol.top)
layer++
}
else if (layerLess.lt("10{10}10")) { // J2 ~ J10
topJ = pol.height + Math.log((Math.log10(pol.bottom) + pol.top) / 2) * LOG5E
layer++
}
else { // J10 and above: an extra layer is added, thus becoming JJ1 and above, where Jx = Gx also holds
let nextToTopJ = pol.height + Math.log((Math.log10(pol.bottom) + pol.top) / 2) * LOG5E
let bottom = nextToTopJ >= 1e10 ? Math.log10(Math.log10(nextToTopJ)) : Math.log10(nextToTopJ)
let top = nextToTopJ >= 1e10 ? 2 : 1
topJ = 1 + Math.log10(Math.log10(bottom) + top)
layer += 2
}
return regularFormat(topJ, precision3) + "K" + commaFormat(layer)
}
// K10,000,000 and beyond
let n = num.layer + 1
if (num.gte("J^" + n + " 10")) n++
return "K" + formatExpanta(n, precision)
}
function formatWhole(num) {
return formatExpanta(num, 0)
}
function formatSmall(num, precision = 2) {
return formatExpanta(num, precision, true)
}
// Formats a value with certain constraints
function formatValue(number, additionalDigits) {
if (number instanceof Hyper) {
return number.format(additionalDigits)
}
var isBig = typeof number === "bigint" || typeof number === "string"
if (!isBig && typeof number !== "number") {
console.error("Cannot format a " + (typeof number) + " because it is not a string, number, BigInt, or HyperNumber.")
} else if (typeof number === "number" && number >= 1e21) {
number = BigInt(number)
}
var string = number.toString(), afterDots = ".", dotIndex = string.indexOf(".")
if (dotIndex !== -1) {
afterDots = string.slice(dotIndex)
string = string.slice(0, dotIndex)
if (dotIndex === 0) {
string = "0"
}
}
if (number < 1e7) {
string = string.replace(/\B(?=(.{3})+(?!.))/g, ",")
if (additionalDigits != null && additionalDigits != 0) {
additionalDigits = parseInt(additionalDigits)
if (!isFinite(additionalDigits) || additionalDigits > 1000000) {
throw RangeError("Precision " + additionalDigits + " is out of range.")
}
var diff = additionalDigits - afterDots.length + 1
string += (diff < 0 ? afterDots.slice(0, additionalDigits + 1) : (afterDots + "0".repeat(diff)))
}
return string
}
var length = string.length
var eIndex = string.indexOf("e")
if (eIndex !== -1) {
length = Number(string.slice(eIndex + 2))
string = string.slice(0, eIndex)
}
if (length > Math.min(abbreviationLimit, 303)) {
if (isBig) {
return string[0] + "." + string[1] + string[2] + string[3] + "e" + (length - 1)
}
return (string.charCodeAt(1) === 46 ? (string + "000").slice(0, 4) : (string + ".00")) + "e" + length
}
var mod3 = length % 3
var thousandPower = Math.floor((length - 1) / 3)
if (mod3 === 0) {
return string[0] + string[1] + string[2] + "." + string[3] + string[4] + shortSuffixes[thousandPower]
} else if (mod3 === 1) {
return string[0] + "." + string[1] + string[2] + string[3] + shortSuffixes[thousandPower]
} else if (mod3 === 2) {
return string[0] + string[1] + "." + string[2] + string[3] + string[4] + shortSuffixes[thousandPower]
}
}
// Custom-made hyper.js script made by Leo Zhang and released into the public domain.
// High speed and high precision
/** @type {string[]} An array with abbreviations for numbers up to a whole lot (will not work properly if suffixes are more than 2 letters) */
var shortSuffixes = ["", "K", "M", "B", "T", "q", "Q", "s", "S", "O", "N", "D", "Ud", "Dd", "Td", "qd", "Qd", "sd", "Sd", "Od", "Nd", "V", "Uv", "Dv", "Tv", "qv", "Qv", "sv", "Sv", "Ov", "Nv", "t", "Ut", "Dt", "Tt", "qt", "Qt", "st", "St", "Ot", "Nt", "qr", "Uq", "Dq", "Tq", "qq", "Qq", "sq", "Sq", "Oq", "Nq", "Qu", "UQ", "DQ", "TQ", "qQ", "QQ", "sQ", "SQ", "OQ", "NQ", "Sg", "Us", "Ds", "Ts", "qs", "Qs", "ss", "Ss", "Os", "Ns", "Sp", "US", "DS", "TS", "qS", "QS", "sS", "SS", "OS", "NS", "Og", "Uo", "Do", "To", "qo", "Qo", "so", "So", "Oo", "No", "Na", "Un", "Dn", "Tn", "qn", "Qn", "sn", "Sn", "On", "Nn", "C", "UC", "DC", "TC", "qC", "QC", "sC", "SC", "OC", "NC"]
/** @type {string[]} An array with LOWERCASE abbreviations for numbers up to a decillion (only works for one-letter lowercase suffixes) */
var shortSuffixesLower = ["", "k", "m", "b", "t", "", "", "", "", "o", "n", "d"]
/** @type {number} The minimum number of digits to stop using abbreviations for. Defaults to 50 but can be increased up to 303. */
var abbreviationLimit = 50
var HDIGITS = 50
var Hyper
(function () {
const tenPowers = [1n, 10n, 100n, 1000n, 10000n, 100000n, 1000000n, 10000000n, 100000000n, 1000000000n, 10000000000n, 100000000000n, 1000000000000n, 10000000000000n, 100000000000000n, 1000000000000000n, 10000000000000000n, 100000000000000000n, 1000000000000000000n, 10000000000000000000n, 100000000000000000000n, 1000000000000000000000n, 10000000000000000000000n, 100000000000000000000000n, 1000000000000000000000000n, 10000000000000000000000000n, 100000000000000000000000000n, 1000000000000000000000000000n, 10000000000000000000000000000n, 100000000000000000000000000000n, 1000000000000000000000000000000n, 10000000000000000000000000000000n, 100000000000000000000000000000000n, 1000000000000000000000000000000000n, 10000000000000000000000000000000000n, 100000000000000000000000000000000000n, 1000000000000000000000000000000000000n, 10000000000000000000000000000000000000n, 100000000000000000000000000000000000000n, 1000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000n, 100000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000000n, 100000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000000000n, 100000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000000000000n, 100000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000000000000000n, 100000000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000000000000000000n, 100000000000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000000000000000000000n, 100000000000000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000000000000000000000000n, 100000000000000000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000000000000000000000000000n, 100000000000000000000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000000000000000000000000000000n, 100000000000000000000000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000000000000000000000000000000000n, 100000000000000000000000000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000000000000000000000000000000000000n, 100000000000000000000000000000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000000000000000000000000000000000000000n, 100000000000000000000000000000000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000000000000000000000000000000000000000000n, 100000000000000000000000000000000000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 100000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n] // store a bunch of powers of ten
function powerOfTen(n) {
return n >= 200n ? 10n ** n : tenPowers[n]
}
function powerOfTenBig(n) {
return n >= 200 ? 10n ** BigInt(n) : tenPowers[n]
}
var BIGDIGITS = 50n, DIGITSMINUSONE = 49, BIGDIGITSMINUSONE = 49n, REPEATSTR = "0000000000000000000000000000000000000000000000000", BIGONE = 10000000000000000000000000000000000000000000000000n, BIGONETENTH = 1000000000000000000000000000000000000000000000000n, DIGITSOFDIGITS = 2, BIGLIMIT = 100000000000000000000000000000000000000000000000000n, FOURLIMIT = 400000000000000000000000000000000000000000000000000n, TWOBIG = 20000000000000000000000000000000000000000000000000n, LIMITMINUSONE = 99999999999999999999999999999999999999999999999999n, DOUBLELIMITDIVTEN = 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, DOUBLELIMIT = 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, DIGITSODD = false, RANDOMSIZE = 8, RANDOMMODULO = 0, RANDOMREPEAT = 1
/**
* Creates an Hyper (also called a "hyper-number") instance that represents a POSITIVE finite integer, which can handle high-quality values anywhere from above 10^(-9007199254740992) to 10^^(10^50) with default precision by using BigInt.
* @param {string | number | bigint | Hyper} value The value to set the number to. The inputs "pi" or "e" are also accepted, as well has Hypers.
* @yields {Hyper}
*/
Hyper = function (value, noWarnings) {
if (!(this instanceof Hyper)) {
return new Hyper(value)
} else if (value == null || value === false || value === 0) {
/** @type {[1 | -1, number | bigint, number | bigint, bigint]} A four-term array storing the information for the Hyper value. If the $[1] is 0, then the $[2] is a Number, and if $[1] is 1, then $[2] is a BigInt. If $[1] is either 0 or 1, then $[2] stores the number of digits as either BigInt or number, and $[3] stores the starting 50 (or a custom amount) digits of the number as a BigInt. Otherwise, $[1] stores the number of 10^ there is in the number. (So, if $[1] is 3, then $[2] represents the number of digits of digits of digits of the number.) Then, $[3] would represent the starting 50 (or a custom amount) digits of the number that is the number of times "of digits" the number has (minus one). (That means that if $[1] is 3, then $[3] is the first 50 (or a custom amount) digits of the number of digits of digits of the number.) This means that Hypers can store values up to about 10^^(1e^50) with default precision. */
this.$ = [1, 0, 0, 0n]
} else if (value === true || value === 1) {
this.$ = [1, 0, 0, BIGONE]
} else if (value instanceof Hyper) {
this.$ = value.$.slice(0)
} else if (typeof value === "bigint") {
var sign = 1
if (value < 0n) {
value = -value
sign = -1
}
var digits = value.toString().length - 1
this.$ = [sign, 0, digits, (digits > DIGITSMINUSONE ? value / powerOfTenBig(digits - DIGITSMINUSONE) : (value * powerOfTenBig(DIGITSMINUSONE - digits)))]
} else if (typeof value === "number" && !isFinite(value)) {
if (!noWarnings) {
console.error("Numbers must be finite.")
}
this.$ = [1, 0, 0, 0n]
return
} else {
var dollar = null;
(function (value) {
var string
if (typeof value === "string") {
string = value.trim()
if (string === "e") {
// Approximation
string = "2.718281828459045235360287471352662497757247093699959574966967627724076630353547594571382178525166427427466391932003059921817413596629043572900334295260595630738132328627943490763233829880753195251019011573834187930702154089149934884167509244761460668082264800168477411853742345442437107539077744992069551702761838606261331384583000752044933826560297606737113200709328709127443747047230696977209310141692836819025515108657463772111252389784425056953696770785449969967946864454905987931636889230098793127736178215424999229576351482208269895193668033182528869398496465105820939239829488793320362509443117301238197068416140397019837679320683282376464804295311802328782509819455815301756717361332069811250996181881593041690351598888519345807273866738589422879228499892086805825749279610484198444363463244968487560233624827041978623209002160990235304369941849146314093431738143640546253152096183690888707016768396424378140592714563549061303107208510383750510115747704171898610687396965521267154688957035035402123407849819334321068170121005627880235193033224745015853904730419957777093503660416997329725088687696640355570716226844716256079882651787134195124665201030592123667719432527867539855894489697096409754591856956380236370162112047742722836489613422516445078182442352948636372141740238893441247963574370263755294448337998016125492278509257782562092622648326277933386566481627725164019105900491644998289315056604725802778631864155195653244258698294695930801915298721172556347546396447910145904090586298496791287406870504895858671747985466775757320568128845920541334053922000113786300945560688166740016984205580403363795376452030402432256613527836951177883863874439662532249850654995886234281899707733276171783928034946501434558897071942586398772754710962953741521115136835062752602326484728703920764310059584116612054529703023647254929666938115137322753645098889031360205724817658511806303644281231496550704751025446501172721155519486685080036853228183152196003735625279449515828418829478761085263981395599006737648292244375287184624578036192981971399147564488262603903381441823262515097482798777996437308997038886778227138360577297882412561190717663946507063304527954661855096666185664709711344474016070462621568071748187784437143698821855967095910259686200235371858874856965220005031173439207321139080329363447972735595527734907178379342163701205005451326383544000186323991490705479778056697853358048966906295119432473099587655236812859041383241160722602998330535370876138939639177957454016137223618789365260538155841587186925538606164779834025435128439612946035291332594279490433729908573158029095863138268329147711639633709240031689458636060645845925126994655724839186564209752685082307544254599376917041977780085362730941710163434907696423722294352366125572508814779223151974778060569672538017180776360346245927877846585065605078084421152969752189087401966090665180351650179250461950136658543663271254963990854914420001457476081930221206602433009641270489439039717719518069908699860663658323227870937650226014929101151717763594460202324930028040186772391028809786660565118326004368850881715723866984224220102495055188169480322100251542649463981287367765892768816359831247788652014117411091360116499507662907794364600585194199856016264790761532103872755712699251827568798930276176114616254935649590379804583818232336861201624373656984670378585330527583333793990752166069238053369887956513728559388349989470741618155012539706464817194670834819721448889879067650379590366967249499254527903372963616265897603949857674139735944102374432970935547798262961459144293645142861715858733974679189757121195618738578364475844842355558105002561149239151889309946342841393608038309166281881150371528496705974162562823609216807515017772538740256425347087908913729172282861151591568372524163077225440633787593105982676094420326192428531701878177296023541306067213604600038966109364709514141718577701418060644363681546444005331608778314317444081194942297559931401188868331483280270655383300469329011574414756313999722170380461709289457909627166226074071874997535921275608441473782330327033016823719364800217328573493594756433412994302485023573221459784328264142168487872167336701061509424345698440187331281010794512722373788612605816566805371439612788873252737389039289050686532413806279602593038772769778379286840932536588073398845721874602100531148335132385004782716937621800490479559795929059165547050577751430817511269898518840871856402603530558373783242292418562564425502267215598027401261797192804713960068916382866527700975276706977703643926022437284184088325184877047263844037953016690546593746161932384036389313136432713768884102681121989127522305625675625470172508634976536728860596675274086862740791285657699631378975303466061666980421826772456053066077389962421834085988207186468262321508028828635974683965435885668550377313129658797581050121491620765676995065971534476347032085321560367482860837865680307306265763346977429563464371670939719306087696349532884683361303882943104080029687386911706666614680001512114344225602387447432525076938707777519329994213727721125884360871583483562696166198057252661220679754062106208064988291845439530152998209250300549825704339055357016865312052649561485724925738620691740369521353373253166634546658859728665945113644137033139367211856955395210845840724432383558606310680696492485123263269951460359603729725319836842336390463213671011619282171115028280160448805880238203198149309636959673583274202498824568494127386056649135252670604623445054922758115170931492187959271800194096886698683703730220047531433818109270803001720593553052070070607223399946399057131158709963577735902719628506114651483752620956534671329002599439766311454590268589897911583709341937044115512192011716488056694593813118384376562062784631049034629395002945834116482411496975832601180073169943739350696629571241027323913874175492307186245454322203955273529524024590380574450289224688628533654221381572213116328811205214648980518009202471939171055539011394331668151582884368760696110250517100739276238555338627255353883096067164466237092264680967125406186950214317621166814009759528149390722260111268115310838731761732323526360583817315103459573653822353499293582283685100781088463434998351840445170427018938199424341009057537625776757111809008816418331920196262341628816652137471732547772778348877436651882875215668571950637193656539038944936642176400312152787022236646363575550356557694888654950027085392361710550213114741374410613444554419210133617299628569489919336918472947858072915608851039678195942983318648075608367955149663644896559294818785178403877332624705194505041984774201418394773120281588684570729054405751060128525805659470304683634459265255213700806875200959345360731622611872817392807462309468536782310609792159936001994623799343421068781349734695924646975250624695861690917857397659519939299399556754271465491045686070209901260681870498417807917392407194599632306025470790177452751318680998228473086076653686685551646770291133682756310722334672611370549079536583453863719623585631261838715677411873852772292259474337378569553845624680101390572787101651296663676445187246565373040244368414081448873295784734849000301947788802046032466084287535184836495919508288832320652212810419044804724794929134228495197002260131043006241071797150279343326340799596053144605323048852897291765987601666781193793237245385720960758227717848336161358261289622611812945592746276713779448758675365754486140761193112595851265575973457301533364263076798544338576171533346232527057200530398828949903425956623297578248873502925916682589445689465599265845476269452878051650172067478541788798227680653665064191097343452887833862172615626958265447820567298775642632532159429441803994321700009054265076309558846589517170914760743713689331946909098190450129030709956622662030318264936573369841955577696378762491885286568660760056602560544571133728684020557441603083705231224258722343885412317948138855007568938112493538631863528708379984569261998179452336408742959118074745341955142035172618420084550917084568236820089773945584267921427347756087964427920270831215015640634134161716644806981548376449157390012121704154787259199894382536495051477137939914720521952907939613762110723849429061635760459623125350606853765142311534966568371511660422079639446662116325515772907097847315627827759878813649195125748332879377157145909106484164267830994972367442017586226940215940792448054125536043131799269673915754241929660731239376354213923061787675395871143610408940996608947141834069836299367536262154524729846421375289107988438130609555262272083751862983706678722443019579379378607210725427728907173285487437435578196651171661833088112912024520404868220007234403502544820283425418788465360259150644527165770004452109773558589762265548494162171498953238342160011406295071849042778925855274303522139683567901807640604213830730877446017084268827226117718084266433365178000217190344923426426629226145600433738386833555534345300426481847398921562708609565062934040526494324426144566592129122564889356965500915430642613425266847259491431423939884543248632746184284665598533231221046625989014171210344608427161661900125719587079321756969854401339762209674945418540711844643394699016269835160784892451405894094639526780735457970030705116368251948770118976400282764841416058720618418529718915401968825328930914966534575357142731848201638464483249903788606900807270932767312758196656394114896171683298045513972950668760474091542042842999354102582911350224169076943166857424252250902693903481485645130306992519959043638402842926741257342244776558417788617173726546208549829449894678735092958165263207225899236876845701782303809656788311228930580914057261086588484587310165815116753332767488701482916741970151255978257270740643180860142814902414678047232759768426963393577354293018673943971638861176420900406866339885684168100387238921448317607011668450388721236436704331409115573328018297798873659091665961240202177855885487617616198937079438005666336488436508914480557103976521469602766258359905198704230017946553679"
} else if (string.toLowerCase() === "pi") {
// Approximation
string = "3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131515574857242454150695950829533116861727855889075098381754637464939319255060400927701671139009848824012858361603563707660104710181942955596198946767837449448255379774726847104047534646208046684259069491293313677028989152104752162056966024058038150193511253382430035587640247496473263914199272604269922796782354781636009341721641219924586315030286182974555706749838505494588586926995690927210797509302955321165344987202755960236480665499119881834797753566369807426542527862551818417574672890977772793800081647060016145249192173217214772350141441973568548161361157352552133475741849468438523323907394143334547762416862518983569485562099219222184272550254256887671790494601653466804988627232791786085784383827967976681454100953883786360950680064225125205117392984896084128488626945604241965285022210661186306744278622039194945047123713786960956364371917287467764657573962413890865832645995813390478027590099465764078951269468398352595709825822620522489407726719478268482601476990902640136394437455305068203496252451749399651431429809190659250937221696461515709858387410597885959772975498930161753928468138268683868942774155991855925245953959431049972524680845987273644695848653836736222626099124608051243884390451244136549762780797715691435997700129616089441694868555848406353422072225828488648158456028506016842739452267467678895252138522549954666727823986456596116354886230577456498035593634568174324112515076069479451096596094025228879710893145669136867228748940560101503308617928680920874760917824938589009714909675985261365549781893129784821682998948722658804857564014270477555132379641451523746234364542858444795265867821051141354735739523113427166102135969536231442952484937187110145765403590279934403742007310578539062198387447808478489683321445713868751943506430218453191048481005370614680674919278191197939952061419663428754440643745123718192179998391015919561814675142691239748940907186494231961567945208095146550225231603881930142093762137855956638937787083039069792077346722182562599661501421503068038447734549202605414665925201497442850732518666002132434088190710486331734649651453905796268561005508106658796998163574736384052571459102897064140110971206280439039759515677157700420337869936007230558763176359421873125147120532928191826186125867321579198414848829164470609575270695722091756711672291098169091528017350671274858322287183520935396572512108357915136988209144421006751033467110314126711136990865851639831501970165151168517143765761835155650884909989859982387345528331635507647918535893226185489632132933089857064204675259070915481416549859461637180270981994309924488957571282890592323326097299712084433573265489382391193259746366730583604142813883032038249037589852437441702913276561809377344403070746921120191302033038019762110110044929321516084244485963766983895228684783123552658213144957685726243344189303968642624341077322697802807318915441101044682325271620105265227211166039666557309254711055785376346682065310989652691862056476931257058635662018558100729360659876486117910453348850346113657686753249441668039626579787718556084552965412665408530614344431858676975145661406800700237877659134401712749470420562230538994561314071127000407854733269939081454664645880797270826683063432858785698305235808933065757406795457163775254202114955761581400250126228594130216471550979259230990796547376125517656751357517829666454779174501129961489030463994713296210734043751895735961458901938971311179042978285647503203198691514028708085990480109412147221317947647772622414254854540332157185306142288137585043063321751829798662237172159160771669254748738986654949450114654062843366393790039769265672146385306736096571209180763832716641627488880078692560290228472104031721186082041900042296617119637792133757511495950156604963186294726547364252308177036751590673502350728354056704038674351362222477158915049530984448933309634087807693259939780541934144737744184263129860809988868741326047215695162396586457302163159819319516735381297416772947867242292465436680098067692823828068996400482435403701416314965897940924323789690706977942236250822168895738379862300159377647165122893578601588161755782973523344604281512627203734314653197777416031990665541876397929334419521541341899485444734567383162499341913181480927777103863877343177207545654532207770921201905166096280490926360197598828161332316663652861932668633606273567630354477628035045077723554710585954870279081435624014517180624643626794561275318134078330336254232783944975382437205835311477119926063813346776879695970309833913077109870408591337464144282277263465947047458784778720192771528073176790770715721344473060570073349243693113835049316312840425121925651798069411352801314701304781643788518529092854520116583934196562134914341595625865865570552690496520985803385072242648293972858478316305777756068887644624824685792603953527734803048029005876075825104747091643961362676044925627420420832085661190625454337213153595845068772460290161876679524061634252257719542916299193064553779914037340432875262888963995879475729174642635745525407909145135711136941091193932519107602082520261879853188770584297259167781314969900901921169717372784768472686084900337702424291651300500516832336435038951702989392233451722013812806965011784408745196012122859937162313017114448464090389064495444006198690754851602632750529834918740786680881833851022833450850486082503930213321971551843063545500766828294930413776552793975175461395398468339363830474611996653858153842056853386218672523340283087112328278921250771262946322956398989893582116745627010218356462201349671518819097303811980049734072396103685406643193950979019069963955245300545058068550195673022921913933918568034490398205955100226353536192041994745538593810234395544959778377902374216172711172364343543947822181852862408514006660443325888569867054315470696574745855033232334210730154594051655379068662733379958511562578432298827372319898757141595781119635833005940873068121602876496286744604774649159950549737425626901049037781986835938146574126804925648798556145372347867330390468838343634655379498641927056387293174872332083760112302991136793862708943879936201629515413371424892830722012690147546684765357616477379467520049075715552781965362132392640616013635815590742202020318727760527721900556148425551879253034351398442532234157623361064250639049750086562710953591946589751413103482276930624743536325691607815478181152843667957061108615331504452127473924544945423682886061340841486377670096120715124914043027253860764823634143346235189757664521641376796903149501910857598442391986291642193994907236234646844117394032659184044378051333894525742399508296591228508555821572503107125701266830240292952522011872676756220415420516184163484756516999811614101002996078386909291603028840026910414079288621507842451670908700069928212066041837180653556725253256753286129104248776182582976515795984703562226293486003415872298053498965022629174878820273420922224533985626476691490556284250391275771028402799806636582548892648802545661017296702664076559042909945681506526530537182941270336931378517860904070866711496558343434769338578171138645587367812301458768712660348913909562009939361031029161615288138437909904231747336394804575931493140529763475748119356709110137751721008031559024853090669203767192203322909433467685142214477379393751703443661991040337511173547191855046449026365512816228824462575916333039107225383742182140883508657391771509682887478265699599574490661758344137522397096834080053559849175417381883999446974867626551658276584835884531427756879002909517028352971634456212964043523117600665101241200659755851276178583829204197484423608007193045761893234922927965019875187212726750798125547095890455635792122103334669749923563025494780249011419521238281530911407907386025152274299581807247162591668545133312394804947079119153267343028244186041426363954800044800267049624820179289647669758318327131425170296923488962766844032326092752496035799646925650493681836090032380929345958897069536534940603402166544375589004563288225054525564056448246515187547119621844396582533754388569094113031509526179378002974120766514793942590298969594699556576121865619673378623625612521632086286922210327488921865436480229678070576561514463204692790682120738837781423356282360896320806822246801224826117718589638140918390367367222088832151375560037279839400415297002878307667094447456013455641725437090697939612257142989467154357846878861444581231459357198492252847160504922124247014121478057345510500801908699603302763478708108175450119307141223390866393833952942578690507643100638351983438934159613185434754649556978103829309716465143840700707360411237359984345225161050702705623526601276484830840761183013052793205427462865403603674532865105706587488225698157936789766974220575059683440869735020141020672358502007245225632651341055924019027421624843914035998953539459094407046912091409387001264560016237428802109276457931065792295524988727584610126483699989225695968815920560010165525637567"
}
} else {
string = value.toString().trim()
}
string = string.replace(/,/g, "")
var firstCode = string.charCodeAt(0), sign = 1
if (firstCode === 45) {
sign = -1
string = string.slice(1)
}
var len = string.length
if (len === 0) {
dollar = [sign, 0, 0, 0n]
return
}
var abbreviationTotal = getAbbreviation()
var eIndex = string.indexOf("e"), fIndex = string.indexOf("F")
if (fIndex === -1) {
fIndex = string.indexOf("f")
}
if (eIndex === -1 && fIndex === -1) {
var dot = string.indexOf(".")
if (dot !== -1) {
len = dot
string = string.slice(0, dot) + string.slice(dot + 1)
}
var match = string.match(/[^0]/)
if (match !== null) {
var firstNonZero = match.index
string = string.slice(firstNonZero)
len -= firstNonZero
} else {
dollar = [sign, 0, 0, 0n]
return
}
if (/[^0-9]/.test(string)) {
if (!noWarnings) {
console.error("The value given could not be converted to a Hyper.")
}
dollar = [sign, 0, 0, 0n]
return
}
dollar = [sign, 0, len + abbreviationTotal - 1, BigInt((string + REPEATSTR).slice(0, HDIGITS))]
return
}
var digits = 0, eTotal = 0n
if (fIndex !== -1) {
var eString = string.slice(fIndex + 1).replace(/,/g, "")
if (/[^0-9]/.test(eString)) {
if (!noWarnings) {
console.error("The value given could not be converted to a Hyper.")
}
dollar = [sign, 0, 0, 0n]
return
}
eTotal = BigInt(eString)
if (eTotal <= -1n) {
if (!noWarnings) {
console.error("You cannot have a negative amount of 'e' values.")
}
dollar = [sign, 0, 0, 0n]
return
} else {
string = fIndex === 0 ? "1" : string.slice(0, fIndex)
}
}
if (eIndex === 0) {
var match = string.match(/[^e/]/)
if (match === null) {
if (!noWarnings) {
console.error("The value given could not be converted to a Hyper.")
}
dollar = [sign, 0, 0, 0n]
return
}
eTotal += BigInt(match.index)
string = string.slice(Number(eTotal))
}
if (eTotal !== 0n && !string.includes("e")) {
string = "1e" + string
eTotal--
}
eIndex = string.indexOf("e")
if (eIndex === string.length - 1) {
if (!noWarnings) {
console.error("The value given could not be converted to a Hyper.")
}
dollar = [sign, 0, 0, 0n]
return
}
var beforeE = string.slice(0, eIndex)
string = string.slice(eIndex + 1)
var firstCode = string.charCodeAt(0)
if (firstCode === 43) {
string = string.slice(1)
}
var absString = string
if (firstCode === 45) {
absString = string.slice(1)
}
if (/[^0-9]/.test(absString)) {
if (!noWarnings) {
console.error("The value given could not be converted to a Hyper.")
}
dollar = [sign, 0, 0, 0n]
return
}
var match = absString.match(/[^0]/)
if (match !== null) {
absString = absString.slice(match.index + (firstCode === 45))
}
var dot = beforeE.indexOf("."), digits = 0
if (dot === -1) {
digits = beforeE.length - 1
} else {
beforeE = beforeE.slice(0, dot) + beforeE.slice(dot + 1)
digits = dot - 1
}
if (/[^0-9]/.test(beforeE)) {
if (!noWarnings) {
console.error("The value given could not be converted to a Hyper.")
}
dollar = [sign, 0, 0, 0n]
return
}
var bigPart = BigInt((beforeE + REPEATSTR).slice(0, HDIGITS))
var originalDigits = digits
digits += parseInt(string)
if (digits >= 9007199254740992) {
var digitEIndex = string.indexOf("e")
if (digitEIndex === -1) {
digits = BigInt(originalDigits) + BigInt(string)
} else {
var beforeValue = string.slice(0, digitEIndex)
var beforeDot = beforeValue.indexOf(".")
if (beforeDot !== -1) {
beforeValue = beforeValue.slice(0, beforeDot) + beforeValue.slice(beforeDot + 1)
}
if (/[^0-9]/.test(beforeValue)) {
if (!noWarnings) {
console.error("The value given could not be converted to a Hyper.")
}
dollar = [sign, 0, 0, 0n]
return
}
digits = BigInt(beforeValue)
}
if (digits >= BIGLIMIT) {
eTotal++
bigPart = BigInt(digits.toString().slice(0, HDIGITS))
digits = digits.toString().length - 1
if (eTotal === 1n) {
eTotal = 2n
}
}
} else if (eTotal !== 0n && digits < 0) {
if (!noWarnings) {
console.error("The value given could not be converted to a Hyper, as it contains negative numbers too far down.")
}
dollar = [sign, 0, 0, 0n]
return
} else if (eTotal !== 0n && digits < HDIGITS) {
if (digits === 0) {
if (!noWarnings) {
console.error("The value given contains an illogical zero.")
}
dollar = [sign, 0, 0, 0n]
return
} else if (digits === 1) {
if (eTotal === 1n) {
dollar = [sign, 0, Number(bigPart / BIGONETENTH), BIGONE]
} else {
var value = bigPart / BIGONETENTH
if (eTotal === 2n && value < 16n) {
dollar = [sign, 0, Math.pow(10, Number(value)), BIGONE]
} else if (value < BIGDIGITS) {
dollar = [sign, eTotal - 1n, powerOfTen(value), BIGONE]
} else {
dollar = [sign, eTotal, value, BIGONE]
}
}
} else if (digits < DIGITSOFDIGITS) {
var value = bigPart / powerOfTenBig(HDIGITS - digits - 1)
if (value < BIGDIGITS) {
dollar = [sign, eTotal - 1n, powerOfTen(value), BIGONE]
} else {
dollar = [sign, eTotal, value, BIGONE]
}
} else if (digits < 0) {
if (!noWarnings) {
console.error("The value given could not be converted to a Hyper, as it contains negative numbers too far down.")
}
dollar = [sign, 0, 0, 0n]
return
} else {
var digitValue = bigPart / powerOfTenBig(DIGITSMINUSONE - digits)
if (eTotal === 1n && digitValue < 9007199254740992) {
dollar = [sign, 0, Number(digitValue), BIGONE]
} else {
dollar = [sign, eTotal, digitValue, BIGONE]
}
}
return
} else if (eTotal !== 0n) {
eTotal++
}
if (bigPart < BIGONE) {
bigPart = bigPart * powerOfTenBig(50 - bigPart.toString().length)
}
if (digits <= -9007199254740992) {
dollar = [sign, 0, 0, 0n]
} else if (digits >= 9007199254740992) {
dollar = [sign, eTotal + 1n, digits, bigPart]
} else {
dollar = [sign, eTotal < 2n ? 0n : eTotal, eTotal < 2n ? Number(digits) : BigInt(digits), bigPart]
}
function getAbbreviation() {
var abbreviationIndex = -1
last = string[len - 2] + string[len - 1]
abbreviationIndex = shortSuffixes.indexOf(last)
if (abbreviationIndex === -1) {
var last = string[len - 1]
var abbreviationIndex = shortSuffixes.indexOf(last)
if (abbreviationIndex === -1) {
abbreviationIndex = shortSuffixesLower.indexOf(last.toLowerCase())
}
if (abbreviationIndex !== -1) {
string = string.slice(0, len -= 1)
}
} else {
string = string.slice(0, len -= 2)
}
if (abbreviationIndex !== -1) {
return abbreviationIndex * 3
}
return 0
}
})(value)
var category = dollar[1]
if (category < 9007199254740992n) {
dollar[1] = Number(category)
}
// Ignore the limit
// } else if (category >= BIGLIMIT) {
// if (!noWarnings) {
// console.error("The value you have inputted is too large!")
// }
// dollar = [dollar[0], 0, 0, 0n]
// }
this.$ = dollar
}
}
/**
* Sets the precision of ALL Hyper values. IMPORTANT: changing the number of digits will BREAK previous instances! If you need to change precision, store your Hyper values as strings and then convert them after setting the digit amount. It is advised to use this function BEFORE any Hyper instances are created.
* @param {string | number | bigint | Hyper} newDigits
*/
Hyper.setDigits = function (newDigits) {
var digits = parseInt(newDigits)
if (digits >= 10000000) {
throw RangeError("Maximum Hyper precision of 10000000 exceeded.")
} else if (!isFinite(digits) || digits < 16) {
throw RangeError("A Hyper value should have a precision between 16 and 10000000.")
}
HDIGITS = digits
DIGITSOFDIGITS = (digits - 1).toString().length
BIGDIGITS = BigInt(HDIGITS)
DIGITSMINUSONE = HDIGITS - 1
BIGDIGITSMINUSONE = BigInt(DIGITSMINUSONE)
REPEATSTR = "0".repeat(DIGITSMINUSONE)
BIGONE = powerOfTen(BIGDIGITSMINUSONE)
BIGONETENTH = BIGONE / 10n
BIGLIMIT = 10n * BIGONE
FOURLIMIT = BIGLIMIT << 2n
TWOBIG = BIGONE << 1n
LIMITMINUSONE = BIGLIMIT - 1n
DOUBLELIMITDIVTEN = BIGONE * BIGONE
DOUBLELIMIT = DOUBLELIMITDIVTEN * 10n
DIGITSODD = (HDIGITS & 1) === 1
RANDOMSIZE = Math.ceil(HDIGITS * 0.103810252966) + 2
RANDOMMODULO = BIGLIMIT * 10000000000n
RANDOMREPEAT = REPEATSTR + "000000000"
LOG10_2 = new Hyper("0.3010299956639811952137388947244930267681898814621085413104274611271081892744245094869272521181861720406844771914309953790947678811335235059996923337046955750645029642541934026618197343116029435011839028981785826171544395318619290463538846995202393108496124625404002633125946214788458473182826726839823261965427935076313175483509271389649469177857689180507900075995480878154597145850319648776261224922908291181909514989971716198604776765000678205179125573286286683420004029205098370845722248954942975621497072446597086136896092219094827612143914965282351678264923148040277462432441633115387382593038830393806332161302390518805821319156854616929053015051319269853784884187183200657535694683929717421320109058968908505856246409872183968766485398562351612773026389278782608498366810303084314155608139436176745488566634245381237339324224695943490602120445042968274606884785461156847684106437979500465969917745657540864018464079456529544341077408293999745400737217016801948890554856910694003754116899634157592972180644303810281520339238808563319868545398739354856065784289684898261394426084663278295260287662127623043419220262891211208361260055836862548999990927948784319747443388868629117713157413143222824169072995854725266157016837865324843772484501494231070981057547644239111166946914554653158213087545714859155264064669459397387274662626481556373135327269337959696802462363735803701702786527871382368266749519828884623367557462306447793364776980371470683133258881873131213864740296038784183570677840989672932230922836364090201677037161827336928454087218080144771762625506953476160886796962493766575320443448687953289293925355111468317252267269027574480678023768175534837405704382181223225333167896207975599032293059759674720866648423041739237925998625349797830939557939058531037975252143068778805590617344892191109026025826773307573559257888422877792921036753407863490855304794891954127419184995998472002896512482522900747644463235884208906503954959958558491035115048492721824049807454415599714989477887378682500728795922343009822942319249669491417573912540823496553976533413869724203094173675384196617867099578338970272787004639974872240934753017262827760378370041738228863589377924969862382325875180463298232538546590341884426607227746447936272479903769129333465546000093551695582424858532028918059736125384801823233442382103597678824131039216641326364909236929561097306295842230012701617892390833049660856580781673692318563832584839462208652330228807179187192362489333183015077311070745689121796914659367263135893208011259762354377304084068691237128559812760223428004379482876405125056913303826126403010530544273522458755389426282403514202977818574552152384456959363447034603700075088301735463847438537626403813454101438397158618878510933055522612438895685859314545981789398788095813097703294418454997539675584688521519928980078439477852749940693683296260337646969514281916547101134848280981159903891701632260198003335883343845347382837025678023183861865130506220796140649616517197441983362605251249435462333474207868218516919591009545367794107815920360973936616374249119974637581407388959127815667522795364331554404420540179775764574548045169358698557713498962599996338712463484916662006552612443129250273097705761564363331480979397586382101639153876281396221678652701621851872329327455199084359964370192229850163095316713600207495922820916926549406462015648516454839158198784522132330450566129638573974937494273361127741513842401000629562952191501261421723765087475239349268709954310991407339846379648623541205877052582157001940121088265053862420946239876135632219151395413745173865916851509644153119575878656498662100238893693108780943450508528466234382177343457889029398133355035174777008710821292356848678620539535720276545541790537872530502710701062170715088910526887959903910530278900868819684174003550490801852363346534150842598678778631295494252602029777067177633226348596208208829274740456372779701472755638788190784400976456870008457883700266813011923206196333878215846040733449263503651051191101403011098782737057847279051316748366723261946119583261254532331540082169467108602701774149967693998249375944746613415141940937550395825843753055648927667101895651619038987222872412515120827394231098838148110137700373589185088874278779534287441592376164595033359658544255003228496766069439226201365430030307203732941074253166516150071412099801810271374497152572160724936646388358103014272780662675943334687260374453743660278272231417303451308357309209362616142054838218146333065315091278414476738378702180988507713216007040367249564728981580033352751469842058022763578119395310334763014144567478637357245580977734937548656939871977977315313337061476862581811862090009206963058344298650460787460029116278906607159634540062737510043368937894881220447411369266695950881395070346377853955421429076370515177102397208455954664489465247862964017040292074927058690719427438246930579064937588750183750703884457234427176240789769116941152012358710805055511735985961521629659405149542528915695955364841351726871348743563342080085760395901723385754688206153274639939549351161075101927656721136437254856506254611463222256880615324720084145852382238890785837765248907173111341650512147876470730970489116197617093858302503305849581101121504565131969764125547918601293547835394401182547837133332286054405356855492490245434708371160091400645641010196802942338217903086164689994345045278524508239311392238465212326190551845924418111314893088540601032585980305127338200705109115230504792377109529732190028025764004059137691978116406217431868624988213475992415657066420261323827207806039547734050897256926007031993499918162369714033636981248973742426654473059686727414390407460882440515586486730005801544006569549555421152828347445060487069447997528971739451418994559379807029685774262364686454897336537102097165601784231357313276095051082662967197110061901064320744390505026043592293054669935647732588381521137672881333780786726554557248189040442459671076802369388082315183854624067985205745376589142625465227654361975144629639061857480794605151881398743854253797577849296638098437322140907600868110433667700123985774973736596986684753627281658550303493228285652349911568985711586625298830173991173920937722170195728579436856228842293201394341037379841733346331457863946409747754472604901415326285182529793843190669901489519994141910823172146228063020285235770595009501977708096548252259090282651194848329180456216167976476286963317658951051778600708783916750621003917822334120790264600470044560790747335459063921492148464330285608789907953708805384410435134164628331734222758835583946159746401439620194985713498176916447994412813714281838514940836026287639961491792281243553692926158515447292989625690979937987129791477286204650869315867131858223273603803065220822848670208661135811869325397336132723558201223604083655750643897432887078086202304074498123191215880788225098396438771638577609130336279917716092308269485124942676675293225060948275950086968570786289625540447452707208686059692942372255188177857897096662442157266624061773729257955065578366922863113845544906178978920438144601195916604884954245337527678342896940298870636226089146780573880960881792031540828198855104263279619097355794653747792205470907992601996860805304282430578160730410834257807986472050734636314753370085069784701525752495353598563515150534508360132197029765274031194933665113817758625126283880382777214951894264778499996342530578006397544192963951628524200665648334223091192066370482834680929211343309931722983951903416735686705390903196483763255429275526434059276929728444145130734555265694636952218842323746192550460492868136348107734182143263465340648467737488813236817830810401443086667510521833430362427533289516602998582429506252067680456341772170766205819082161533182188493474286482041621036191973059303060732362130619733656468282296971262673030597380322275439978659606829818683157530316256389688027106280605740239003777533012943030900486949898890263782827411092885938355840380657210797268092891482342348206375424836932019679456968995034002447211968939735481341972337416743519797688481730251024672408952076713655461777156971259334974941897210500373976906735095433988914179406933485967631377204143361108738778442893083037918944370764256354896550857194997985277986138916751877739597592511922913551844714098664171862993642682380656068480911002730321880266614164983171182198291547835336817726275109042460742971623031339464252696559819732974722411952564600019993386652881362728938113620708085246185483391797207145055451333879188823640356556702884340628360727853378460422648325596144952543340955600629219569171086367679128913179508000572805489701142230313708460561229225268299180888001864493384732200661465422936513632253681883072185350802292283956422672732632969985992422806087141830535612839701385677993947948782395557306472916288613132567250664393649137954804350646397527876242225200924596601427176755185451764640313396521110178838490860727956804548173615975448360263158958851520058153026421382702231772218746065152398962272405488498914706741979281683379602344554588917521988050022116838257296131254142080844454035371770460222300772676883856320840226827112216350126508968632984641568461067724738000015493914400293223683218661032048805528681950445757742942117162711526638975851557800104108993616275010761954038116040195556617834775451240079923140748788181851290477242791214248534020217957008646958225012894911716229506711514403190966389613237089835199978134946237607510467101167631775631808371419852453829834215138646145609651088687321504942963870061739697456380103034379719823731337665855197063131674917951963031373564619369164477834843557975058207889079621272231925012150712141547221307773913877305843294562364928283129073157238688181334367923065788092414166810854868709393249342946152465112661687406842415927581551259115524103935194940064451956953472268958143334475057512458559752957017123135046637285476946182638015941411242456024324975723831439850493041949994883421936737116638149496485708828791106546049927228684071450")
LOG10_E = new Hyper("0.4342944819032518276511289189166050822943970058036665661144537831658646492088707747292249493384317483187061067447663037336416792871589639065692210646628122658521270865686703295933708696588266883311636077384905142844348666768646586085135561482123487653435434357317253835622281395603048646652366095539377356176323431916710991411597894962993512457934926357655469077671082419150479910989674900103277537653570270087328550951731440674697951899513594088040423931518868108402544654089797029863286828762624144013457043546132920600712605104028367125954846287707861998992326748439902348171535934551079475492552482577820679220140931468164467381030560475635720408883383209488996522717494541331791417640247407505788767860971099257547730046048656049515610057985741340272675201439247917970859047931285212493341197329877226463885350226083881626316463883553685501768460295286399391633510647555704050513182342988874882120643595023818902643317711537382203362634416478397146001858396093006317333986134035135741787144971453076492968331392399810608505734816169809280016199523523117237676561989228127013815804248715978344927215947562057179993483814031940166771520104787197582531617951490375597514246570736646439756863149325162498727994852637448791165959219701720662704559284657036462635675733575739369673994570909602526350957193468839951236811356428010958778313759442713049980643798750414472095974872674060160650105375287000491167867133309154761441005054775930890767885596533432190763128353570304854020979941614010807910607498871752495841461303867532086001324486392545573072842386175970677989354844570318359336523016027971626535726514428519866063768635338181954876389161343652374759465663921380736144503683797876824369028804493640496751871720614130731804417180216440993200651069696951247072666224570004229341407923361685302418860272411867806272570337552562870767696632173672454758133339263840130320038598899947332285703494195837691472090608812447825078736711573033931565625157907093245370450744326623349807143038059581776957944070042202545430531910888982754062263600601879152267477788232096025228766762416332296812464502577295040226623627536311798532153780883272326920785980990757434437367248710355853306546581653535157943990070326436222520010336980419843015524524173190520247212241110927324425302930200871037337504867498689117225672067268275246578790446735268575794059983346595878592624978725380185506389602375304294539963737367434680767515249986297676732404903363175488195323680087668648666069282082342536311304939972702858872849086258458687045569244548538607202497396631126372122497538854967981580284810494724140453341192674240839673061167234256843129624666246259542760677182858963306586513950932049023032806357536242804315480658368852257832901530787483141985929074121415344772165398214847619288406571345438798607895199435011532826457742311266817183284968697890904324421005272233475053141625981646457044538901148313760708445483457955728303866473638468537587172210685993933008378534367552699899185150879055911525282664002892347937881121407895555195374408772295866252736746195639280603742726018616689670312012663117696913355706331630849577406356406229544498141403602074278756296665237541703118888983326952979459481210760848339634648644578297380492018939593886450713530024251256429146752636965688118790367526300650703432024423641454042942756681159988708670742574270248887466031356154482731009059311783482476274672791911930315614087348515809602788857832461865544654766307340625511354958708319564665767428807303231693426738727205599774366566529764447395141032833942918472472974321114019358087391109026762802963420497065078011899433838008080132868909397172465029499287660721651780984955411231009057182178892113097407890171554042645169832090273444520463039848823570143978006332330954882686175070447049618001348968372301641740437719913516171210181685548502811752314858971337587901923152484509079359066533916615589936769871036713763268689563891273495175161631796453225380319832428353970970623980284544713857277032427692338387873041312636525221126106093060752992030645096844169711465638074719985864264878644555193681313493997768075370028036024119728783045170876588640557274222898045184194495971154337684449500375878822631988769253208536691125509225218187312393277190049382097378497872783140532034411259469402102495126766408527000824078549191015654613505763051777155024580852073990996723946987968358210406781250157789270921046764448617822017096378924405984125146522842779108272140383674135124864245915091815340922639427082875668985698356822677628524958196454993061713856777006002238553957911602032480336612702055015863475646838924124592112055929324405726099371912880655651226464328758822074225247037795086602908776833119806840511399446881155342324981337347844120983456946922255832231935667026543657151456765841719852590093095753594653700397628552739046785908520751976630545537855996781584342820849035683293975038081324535967378709052619102863080979412995879726862061437759787027312460562248130999359000460491855815371755229660375838102214077454998581218937727750474740350081611351495555827274287815042722142159066568275563951252881072633687915551290579461533213661234613307913094497411606460476944972407308576179088626086990053572344073772243952195706907051471543030649919167646660810350301543918340266544820511283258938482965646574152877108216191815070945416918816648708173817283866184696427804338592874848836712713885948748864256059629364373661193990338149294178869165655374371442251631510166956971318821537197078712762884509197718168539981181059708755940544576804025044314332832831430871398001355984742003322031419736452286069042183496762953590253271894720408894319132940392623473338953132838790937271913997336484386213799985197853073623484964873618297478967112046001599027695576711653642561655403661720533824847627504146190883933360535112877665847840440539788207369894895192544143121649275598929857083871039693921736581776140467076979427096257367400115859131308388639108136090627487138248529212821388899542557705951136325163564238761792535832656673730284632572389062056245816270065726554205787201071090666206626412259785715726497258159394455170268034822889883355664394579731947330905133757533689694106552046919252622325971173955311030220143860013645909941894196550186707428069984819039517227296901396250522075278390149933850689043374851246590647239774928651529080900687768030075825808765463251365676764590035302266538226679332805986027416329691045896153216890334699278232922747692522724510531881188608149686661029586079983109571243311111136703558201442758677463267533379937282469741978656733889064212498629490651699806547109556383558645617376326352513467259156605637097570330430298309670510512932537022018937130362557170359270033203147096402393470466689273772068014572464007330886920833703527978171189284453904626682244618397973373927027547650393721303159537669610228026513108652561635267752392911156397269253200337327732651480762984196386990970037051231347676932558410764809565649691065994722563246444084139740887376362675998643358444409236407158968222922526883441351369846055953461472384203055619836604223325716542986733025072958040186749048134902616520869194942729372751478165759530003443737123738900711731696993174599500402765634745460852127935825138545288998964508152139014305709442198082222844750917655276585717383896188471891549154053075648170135810037345783987887106249203482444397797936823325957257539309416996616849544758942503514661498620386592655018048209921956623977940042612721633582165927285990414441689159125763750229499700475524521989227077375120515537886094209260377139410252378259199158851020982674486846935899156506301972465035918027218245522165063116635129584338154700194607813844361250394917322858544724881840914997412163974731143921948600233007299580549336293464543014481168617266973167365854178899663320878828996479915877440457514561635149137156365957808691837337305824634957868107967986869563983316428498499175438366670681950735900835555555098227258961111546747741673538483065436241120467433046364471190556457877274105222914928684872810621244972985691677798922697171237639561695711608771927043334781072020711310447332649984861886158785264456570763285437524238870028067765616856749437532740825414174523267969279665154935964576290561576290960910728892464994113126120683944015232333047320687296219334246831871033829061240602259873026296842899755603033060752804209240054061380796216145758088991883549479017815949053547662454174014091942815432692050761033498837068226015630824198163368941632839760353569420646191716402983862818993745607891920188139606938952856793000598026030484044348356626852225309624071442293251144977907695417093225046459679855937346760896200494075170639354378182978391633925350516415780554964318568236067139673830262920040074126859416917979854683274547215108335594419627982851841683015169780258476487252959663442173867827889982482402937970248944079314028347338610449247024985367163423758006786205884292414701030885176343394370559656368945302825955691519349270321340530591363088504126752179950925104939236441706864304067072262989050227651250328838389992886189896376699606425296084198174234614547060650019208088789571272965005387424959797174771976999752036165714401605581106675964026387196448990028958176179465026995283418314314409825114671990010709602520578518622579825956071617261293752097207209840604760531345560736369209294087359279685939198716872787778415596266773814234555011232965753278885250126309373532351682844683066802303911555187649455564413477352576255661761777185809894708122694186881687278459151058474743799837778392070518396052180919532236209918934013062799345578286845781720141179903393928233249001393543656693822876577905721174281877774455620009671770127034567543582705147686388376600560313349373869893679217924572684392354493529556138514726316963937677107924534846123803983444588563473236994103402283586214821365369634570047687539488822909173980177272887823849541200982148428346057148240302171650827798215085153754117950457804854754744047625297552891737646787318730598852")
LOG2_E = new Hyper("1.442695040888963407359924681001892137426645954152985934135449406931109219181185079885526622893506344496997518309652544255593101687168359642720662158223479336274537369884718493630701387663532015533894318916664837643128615424047478422289497904795091530351338588054968865893096996368036110511075630844145427215828344941891933908577715790044171280246848341374522695182369011239094034459968539906113421722886278029158010630061976762445652605995073753240625655815475938178305239725510724813077156267545807578171330193573006168761937372982675897415623817983567103443489750680705518088486561386832917732182934913968431059345402202518636934526269215095597191002219679224321433424494179071455118499385921221675365311300774632767206461233741108211913794433398480579310912877609670200375758998158851806126788099760956252507841024847056900768768058461327865474782027808659462060910749015324819969730579015272324787298740981254100033448687573822364716494544753706716759589942809981826783490131666633534803678986944688709116660497353729258607212948697354540708098306748938341237186314008359796188659758687452533054689212976641570420621259246313692421680590877408335813928666541584971162587069556578588747699631296952500459372627389026805669355128729433837219131116650881001587862655915637954055905677822368140030968843934808622848184791345633141193023840264097274843644962195449224465222047176358607479658556660534098286098574027883743312688563354434306978701896435826139118100252599020766184432984883184723915912701390457047735764831010211928297085328960931680353919649869573264393791490308485470616433789856348238900004564261855622496930913960312520223767376074153862116245551165086436799129389371225572752855358505388627546928167550407303918984389641052039899021078907741074670715487187445927826480325745329406836552544103465737320315138225129361437624142202250714370369730734609414850108603189323604113311115744937702491468814553609722861672425272088889061517451052531559178316247029430178095934252371975125612329569505926858901075573121447832714438655839592620356007499708416567681679268721978983048302281782977385152293797381195278398266923467818982723138352442777865647623134859901194028780732484171511058619349202546881837818357300094700147502951964817837874039354216278848238941974695520862627419471357392597226651239427201166462692938707284017956993398889202501277913459329094676020415764879790841607401359157889710773691716288172692755182517960232474350173532606863738793763572044458313264353526509290061748888247033974920459020557724020364994277699238470527177685203357040125910731736639056137520453197778773562797180625921321743667984249874334562328228971247257945609197595215055835184523639531383497657376260166981167685146145560638695562162638896323160272971094995069592801744350030798593924157506631512149867563008065061831442109254227561277967430907171276820183902280303065724252294800267075913436729080697447776799229453917140856561043148672020633912643384787632773495535569020831968308365499869958364273149079814521788625848451395766110403819805021113756743817251718600268591287264377763324903973629633852363464853453173840906426836835666231946259994976397115999688210521685143972181120803362753277710877521564849574103985301296247671763047156585964792880879376248342674441071955700343262768181898741616005094467642901010913425981148736992960783462718542553484930121975860318747318569641255962953587995973858821355995384741785595981341760463985344429527033939820883662829291277838449027147019204901714694893112878963897715820590960528434031909256530215925857297505043491577322606715497095678034285598632902698595824599737299885187245489060653642712769554424721395918154405783521212079344368736372307557412386882432395351227013135052951958925168506223995164165891161002348879844727588061347294723811662775944506845234655263101639919321591490974443553161510684551135594749268898334199868857619261206200495959968577400380717469779805821160858713482698211319347075218435146643676328882719788207491857524007463133613285208658460532800487276271988748891302822234197593587597783697265158305612590107412055513873940096016813578790460169363246244467916277783004751204980430843808569553029021487803694938895789041272366368026285809501704874354895866296987008976209460295150926137105309813290776148689376421966654993625965623229718824113727696646704325736357204652741177314198331457888659890655949766869704197192356889298314166102424954291946877919673677950286430889703840011530039504977994113946378154915758332141372041068468273696110075177409798023457893597423923239873789931409372560626371895703204682804512269710999646359650982544315626805399457654635377350716792966846077290818082063322372776485953402216717703340844802853282869962068687866770774780082319984096426103644324118454154682262556301480302287900607015032479749873420588418765811078215518457144116434314990721845674816876484118864353183148693300269331688794801531470706533048809398937091231071592804965615791371810742359864832552926714722986823236038508718790966213441959168085857211807466843551926174751216420597334672381207348666193018576985226203407378322193979110448554855334565861047585545898083272921193853940713705239320144100776831675939252095236161990092905384657812901942954915927490013751940721271200844385267251991915182485793862611290315950805581384188669488472219248779130968844580351540558028521536764834090393513915472712910558686616046528813067149937135238145863304596076015553095725946464084968707013471797962321551562376629332053354045966071993185203056991942058926197337937239593445870326137408081030909131482005814145165538402382905194011658567693615642858548230404063193606656656116157041680085788729079404035638362497343672663400266622866993615148162108442800206128631875616087373808962460962441857701934475568497490419695999606881024667508353542964768739398691505651152277350557748872769191066674454691506689297860579198757576365340890095977074669826361708569604579691269317820241427863723139349337077545365218406316112972755184362597583181937736950764560412014964861870826205850726023349587487877159959193502826006378754243698520598954935107617473928936248131748704789894947844772132859813244566108082319565635784522103909612491589480801485392449514617243630554573491439584889630827339274760318328679614778753981962774755499915551674221201466200667553605530324209781789132403006360528742053603376587459946086738978061675037254765286692073397017945222674446295438711345758690198058218480571098887538007738175702089700387304644392853921227236170057622304532929114054218680069017676954679219997920115796178352122363938635725773526964725808103597246238667399145193515162411874667251919121308943729141978770297650936851679990586205799250497461037726324475175368318181630267942711260661621125846331981128748235689256527234708205083667534708698696473462578021475829786205328965817783797798791330198968298702675954013232726913142168320972015406210239253608538956071643276376535711566216917409458882840754017599453120162965311976045667727447670293220742785003885071829844985469848464779667085848777437467811418880488200267147343946587286390653935019929129761272894881486324572314777030948020287997566233156865398737135713487218552335937575844812700645591195400104337458003249810016546387570883238756833280796369048160830266305716653624702758936118176229119686042227922993882075484128833176583861776355029379733324816953188224576615747818274751183238863074375402019475496153867094622681716291356086998478265066737468395742413663895247576612736941080707106731972704751770413829580477334275249335055539708587382141737036625620420177433856493215833473535316346754359986982293497962509032625409733217793062878961256381054907705572381729374049783818340150389956316107477280689191786075831786147267570641949849193197732322189827597798376047472551163230073908775937812110757342337257175849405393004189955546401740133605383588694223806513203073972690061702057233574052597252596625372612969127437885267338937523249881574465755337870124716674716761647150994006988209140281583160584661530310832397977083897360221104034696363660096476801706701329205088700146508133569351221053716468286227833592950326082160774544573333543924437848020196944517131457405609336104941533761219292015503145743656505307114112777019140856267778752842848211545388890591745132302363877555514034672289214441828788490045344634666655944416560131535416851305266660205845598700686344261628411500323218154116187699628741647565568609228973457778986498869038483604326232893156085209471706475066338779105054996755307051892305917933499740659811320364627235862969539243304983079273988768411579869145152816781478696202299878925070473606664683648086923201545194237769108327209008174133147115106427275433446293059928549960275842173622985654077513478882444463588614391673798017794066719685152428934653828141438546793410893664253087016661097935528929986463788883440802898890320794175748412840618674734041573194015613863815780446214741765700321925301855406316036210810190711535343488711703133248846100356421892468260929499617769027343336935867537780173126696247788684853073049749705050090155672410389532580357619804249782598141609167390336368020124206274482224958868890324671279432435681468924612191230529690331804984438669741446787300866043055984546146463552353226575533967697801221258223408568355425312344027313754886029289015816075061298986921758028201151217177984322702563003126726540410726499397286217268042657384012110304910915083753027220814284776341445611116020982464327192431612929747912323448441418177389130078228246471513942869842137594908459408976152246974197902736074811295174498206778910198486085078265530175639894797660373976189663356655395496429004464488257395713268127085127431341030943181255138645714864352673509022772610411320801384222434201880410442231485396034787064433515321211300101779554863753207019449215074144903040384537523742261623044083807053939300384229165026442783563078264202157486276623366317114394870684482098204550399584201628596939712381527239829")
HALF = new Hyper("0.5")
TWO = new Hyper("2")
TEN = new Hyper("10")
}
function HyperAddBase(start, num) {
var aData = start.$[3]
var bData = num.$[3]
if (start.$[3] === 0n) {
return num
} else if (num.$[3] === 0n) {
return new Hyper(start)
}
var c1 = start.$[1]
var c2 = num.$[1]
if (c1 >= 2 || c2 >= 2) {
// This optimization (where the code simply finds the higher value) may in theory result in inaccurate numbers for the edge values between categories 1 and 2 that result in slight precision errors, but that is not considered here.
if (c1 === c2) {
if (start.$[2] === num.$[2]) {
return start.$[3] > num.$[3] ? new Hyper(start) : num
} else {
return start.$[2] > num.$[2] ? new Hyper(start) : num
}
} else {
return c1 > c2 ? new Hyper(start) : num
}
} else if (c1 === 0 && c2 === 0) {
var d1 = start.$[2]
var d2 = num.$[2]
var max = d1 > d2 ? d1 : d2
var sum
if (d1 === d2) {
sum = start.$[3] + bData
} else if (d1 > d2) {
if (d1 - d2 > DIGITSMINUSONE) {
return new Hyper(start)
}
sum = start.$[3] + bData / powerOfTenBig(d1 - d2)
} else {
if (d2 - d1 > DIGITSMINUSONE) {
return num
}
sum = start.$[3] / powerOfTenBig(d2 - d1) + bData
}
if (sum >= BIGLIMIT) {
if (max === 9007199254740991) {
num.$ = [1, 1, 9007199254740992n, sum / 10n]
} else {
num.$ = [1, 0, max + 1, sum / 10n]
}
} else {
num.$ = [1, 0, max, sum]
}
} else if (c1 === 1 && c2 === 1) {
var d1 = start.$[2]
var d2 = num.$[2]
var max = d1 > d2 ? d1 : d2
var diff = d1 - d2
if (d1 === d2) {
sum = start.$[3] + bData
} else if (d1 > d2) {
if (d1 - d2 > DIGITSMINUSONE) {
return new Hyper(start)
}
sum = start.$[3] + bData / powerOfTen(diff)
} else {
if (d2 - d1 > DIGITSMINUSONE) {
return num
}
sum = start.$[3] / powerOfTen(-diff) + bData
}
if (sum >= BIGLIMIT) {
if (max === LIMITMINUSONE) {
num.$ = [1, 2, BIGDIGITS, BIGONE]
return num
}
num.$ = [1, 1, max + 1n, sum / 10n]
} else {
num.$ = [1, 1, max, sum]
}
} else if (c1 === 0 && c2 === 1) {
var d1 = BigInt(start.$[2])
var d2 = num.$[2]
var max = d1 > d2 ? d1 : d2
var diff = d1 - d2
if (d1 === d2) {
sum = start.$[3] + bData
} else if (d1 < d2) {
if (d2 - d1 > DIGITSMINUSONE) {
return num
}
sum = start.$[3] / powerOfTen(-diff) + bData
}
if (sum >= BIGLIMIT) {
num.$ = [1, 1, max + 1n, sum / 10n]
} else {
num.$ = [1, 1, max, sum]
}
} else {
var d1 = start.$[2]
var d2 = BigInt(num.$[2])
var max = d1 > d2 ? d1 : d2
var diff = d1 - d2
if (d1 === d2) {
sum = start.$[3] + bData
} else if (d1 > d2) {
if (d1 - d2 > DIGITSMINUSONE) {
return new Hyper(start)
}
sum = start.$[3] + bData / powerOfTen(diff)
}
if (sum >= BIGLIMIT) {
num.$ = [1, 1, max + 1n, sum / 10n]
} else {
num.$ = [1, 1, max, sum]
}
}
return num
}
function HyperSubtractBase(start, b) {
var aData = start.$[3]
var bData = b.$[3]
if (aData === 0n) {
return b.$[3] === 0n ? b : false
} else if (bData === 0n) {
return new Hyper(start)
}
var c1 = start.$[1]
var c2 = b.$[1]
if (c1 >= 2 || c2 >= 2) {
// This optimization (where the code simply finds the higher value) may in theory result in inaccurate numbers for the edge values between categories 1 and 2 that result in slight precision errors, but that is not considered here.
if (c1 === c2) {
if (start.$[2] === b.$[2]) {
if (start.$[3] === b.$[3]) {
return new Hyper()
}
return start.$[3] > b.$[3] ? new Hyper(start) : false
} else {
return start.$[2] > b.$[2] ? new Hyper(start) : false
}
} else {
return c1 > c2 ? new Hyper(start) : false
}
} else if (c1 === c2) {
if (start.$[2] === b.$[2]) {
if (start.$[3] <= b.$[3]) {
if (start.$[3] === b.$[3]) {
b.$ = [1, 0, 0, 0n]
return b
}
return false
}
} else if (start.$[2] < b.$[2]) {
return false
}
} else if (c1 < c2) {
return false
}
var a = new Hyper(start)
var digits = a.$[2]
if (c1 === 0 && c2 === 0) {
var digitDiff = digits - b.$[2]
if (digitDiff > DIGITSMINUSONE) {
return a
}
var modified = aData - (digitDiff === 0 ? bData : bData / powerOfTenBig(digitDiff))
var length = modified.toString().length
if (length !== HDIGITS) {
var digitDiff = HDIGITS - length
digits -= digitDiff
modified *= powerOfTenBig(digitDiff)
}
if (digits <= -9007199254740992) {
a.$ = [1, 0, 0, 0n]
return a
}
a.$[3] = modified
} else if (c1 === 1) {
var digitDiff = a.$[2] - (c2 === 0 ? BigInt(b.$[2]) : b.$[2])
if (digitDiff > DIGITSMINUSONE) {
return a
}
var modified = aData - (digitDiff === 0 ? bData : bData / powerOfTenBig(digitDiff))
var length = modified.toString().length
if (length !== HDIGITS) {
var digitDiff = BigInt(HDIGITS - length)
digits -= digitDiff
modified *= powerOfTen(digitDiff)
}
if (digits < 9007199254740992n) {
a.$[1] = 0
digits = Number(digits)
}
a.$[3] = modified
}
a.$[2] = digits
return a
}
function HyperMultiply(start, value) {
if (value === 1) {
return new Hyper(start)
} else if (start.$[3] === 0n) {
return new Hyper()
}
var isHyper = value instanceof Hyper
var b = new Hyper(value)
if (b.$[3] === 0n) {
return new Hyper()
}
var s1 = start.$[0]
var s2 = b.$[0]
var sign = ((s1 === 1 && s2 === 1) || (s1 === -1 && s2 === -1)) ? 1 : -1
b.$[0] = sign
var c1 = start.$[1]
var c2 = b.$[1]
var digits = b.$[2]
if (c1 === 0 && c2 === 0) {
var multiplied = start.$[3] * b.$[3]
var d1 = start.$[2]
var d = d1 + digits
if (multiplied >= DOUBLELIMIT) {
if (d >= 9007199254740992) {
b.$[1] = 1
d = BigInt(digits + 1) + BigInt(d1)
} else {
if (d <= -9007199254740991) {
b.$ = [sign, 0, 0, 0n]
return b
}
d++
}
b.$[3] = multiplied / BIGLIMIT
} else {
if (d >= 9007199254740992) {
b.$[1] = 1
d = BigInt(digits) + BigInt(d1)
} else if (d <= -9007199254740992) {
b.$ = [sign, 0, 0, 0n]
return b
}
b.$[3] = multiplied / BIGONE
}
b.$[2] = d
return b