-
Notifications
You must be signed in to change notification settings - Fork 46
/
index.d.ts
1313 lines (1313 loc) · 67.6 KB
/
index.d.ts
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
export type CompareResult = -1 | 0 | 1;
export type DecimalSource = Decimal | number | string;
/**
* The value of the Decimal is sign * 10^10^10...^mag, with (layer) 10s. If the layer is not 0, then negative mag means it's the reciprocal of the corresponding number with positive mag.
*/
export default class Decimal {
/**
* Represents the number 0.
*/
static readonly dZero: Decimal;
/**
* Represents the number 1.
*/
static readonly dOne: Decimal;
/**
* Represents the number -1.
*/
static readonly dNegOne: Decimal;
/**
* Represents the number 2.
*/
static readonly dTwo: Decimal;
/**
* Represents the number 10.
*/
static readonly dTen: Decimal;
/**
* Represents a NaN (Not A Number) value.
*/
static readonly dNaN: Decimal;
/**
* Represents positive infinity.
*/
static readonly dInf: Decimal;
/**
* Represents negative infinity.
*/
static readonly dNegInf: Decimal;
/**
* Represents the largest value a JavaScript number can have, which is approximately 1.79 * 10^308.
*/
static readonly dNumberMax: Decimal;
/**
* Represents the smallest value a JavaScript number can have, which is approximately 5 * 10^-324.
*/
static readonly dNumberMin: Decimal;
/**
* Represents the largest Decimal where adding 1 to the layer is a safe operation
* (Decimals larger than this are too big for pow/exp/log to affect, but tetrate/iteratedlog/slog can still affect them).
* Approximately 10^^(9.007 * 10^15).
*/
static readonly dLayerSafeMax: Decimal;
/**
* Represents the smallest Decimal where adding 1 to the layer is a safe operation. Approximately 1 / (10^^(9.007 * 10^15)).
*/
static readonly dLayerSafeMin: Decimal;
/**
* Represents the largest finite value a Decimal can represent. Approximately 10^^(1.79 * 10^308).
*/
static readonly dLayerMax: Decimal;
/**
* Represents the smallest non-zero value a Decimal can represent. Approximately 1 / (10^^(1.79 * 10^308)).
*/
static readonly dLayerMin: Decimal;
private static fromStringCache;
sign: number;
mag: number;
layer: number;
constructor(value?: DecimalSource);
get m(): number;
set m(value: number);
get e(): number;
set e(value: number);
get s(): number;
set s(value: number);
get mantissa(): number;
set mantissa(value: number);
get exponent(): number;
set exponent(value: number);
/**
* Turns the given components into a valid Decimal.
*/
static fromComponents(sign: number, layer: number, mag: number): Decimal;
/**
* Turns the given components into a Decimal, but not necessarily a valid one (it's only valid if the components would already create a valid Decimal without normalization). Users of this library should not use this function.
*/
static fromComponents_noNormalize(sign: number, layer: number, mag: number): Decimal;
/**
* Turns the mantissa and exponent into a valid Decimal with value mantissa * 10^exponent.
*/
static fromMantissaExponent(mantissa: number, exponent: number): Decimal;
/**
* Turns the mantissa and exponent into a Decimal, but not necessarily a valid one. Users of this library should not use this function.
*/
static fromMantissaExponent_noNormalize(mantissa: number, exponent: number): Decimal;
/**
* Creates a deep copy of the provided value.
*/
static fromDecimal(value: Decimal): Decimal;
/**
* Converts a floating-point number into a Decimal.
*/
static fromNumber(value: number): Decimal;
/**
* Converts a string into a Decimal.
*
* If linearhyper4 is true, then strings like "10^^8.5" will use the linear approximation of tetration even for bases <= 10.
*/
static fromString(value: string, linearhyper4?: boolean): Decimal;
/**
* The function used by new Decimal() to create a new Decimal. Accepts a DecimalSource: uses fromNumber if given a number, uses fromString if given a string, and uses fromDecimal if given a Decimal.
*/
static fromValue(value: DecimalSource): Decimal;
/**
* Converts a DecimalSource to a Decimal, without constructing a new Decimal
* if the provided value is already a Decimal.
*
* As the return value could be the provided value itself, this function
* returns a read-only Decimal to prevent accidental mutations of the value.
* Use `new Decimal(value)` to explicitly create a writeable copy if mutation
* is required.
*/
static fromValue_noAlloc(value: DecimalSource): Readonly<Decimal>;
/**
* Absolute value function: returns 'value' if 'value' >= 0, returns the negative of 'value' if 'value' < 0.
*/
static abs(value: DecimalSource): Decimal;
/**
* Returns the negative of the given value.
*/
static neg(value: DecimalSource): Decimal;
/**
* Returns the negative of the given value.
*/
static negate(value: DecimalSource): Decimal;
/**
* Returns the negative of the given value.
*/
static negated(value: DecimalSource): Decimal;
/**
* Returns the sign of the given value.
*/
static sign(value: DecimalSource): number;
/**
* Returns the sign of the given value.
*/
static sgn(value: DecimalSource): number;
/**
* Rounds the value to the nearest integer.
*/
static round(value: DecimalSource): Decimal;
/**
* "Rounds" the value to the nearest integer that's less than or equal to it.
*/
static floor(value: DecimalSource): Decimal;
/**
* "Rounds" the value to the nearest integer that's greater than or equal to it.
*/
static ceil(value: DecimalSource): Decimal;
/**
* Extracts the integer part of the Decimal and returns it. Behaves like floor on positive numbers, but behaves like ceiling on negative numbers.
*/
static trunc(value: DecimalSource): Decimal;
/**
* Addition: returns the sum of the two Decimals.
*/
static add(value: DecimalSource, other: DecimalSource): Decimal;
/**
* Addition: returns the sum of the two Decimals.
*/
static plus(value: DecimalSource, other: DecimalSource): Decimal;
/**
* Subtraction: returns the difference between 'value' and 'other'.
*/
static sub(value: DecimalSource, other: DecimalSource): Decimal;
/**
* Subtraction: returns the difference between 'value' and 'other'.
*/
static subtract(value: DecimalSource, other: DecimalSource): Decimal;
/**
* Subtraction: returns the difference between 'value' and 'other'.
*/
static minus(value: DecimalSource, other: DecimalSource): Decimal;
/**
* Multiplication: returns the product of the two Decimals.
*/
static mul(value: DecimalSource, other: DecimalSource): Decimal;
/**
* Multiplication: returns the product of the two Decimals.
*/
static multiply(value: DecimalSource, other: DecimalSource): Decimal;
/**
* Multiplication: returns the product of the two Decimals.
*/
static times(value: DecimalSource, other: DecimalSource): Decimal;
/**
* Division: returns the quotient of 'value' and 'other'.
*/
static div(value: DecimalSource, other: DecimalSource): Decimal;
/**
* Division: returns the quotient of 'value' and 'other'.
*/
static divide(value: DecimalSource, other: DecimalSource): Decimal;
/**
* Returns the reciprocal (1 / X) of the given value.
*/
static recip(value: DecimalSource): Decimal;
/**
* Returns the reciprocal (1 / X) of the given value.
*/
static reciprocal(value: DecimalSource): Decimal;
/**
* Returns the reciprocal (1 / X) of the given value.
*/
static reciprocate(value: DecimalSource): Decimal;
/**
* Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1.
* Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)...
* unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory.
* These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers.
*/
static mod(value: DecimalSource, other: DecimalSource, floored?: boolean): Decimal;
/**
* Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1.
* Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)...
* unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory.
* These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers.
*/
static modulo(value: DecimalSource, other: DecimalSource, floored?: boolean): Decimal;
/**
* Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1.
* Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)...
* unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory.
* These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers.
*/
static modular(value: DecimalSource, other: DecimalSource, floored?: boolean): Decimal;
/**
* Returns 1 if 'value' > 'other', returns -1 if 'value' < 'other', returns 0 if 'value' == 'other'.
*/
static cmp(value: DecimalSource, other: DecimalSource): CompareResult;
/**
* Compares the absolute values of this and value.
* Returns 1 if |'value'| > |'other'|, returns -1 if |'value'| < |'other'|, returns 0 if |'value'| == |'other'|.
*/
static cmpabs(value: DecimalSource, other: DecimalSource): CompareResult;
/**
* Returns 1 if 'value' > 'other', returns -1 if 'value' < 'other', returns 0 if 'value' == 'other'.
*/
static compare(value: DecimalSource, other: DecimalSource): CompareResult;
/**
* Returns true if the given value is an NaN value.
*/
static isNaN(value: DecimalSource): boolean;
/**
* Returns true if the given value is finite (by Decimal standards, not by floating point standards - a humongous Decimal like 10^^10^100 is still finite!)
*/
static isFinite(value: DecimalSource): boolean;
/**
* The Decimal equivalent of ==. Returns true if 'value' and 'other' have equal values.
*/
static eq(value: DecimalSource, other: DecimalSource): boolean;
/**
* Returns true if 'value' and 'other' have equal values.
*/
static equals(value: DecimalSource, other: DecimalSource): boolean;
/**
* The Decimal equivalent of !=. Returns true if 'value' and 'other' do not have equal values.
*/
static neq(value: DecimalSource, other: DecimalSource): boolean;
/**
* Returns true if 'value' and 'other' do not have equal values.
*/
static notEquals(value: DecimalSource, other: DecimalSource): boolean;
/**
* The Decimal equivalent of <. Returns true if 'value' is less than 'other'.
*/
static lt(value: DecimalSource, other: DecimalSource): boolean;
/**
* The Decimal equivalent of <=. Returns true if 'value' is less than or equal to 'other'.
*/
static lte(value: DecimalSource, other: DecimalSource): boolean;
/**
* The Decimal equivalent of >. Returns true if 'value' is greater than 'other'.
*/
static gt(value: DecimalSource, other: DecimalSource): boolean;
/**
* The Decimal equivalent of >=. Returns true if 'value' is greater than or equal to 'other'.
*/
static gte(value: DecimalSource, other: DecimalSource): boolean;
/**
* Returns whichever of 'value' and 'other' is higher.
*/
static max(value: DecimalSource, other: DecimalSource): Decimal;
/**
* Returns whichever of 'value' and 'other' is lower.
*/
static min(value: DecimalSource, other: DecimalSource): Decimal;
/**
* Returns whichever of 'value' and 'other' has a larger absolute value.
*/
static minabs(value: DecimalSource, other: DecimalSource): Decimal;
/**
* Returns whichever of 'value' and 'other' has a smaller absolute value.
*/
static maxabs(value: DecimalSource, other: DecimalSource): Decimal;
/**
* A combination of minimum and maximum: the value returned by clamp is normally 'value', but it won't go below 'min' and it won't go above 'max'.
* Therefore, if 'value' < 'min', then 'min' is returned, and if 'value' > 'max', then 'max' is returned.
*/
static clamp(value: DecimalSource, min: DecimalSource, max: DecimalSource): Decimal;
/**
* Returns 'value', unless 'value' is less than 'min', in which case 'min' is returned.
*/
static clampMin(value: DecimalSource, min: DecimalSource): Decimal;
/**
* Returns 'value', unless 'value' is greater than 'max', in which case 'max' is returned.
*/
static clampMax(value: DecimalSource, max: DecimalSource): Decimal;
/**
* Returns 1 if 'value' is greater than 'other', returns -1 if 'value' is less than 'other', returns 0 if 'value' is equal to 'other'.
* However, the two Decimals are considered equal if they're approximately equal up to a certain tolerance.
* Tolerance is a relative tolerance, multiplied by the greater of the magnitudes of the two arguments.
* For example, if you put in 1e-9, then any number closer to the
* larger number than (larger number)*1e-9 will be considered equal.
*/
static cmp_tolerance(value: DecimalSource, other: DecimalSource, tolerance: number): CompareResult;
/**
* Returns 1 if 'value' is greater than 'other', returns -1 if 'value' is less than 'other', returns 0 if 'value' is equal to 'other'.
* However, the two Decimals are considered equal if they're approximately equal up to a certain tolerance.
* Tolerance is a relative tolerance, multiplied by the greater of the magnitudes of the two arguments.
* For example, if you put in 1e-9, then any number closer to the
* larger number than (larger number)*1e-9 will be considered equal.
*/
static compare_tolerance(value: DecimalSource, other: DecimalSource, tolerance: number): CompareResult;
/**
* Tests whether two Decimals are approximately equal, up to a certain tolerance.
* Tolerance is a relative tolerance, multiplied by the greater of the magnitudes of the two arguments.
* For example, if you put in 1e-9, then any number closer to the
* larger number than (larger number)*1e-9 will be considered equal.
*/
static eq_tolerance(value: DecimalSource, other: DecimalSource, tolerance: number): boolean;
/**
* Tests whether two Decimals are approximately equal, up to a certain tolerance.
* Tolerance is a relative tolerance, multiplied by the greater of the magnitudes of the two arguments.
* For example, if you put in 1e-9, then any number closer to the
* larger number than (larger number)*1e-9 will be considered equal.
*/
static equals_tolerance(value: DecimalSource, other: DecimalSource, tolerance: number): boolean;
/**
* Tests whether two Decimals are not approximately equal, up to a certain tolerance.
* Tolerance is a relative tolerance, multiplied by the greater of the magnitudes of the two arguments.
* For example, if you put in 1e-9, then any number closer to the
* larger number than (larger number)*1e-9 will be considered equal.
*/
static neq_tolerance(value: DecimalSource, other: DecimalSource, tolerance: number): boolean;
/**
* Tests whether two Decimals are not approximately equal, up to a certain tolerance.
* Tolerance is a relative tolerance, multiplied by the greater of the magnitudes of the two arguments.
* For example, if you put in 1e-9, then any number closer to the
* larger number than (larger number)*1e-9 will be considered equal.
*/
static notEquals_tolerance(value: DecimalSource, other: DecimalSource, tolerance: number): boolean;
/**
* Returns true if 'value' is less than 'other'.
* However, the two Decimals are considered equal if they're approximately equal up to a certain tolerance.
* Tolerance is a relative tolerance, multiplied by the greater of the magnitudes of the two arguments.
* For example, if you put in 1e-9, then any number closer to the
* larger number than (larger number)*1e-9 will be considered equal.
*/
static lt_tolerance(value: DecimalSource, other: DecimalSource, tolerance: number): boolean;
/**
* Returns true if 'value' is less than or equal to 'other'.
* However, the two Decimals are considered equal if they're approximately equal up to a certain tolerance.
* Tolerance is a relative tolerance, multiplied by the greater of the magnitudes of the two arguments.
* For example, if you put in 1e-9, then any number closer to the
* larger number than (larger number)*1e-9 will be considered equal.
*/
static lte_tolerance(value: DecimalSource, other: DecimalSource, tolerance: number): boolean;
/**
* Returns true if 'value' is greater than 'other'.
* However, the two Decimals are considered equal if they're approximately equal up to a certain tolerance.
* Tolerance is a relative tolerance, multiplied by the greater of the magnitudes of the two arguments.
* For example, if you put in 1e-9, then any number closer to the
* larger number than (larger number)*1e-9 will be considered equal.
*/
static gt_tolerance(value: DecimalSource, other: DecimalSource, tolerance: number): boolean;
/**
* Returns true if 'value' is greater than or equal to 'other'.
* However, the two Decimals are considered equal if they're approximately equal up to a certain tolerance.
* Tolerance is a relative tolerance, multiplied by the greater of the magnitudes of the two arguments.
* For example, if you put in 1e-9, then any number closer to the
* larger number than (larger number)*1e-9 will be considered equal.
*/
static gte_tolerance(value: DecimalSource, other: DecimalSource, tolerance: number): boolean;
/**
* "Positive log10": Returns the base-10 logarithm of nonnegative Decimals, but returns 0 for negative Decimals.
*/
static pLog10(value: DecimalSource): Decimal;
/**
* Returns the base-10 logarithm of abs('value').
*/
static absLog10(value: DecimalSource): Decimal;
/**
* Base-10 logarithm: returns the Decimal X such that 10^X = 'value'.
* For numbers above layer 0, this is equivalent to subtracting 1 from layer and normalizing.
*/
static log10(value: DecimalSource): Decimal;
/**
* Logarithms are one of the inverses of exponentiation: this function finds the Decimal X such that base^X = 'value'.
*/
static log(value: DecimalSource, base: DecimalSource): Decimal;
/**
* Base-2 logarithm: returns the Decimal X such that 2^X = 'value'.
*/
static log2(value: DecimalSource): Decimal;
/**
* Base-e logarithm, also known as the "natural" logarithm: returns the Decimal X such that e^X = 'value'.
*/
static ln(value: DecimalSource): Decimal;
/**
* Logarithms are one of the inverses of exponentiation: this function finds the Decimal X such that base^X = 'value'.
*/
static logarithm(value: DecimalSource, base: DecimalSource): Decimal;
/**
* Exponentiation: Returns the result of 'value' ^ 'other' (often written as 'value' ** 'other' in programming languages).
*/
static pow(value: DecimalSource, other: DecimalSource): Decimal;
/**
* Raises 10 to the power of 'value', i.e. (10^'value'). For positive numbers above 1, this is equivalent to adding 1 to the value's layer and normalizing.
*/
static pow10(value: DecimalSource): Decimal;
/**
* Roots are one of the inverses of exponentiation: this function finds the Decimal X such that X ^ 'other' = 'value'.
* Equivalent to 'value' ^ (1 / 'other'), which is written here as value.pow(other.recip()).
*/
static root(value: DecimalSource, other: DecimalSource): Decimal;
/**
* For positive integers, X factorial (written as X!) equals X * (X - 1) * (X - 2) *... * 3 * 2 * 1. 0! equals 1.
* This can be extended to real numbers (except for negative integers) via the gamma function, which is what this function does.
*/
static factorial(value: DecimalSource, _other?: never): Decimal;
/**
* The gamma function extends the idea of factorials to non-whole numbers using some calculus.
* Gamma(x) is defined as the integral of t^(x-1) * e^-t dt from t = 0 to t = infinity,
* and gamma(x) = (x - 1)! for nonnegative integer x, so the factorial for non-whole numbers is defined using the gamma function.
*/
static gamma(value: DecimalSource, _other?: never): Decimal;
/**
* Returns the natural (base-e) logarithm of Gamma('value').
*/
static lngamma(value: DecimalSource, _other?: never): Decimal;
/**
* Base-e exponentiation: returns e^'value'.
*/
static exp(value: DecimalSource): Decimal;
/**
* Squaring a number means multiplying it by itself, a.k.a. raising it to the second power.
*/
static sqr(value: DecimalSource): Decimal;
/**
* Square root: finds the Decimal X such that X * X, a.k.a X^2, equals 'value'. Equivalent to X^(1/2).
*/
static sqrt(value: DecimalSource): Decimal;
/**
* Cubing a number means raising it to the third power.
*/
static cube(value: DecimalSource): Decimal;
/**
* Cube root: finds the Decimal X such that X^3 equals 'value'. Equivalent to X^(1/3).
*/
static cbrt(value: DecimalSource): Decimal;
/**
*
* Tetration: The result of exponentiating 'value' to 'value' 'height' times in a row. https://en.wikipedia.org/wiki/Tetration
*
* If payload != 1, then this is 'iterated exponentiation', the result of exping 'payload' to base 'value' 'height' times. https://andydude.github.io/tetration/archives/tetration2/ident.html
*
* Works with negative and positive real heights. Tetration for non-integer heights does not have a single agreed-upon definition,
* so this library uses an analytic approximation for bases <= 10, but it reverts to the linear approximation for bases > 10.
* If you want to use the linear approximation even for bases <= 10, set the linear parameter to true.
* Analytic approximation is not currently supported for bases > 10.
*/
static tetrate(value: DecimalSource, height?: number, payload?: DecimalSource, linear?: boolean): Decimal;
/**
* Iterated exponentiation, the result of exping 'payload' to base 'value' 'height' times. https://andydude.github.io/tetration/archives/tetration2/ident.html
*
* Works with negative and positive real heights. Tetration for non-integer heights does not have a single agreed-upon definition,
* so this library uses an analytic approximation for bases <= 10, but it reverts to the linear approximation for bases > 10.
* If you want to use the linear approximation even for bases <= 10, set the linear parameter to true.
* Analytic approximation is not currently supported for bases > 10.
*
* Identical to tetrate.
*/
static iteratedexp(value: DecimalSource, height?: number, payload?: Decimal, linear?: boolean): Decimal;
/**
* iterated log/repeated log: The result of applying log(base) 'times' times in a row. Approximately equal to subtracting 'times' from the number's slog representation. Equivalent to tetrating to a negative height.
*
* Works with negative and positive real heights. Tetration for non-integer heights does not have a single agreed-upon definition,
* so this library uses an analytic approximation for bases <= 10, but it reverts to the linear approximation for bases > 10.
* If you want to use the linear approximation even for bases <= 10, set the linear parameter to true.
* Analytic approximation is not currently supported for bases > 10.
*/
static iteratedlog(value: DecimalSource, base?: DecimalSource, times?: number, linear?: boolean): Decimal;
/**
* Adds/removes layers from a Decimal, even fractional layers (e.g. its slog10 representation). Very similar to tetrate base 10 and iterated log base 10.
*
* Tetration for non-integer heights does not have a single agreed-upon definition,
* so this library uses an analytic approximation for bases <= 10, but it reverts to the linear approximation for bases > 10.
* If you want to use the linear approximation even for bases <= 10, set the linear parameter to true.
* Analytic approximation is not currently supported for bases > 10.
*/
static layeradd10(value: DecimalSource, diff: DecimalSource, linear?: boolean): Decimal;
/**
* layeradd: like adding 'diff' to the number's slog(base) representation. Very similar to tetrate base 'base' and iterated log base 'base'.
*
* Tetration for non-integer heights does not have a single agreed-upon definition,
* so this library uses an analytic approximation for bases <= 10, but it reverts to the linear approximation for bases > 10.
* If you want to use the linear approximation even for bases <= 10, set the linear parameter to true.
* Analytic approximation is not currently supported for bases > 10.
*/
static layeradd(value: DecimalSource, diff: number, base?: DecimalSource, linear?: boolean): Decimal;
/**
* Super-logarithm, one of tetration's inverses, tells you what size power tower you'd have to tetrate 'base' to to get 'value'. https://en.wikipedia.org/wiki/Super-logarithm
*
* By definition, will never be higher than 1.8e308 in break_eternity.js, since a power tower 1.8e308 numbers tall is the largest representable number.
*
* Accepts a number of iterations (default is 100), and use binary search to, after making an initial guess, hone in on the true value, assuming tetration as the ground truth.
*
* Tetration for non-integer heights does not have a single agreed-upon definition,
* so this library uses an analytic approximation for bases <= 10, but it reverts to the linear approximation for bases > 10.
* If you want to use the linear approximation even for bases <= 10, set the linear parameter to true.
* Analytic approximation is not currently supported for bases > 10.
*/
static slog(value: DecimalSource, base?: DecimalSource, linear?: boolean): Decimal;
/**
* The Lambert W function, also called the omega function or product logarithm, is the solution W(x) === x*e^x.
* https://en.wikipedia.org/wiki/Lambert_W_function
*
* This is a multi-valued function in the complex plane, but only two branches matter for real numbers: the "principal branch" W0, and the "non-principal branch" W_-1.
* W_0 works for any number >= -1/e, but W_-1 only works for negative numbers >= -1/e.
* The "principal" parameter, which is true by default, decides which branch we're looking for: W_0 is used if principal is true, W_-1 is used if principal is false.
*/
static lambertw(value: DecimalSource, principal: boolean): Decimal;
/**
* The super square-root function - what number, tetrated to height 2, equals 'value'? https://en.wikipedia.org/wiki/Tetration#Super-root
*/
static ssqrt(value: DecimalSource): Decimal;
/**
* Super-root, one of tetration's inverses - what number, tetrated to height 'degree', equals 'value'? https://en.wikipedia.org/wiki/Tetration#Super-root
*
* Only works with the linear approximation of tetration, as starting with analytic and then switching to linear would result in inconsistent behavior for super-roots.
* This only matters for non-integer degrees.
*/
static linear_sroot(value: DecimalSource, degree: number): Decimal;
/**
* Pentation/pentate: The result of tetrating 'height' times in a row. An absurdly strong operator - Decimal.pentate(2, 4.28) and Decimal.pentate(10, 2.37) are already too huge for break_eternity.js!
* https://en.wikipedia.org/wiki/Pentation
*
* Tetration for non-integer heights does not have a single agreed-upon definition,
* so this library uses an analytic approximation for bases <= 10, but it reverts to the linear approximation for bases > 10.
* If you want to use the linear approximation even for bases <= 10, set the linear parameter to true.
* Analytic approximation is not currently supported for bases > 10.
*
* For non-whole pentation heights, the linear approximation of pentation is always used, as there is no defined analytic approximation of pentation.
*/
static pentate(value: DecimalSource, height?: number, payload?: DecimalSource, linear?: boolean): Decimal;
/**
* Penta-logarithm, one of pentation's inverses, tells you what height you'd have to pentate 'base' to to get 'value'.
*
* Grows incredibly slowly. For bases above 2, you won't be seeing a result greater than 5 out of this function.
*
* Accepts a number of iterations (default is 100), and use binary search to, after making an initial guess, hone in on the true value, assuming pentation as the ground truth.
*
* Tetration for non-integer heights does not have a single agreed-upon definition,
* so this library uses an analytic approximation for bases <= 10, but it reverts to the linear approximation for bases > 10.
* If you want to use the linear approximation even for bases <= 10, set the linear parameter to true.
* Analytic approximation is not currently supported for bases > 10.
*
* For non-whole pentation heights, the linear approximation of pentation is always used, as there is no defined analytic approximation of pentation.
*/
static penta_log(value: DecimalSource, base?: DecimalSource, linear?: boolean): Decimal;
/**
* Penta-root, one of pentation's inverses - what number, pentated to height 'degree', equals 'value'?
*
* Only works with the linear approximation of tetration, as starting with analytic and then switching to linear would result in inconsistent behavior for super-roots.
*/
static linear_penta_root(value: DecimalSource, degree: number): Decimal;
/**
* The sine function, one of the main two trigonometric functions. Behaves periodically with period 2*pi.
*/
static sin(value: DecimalSource): Decimal;
/**
* The cosine function, one of the main two trigonometric functions. Behaves periodically with period 2*pi.
*/
static cos(value: DecimalSource): Decimal;
/**
* The tangent function, equal to sine divided by cosine. Behaves periodically with period pi.
*/
static tan(value: DecimalSource): Decimal;
/**
* The arcsine function, the inverse of the sine function.
*/
static asin(value: DecimalSource): Decimal;
/**
* The arccosine function, the inverse of the cosine function.
*/
static acos(value: DecimalSource): Decimal;
/**
* The arctangent function, the inverse of the tangent function.
*/
static atan(value: DecimalSource): Decimal;
/**
* Hyperbolic sine: sinh(X) = (e^x - e^-x)/2.
*/
static sinh(value: DecimalSource): Decimal;
/**
* Hyperbolic cosine: cosh(x) = (e^x + e^-x)/2.
*/
static cosh(value: DecimalSource): Decimal;
/**
* Hyperbolic tangent: tanh(x) = sinh(x)/cosh(x).
*/
static tanh(value: DecimalSource): Decimal;
/**
* Hyperbolic arcsine, the inverse of hyperbolic sine.
*/
static asinh(value: DecimalSource): Decimal;
/**
* Hyperbolic arccosine, the inverse of hyperbolic cosine.
*/
static acosh(value: DecimalSource): Decimal;
/**
* Hyperbolic arcctangent, the inverse of hyperbolic tangent.
*/
static atanh(value: DecimalSource): Decimal;
/**
* If you're willing to spend 'resourcesAvailable' and want to buy something
* with exponentially increasing cost each purchase (start at priceStart,
* multiply by priceRatio, already own currentOwned), how much of it can you buy?
* Adapted from Trimps source code.
*/
static affordGeometricSeries(resourcesAvailable: DecimalSource, priceStart: DecimalSource, priceRatio: DecimalSource, currentOwned: DecimalSource): Decimal;
/**
* How much resource would it cost to buy (numItems) items if you already have currentOwned,
* the initial price is priceStart and it multiplies by priceRatio each purchase?
*/
static sumGeometricSeries(numItems: DecimalSource, priceStart: DecimalSource, priceRatio: DecimalSource, currentOwned: DecimalSource): Decimal;
/**
* If you're willing to spend 'resourcesAvailable' and want to buy something with additively
* increasing cost each purchase (start at priceStart, add by priceAdd, already own currentOwned),
* how much of it can you buy?
*/
static affordArithmeticSeries(resourcesAvailable: DecimalSource, priceStart: DecimalSource, priceAdd: DecimalSource, currentOwned: DecimalSource): Decimal;
/**
* How much resource would it cost to buy (numItems) items if you already have currentOwned,
* the initial price is priceStart and it adds priceAdd each purchase?
* Adapted from http://www.mathwords.com/a/arithmetic_series.htm
*/
static sumArithmeticSeries(numItems: DecimalSource, priceStart: DecimalSource, priceAdd: DecimalSource, currentOwned: DecimalSource): Decimal;
/**
* When comparing two purchases that cost (resource) and increase your resource/sec by (deltaRpS),
* the lowest efficiency score is the better one to purchase.
* From Frozen Cookies:
* http://cookieclicker.wikia.com/wiki/Frozen_Cookies_(JavaScript_Add-on)#Efficiency.3F_What.27s_that.3F
*/
static efficiencyOfPurchase(cost: DecimalSource, currentRpS: DecimalSource, deltaRpS: DecimalSource): Decimal;
static randomDecimalForTesting(maxLayers: number): Decimal;
static affordGeometricSeries_core(resourcesAvailable: Decimal, priceStart: Decimal, priceRatio: Decimal, currentOwned: DecimalSource): Decimal;
static sumGeometricSeries_core(numItems: DecimalSource, priceStart: Decimal, priceRatio: Decimal, currentOwned: DecimalSource): Decimal;
static affordArithmeticSeries_core(resourcesAvailable: Decimal, priceStart: Decimal, priceAdd: Decimal, currentOwned: Decimal): Decimal;
static sumArithmeticSeries_core(numItems: Decimal, priceStart: Decimal, priceAdd: Decimal, currentOwned: Decimal): Decimal;
static efficiencyOfPurchase_core(cost: Decimal, currentRpS: Decimal, deltaRpS: Decimal): Decimal;
/**
* Turns the Decimal into a valid Decimal. This function is meant for internal purposes - users of this library should not need to use normalize.
*
* Note: this function mutates the Decimal it is called on.
*/
normalize(): this;
/**
* Turns the given components into a valid Decimal.
*
* Note: this function mutates the Decimal it is called on.
*/
fromComponents(sign: number, layer: number, mag: number): this;
/**
* Turns the given components into a Decimal, but not necessarily a valid one (it's only valid if the components would already create a valid Decimal without normalization). Users of this library should not use this function.
*
* Note: this function mutates the Decimal it is called on.
*/
fromComponents_noNormalize(sign: number, layer: number, mag: number): this;
/**
* Turns the mantissa and exponent into a valid Decimal with value mantissa * 10^exponent.
*
* Note: this function mutates the Decimal it is called on.
*/
fromMantissaExponent(mantissa: number, exponent: number): this;
/**
* Turns the mantissa and exponent into a Decimal, but not necessarily a valid one. Users of this library should not use this function.
*
* Note: this function mutates the Decimal it is called on.
*/
fromMantissaExponent_noNormalize(mantissa: number, exponent: number): this;
/**
* Turns the Decimal that this function is called on into a deep copy of the provided value.
*
* Note: this function mutates the Decimal it is called on.
*/
fromDecimal(value: Decimal): this;
/**
* Converts a floating-point number into a Decimal.
*
* Note: this function mutates the Decimal it is called on.
*/
fromNumber(value: number): this;
/**
* Converts a string into a Decimal.
*
* If linearhyper4 is true, then strings like "10^^8.5" will use the linear approximation of tetration even for bases <= 10.
*
* Note: this function mutates the Decimal it is called on.
*/
fromString(value: string, linearhyper4?: boolean): Decimal;
/**
* The function used by new Decimal() to create a new Decimal. Accepts a DecimalSource: uses fromNumber if given a number, uses fromString if given a string, and uses fromDecimal if given a Decimal.
*
* Note: this function mutates the Decimal it is called on.
*/
fromValue(value: DecimalSource): Decimal;
/**
* Returns the numeric value of the Decimal it's called on. Will return Infinity (or -Infinity for negatives) for Decimals that are larger than Number.MAX_VALUE.
*/
toNumber(): number;
mantissaWithDecimalPlaces(places: number): number;
magnitudeWithDecimalPlaces(places: number): number;
/**
* Returns a string representation of the Decimal it's called on.
* This string is written as a plain number for most layer 0 numbers, in scientific notation for layer 1 numbers (and layer 0 numbers below 1e-6),
* in "ee...X" form for numbers from layers 2 to 5, and in (e^N)X form for layer > 5.
*/
toString(): string;
toExponential(places: number): string;
toFixed(places: number): string;
toPrecision(places: number): string;
valueOf(): string;
toJSON(): string;
toStringWithDecimalPlaces(places: number): string;
/**
* Absolute value function: returns 'this' if 'this' >= 0, returns the negative of 'this' if this < 0.
*/
abs(): Decimal;
/**
* Negates the Decimal it's called on: in other words, when given X, returns -X.
*/
neg(): Decimal;
/**
* Negates the Decimal it's called on: in other words, when given X, returns -X.
*/
negate(): Decimal;
/**
* Negates the Decimal it's called on: in other words, when given X, returns -X.
*/
negated(): Decimal;
/**
* Returns the sign of the Decimal it's called on. (Though, since sign is a public data member of Decimal, you might as well just call .sign instead of .sgn())
*/
sgn(): number;
/**
* Rounds the Decimal it's called on to the nearest integer.
*/
round(): Decimal;
/**
* "Rounds" the Decimal it's called on to the nearest integer that's less than or equal to it.
*/
floor(): Decimal;
/**
* "Rounds" the Decimal it's called on to the nearest integer that's greater than or equal to it.
*/
ceil(): Decimal;
/**
* Extracts the integer part of the Decimal and returns it. Behaves like floor on positive numbers, but behaves like ceiling on negative numbers.
*/
trunc(): Decimal;
/**
* Addition: returns the sum of 'this' and 'value'.
*/
add(value: DecimalSource): this | Decimal;
/**
* Addition: returns the sum of 'this' and 'value'.
*/
plus(value: DecimalSource): Decimal;
/**
* Subtraction: returns the difference between 'this' and 'value'.
*/
sub(value: DecimalSource): Decimal;
/**
* Subtraction: returns the difference between 'this' and 'value'.
*/
subtract(value: DecimalSource): Decimal;
/**
* Subtraction: returns the difference between 'this' and 'value'.
*/
minus(value: DecimalSource): Decimal;
/**
* Multiplication: returns the product of 'this' and 'value'.
*/
mul(value: DecimalSource): Decimal;
/**
* Multiplication: returns the product of 'this' and 'value'.
*/
multiply(value: DecimalSource): Decimal;
/**
* Multiplication: returns the product of 'this' and 'value'.
*/
times(value: DecimalSource): Decimal;
/**
* Division: returns the quotient of 'this' and 'value'.
*/
div(value: DecimalSource): Decimal;
/**
* Division: returns the quotient of 'this' and 'value'.
*/
divide(value: DecimalSource): Decimal;
/**
* Division: returns the quotient of 'this' and 'value'.
*/
divideBy(value: DecimalSource): Decimal;
/**
* Division: returns the quotient of 'this' and 'value'.
*/
dividedBy(value: DecimalSource): Decimal;
/**
* Returns the reciprocal (1 / X) of the Decimal it's called on.
*/
recip(): Decimal;
/**
* Returns the reciprocal (1 / X) of the Decimal it's called on.
*/
reciprocal(): Decimal;
/**
* Returns the reciprocal (1 / X) of the Decimal it's called on.
*/
reciprocate(): Decimal;
/**
* Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1.
* Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)...
* unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory.
* These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers.
*/
mod(value: DecimalSource, floored?: boolean): Decimal;
/**
* Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1.
* Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)...
* unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory.
* These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers.
*/
modulo(value: DecimalSource, floored?: boolean): Decimal;
/**
* Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1.
* Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)...
* unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory.
* These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers.
*/
modular(value: DecimalSource, floored?: boolean): Decimal;
/**
* Returns 1 if 'this' > 'value', returns -1 if 'this' < 'value', returns 0 if 'this' == 'value'.
*/
cmp(value: DecimalSource): CompareResult;
/**
* Compares the absolute values of this and value.
* Returns 1 if |'this'| > |'value'|, returns -1 if |'this'| < |'value'|, returns 0 if |'this'| == |'value'|.
*/
cmpabs(value: DecimalSource): CompareResult;
/**
* Returns 1 if 'this' > 'value', returns -1 if 'this' < 'value', returns 0 if 'this' == 'value'.
*/
compare(value: DecimalSource): CompareResult;
/**
* Returns true if the Decimal is an NaN value.
*/
isNan(): boolean;
/**
* Returns true if the Decimal is finite (by Decimal standards, not by floating point standards - a humongous Decimal like 10^^10^100 is still finite!)
*/
isFinite(): boolean;
/**
* The Decimal equivalent of ==. Returns true if 'this' and 'value' have equal values.
*/
eq(value: DecimalSource): boolean;
/**
* Returns true if 'this' and 'value' have equal values.
*/
equals(value: DecimalSource): boolean;
/**
* The Decimal equivalent of !=. Returns true if 'this' and 'value' do not have equal values.
*/
neq(value: DecimalSource): boolean;
/**
* Returns true if 'this' and 'value' do not have equal values.
*/
notEquals(value: DecimalSource): boolean;
/**
* The Decimal equivalent of <. Returns true if 'this' is less than 'value'.
*/
lt(value: DecimalSource): boolean;
/**
* The Decimal equivalent of <=. Returns true if 'this' is less than or equal to 'value'.
*/
lte(value: DecimalSource): boolean;
/**
* The Decimal equivalent of >. Returns true if 'this' is greater than 'value'.
*/
gt(value: DecimalSource): boolean;
/**
* The Decimal equivalent of >=. Returns true if 'this' is greater than or equal to 'value'.
*/
gte(value: DecimalSource): boolean;
/**
* Returns whichever of 'this' and 'value' is higher.
*/
max(value: DecimalSource): Decimal;
/**
* Returns whichever of 'this' and 'value' is lower.
*/
min(value: DecimalSource): Decimal;
/**
* Returns whichever of 'this' and 'value' has a larger absolute value.
*/
maxabs(value: DecimalSource): Decimal;
/**
* Returns whichever of 'this' and 'value' has a smaller absolute value.
*/
minabs(value: DecimalSource): Decimal;
/**
* A combination of minimum and maximum: the value returned by clamp is normally 'this', but it won't go below 'min' and it won't go above 'max'.
* Therefore, if 'this' < 'min', then 'min' is returned, and if 'this' > 'max', then 'max' is returned.
*/
clamp(min: DecimalSource, max: DecimalSource): Decimal;
/**
* Returns 'this', unless 'this' is less than 'min', in which case 'min' is returned.
*/
clampMin(min: DecimalSource): Decimal;
/**
* Returns 'this', unless 'this' is greater than 'max', in which case 'max' is returned.
*/
clampMax(max: DecimalSource): Decimal;
/**
* Returns 1 if 'this' is greater than 'value', returns -1 if 'this' is less than 'value', returns 0 if 'this' is equal to 'value'.
* However, the two Decimals are considered equal if they're approximately equal up to a certain tolerance.
* Tolerance is a relative tolerance, multiplied by the greater of the magnitudes of the two arguments.
* For example, if you put in 1e-9, then any number closer to the
* larger number than (larger number)*1e-9 will be considered equal.
*/
cmp_tolerance(value: DecimalSource, tolerance: number): CompareResult;
/**
* Returns 1 if 'this' is greater than 'value', returns -1 if 'this' is less than 'value', returns 0 if 'this' is equal to 'value'.
* However, the two Decimals are considered equal if they're approximately equal up to a certain tolerance.
* Tolerance is a relative tolerance, multiplied by the greater of the magnitudes of the two arguments.
* For example, if you put in 1e-9, then any number closer to the
* larger number than (larger number)*1e-9 will be considered equal.
*/
compare_tolerance(value: DecimalSource, tolerance: number): CompareResult;
/**
* Tests whether two Decimals are approximately equal, up to a certain tolerance.
* Tolerance is a relative tolerance, multiplied by the greater of the magnitudes of the two arguments.
* For example, if you put in 1e-9, then any number closer to the
* larger number than (larger number)*1e-9 will be considered equal.
*/
eq_tolerance(value: DecimalSource, tolerance: number): boolean;
/**
* Tests whether two Decimals are approximately equal, up to a certain tolerance.
* Tolerance is a relative tolerance, multiplied by the greater of the magnitudes of the two arguments.
* For example, if you put in 1e-9, then any number closer to the
* larger number than (larger number)*1e-9 will be considered equal.
*/
equals_tolerance(value: DecimalSource, tolerance: number): boolean;
/**
* Tests whether two Decimals are not approximately equal, up to a certain tolerance.
* Tolerance is a relative tolerance, multiplied by the greater of the magnitudes of the two arguments.
* For example, if you put in 1e-9, then any number closer to the
* larger number than (larger number)*1e-9 will be considered equal.
*/
neq_tolerance(value: DecimalSource, tolerance: number): boolean;
/**
* Tests whether two Decimals are not approximately equal, up to a certain tolerance.
* Tolerance is a relative tolerance, multiplied by the greater of the magnitudes of the two arguments.
* For example, if you put in 1e-9, then any number closer to the
* larger number than (larger number)*1e-9 will be considered equal.
*/
notEquals_tolerance(value: DecimalSource, tolerance: number): boolean;
/**
* Returns true if 'this' is less than 'value'.
* However, the two Decimals are considered equal if they're approximately equal up to a certain tolerance.
* Tolerance is a relative tolerance, multiplied by the greater of the magnitudes of the two arguments.
* For example, if you put in 1e-9, then any number closer to the
* larger number than (larger number)*1e-9 will be considered equal.
*/
lt_tolerance(value: DecimalSource, tolerance: number): boolean;
/**
* Returns true if 'this' is less than or equal to 'value'.
* However, the two Decimals are considered equal if they're approximately equal up to a certain tolerance.