@nodef/extra-bigint.web 0.0.0-stage → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +179 -2
- package/deno.lock +37 -0
- package/index.d.ts +276 -0
- package/index.js +2 -0
- package/index.js.map +7 -0
- package/index.test.ts +743 -0
- package/package.json +13 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020-26 Subhajit Sahu
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,180 @@
|
|
|
1
|
-
|
|
1
|
+
A [BigInt] can represent whole numbers larger than 2⁵³ - 1 [(1)].<br>
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
▌
|
|
4
|
+
📦 [JSR](https://jsr.io/@nodef/extra-bigint),
|
|
5
|
+
📦 [NPM](https://www.npmjs.com/package/@nodef/extra-bigint),
|
|
6
|
+
🌐 [Web](https://cdn.jsdelivr.net/npm/@nodef/extra-bigint.web),
|
|
7
|
+
📰 [Docs](https://jsr.io/@nodef/extra-bigint/doc).
|
|
8
|
+
|
|
9
|
+
*ES2020* introduced **BigInt** as a built-in object. **BigInt** enables us to
|
|
10
|
+
represent integers with arbitrary precision, allowing us to perform mathematical
|
|
11
|
+
operations on large integers [(2)]. This package includes common bigint
|
|
12
|
+
functions related to querying **about** numbers, **comparing** numbers,
|
|
13
|
+
performing **rounded division**, performing **modulo** operations, **controlling**
|
|
14
|
+
**range** of numbers, performing **arithmetic** operations, obtaining **divisors**
|
|
15
|
+
of a number (and related operations), getting the number of possible
|
|
16
|
+
**arrangements** of a set of objects, performing **geometry**-related
|
|
17
|
+
calculations, performing basic **statistical** analysis, and finding various
|
|
18
|
+
**statistical means**.
|
|
19
|
+
|
|
20
|
+
[BigInt]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt
|
|
21
|
+
[(1)]: https://www.geeksforgeeks.org/bigint-in-javascript/
|
|
22
|
+
[(2)]: https://www.smashingmagazine.com/2019/07/essential-guide-javascript-newest-data-type-bigint/
|
|
23
|
+
|
|
24
|
+
<br>
|
|
25
|
+
|
|
26
|
+
```javascript
|
|
27
|
+
import * as xbigint from "jsr:@nodef/extra-bigint";
|
|
28
|
+
|
|
29
|
+
xbigint.isPrime(113n);
|
|
30
|
+
// → true
|
|
31
|
+
|
|
32
|
+
xbigint.floorDiv(7n, 3n);
|
|
33
|
+
// → 2n
|
|
34
|
+
|
|
35
|
+
xbigint.sqrt(81n);
|
|
36
|
+
// → 9n
|
|
37
|
+
|
|
38
|
+
xbigint.lcm(2n, 3n, 4n);
|
|
39
|
+
// → 12n
|
|
40
|
+
|
|
41
|
+
xbigint.log2(8n);
|
|
42
|
+
// → 3n
|
|
43
|
+
|
|
44
|
+
xbigint.sum(1n, 2n, 3n, 4n);
|
|
45
|
+
// → 10n
|
|
46
|
+
|
|
47
|
+
xbigint.mean(1n, 7n, 8n);
|
|
48
|
+
// → 5n
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
<br>
|
|
52
|
+
<br>
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
## Index
|
|
56
|
+
|
|
57
|
+
| Property | Description |
|
|
58
|
+
| ---- | ---- |
|
|
59
|
+
| [is] | Check if value is a bigint. |
|
|
60
|
+
| | |
|
|
61
|
+
| [compare] | Compare two bigints. |
|
|
62
|
+
| | |
|
|
63
|
+
| [abs] | Get the absolute of a bigint. |
|
|
64
|
+
| [sign] | Get the sign of a bigint. |
|
|
65
|
+
| | |
|
|
66
|
+
| [floorDiv] | Perform floor-divison of two bigints (\\). |
|
|
67
|
+
| [ceilDiv] | Perform ceiling-divison of two bigints. |
|
|
68
|
+
| [roundDiv] | Perform rounded-divison of two bigints. |
|
|
69
|
+
| | |
|
|
70
|
+
| [rem] | Find the remainder of x/y with sign of x (truncated division). |
|
|
71
|
+
| [mod] | Find the remainder of x/y with sign of y (floored division). |
|
|
72
|
+
| [modp] | Find the remainder of x/y with +ve sign (euclidean division). |
|
|
73
|
+
| | |
|
|
74
|
+
| [constrain] | Constrain a bigint within a minimum and a maximum value. |
|
|
75
|
+
| [remap] | Re-map a bigint from one range to another. |
|
|
76
|
+
| [lerp] | Linearly interpolate a bigint between two bigints. |
|
|
77
|
+
| | |
|
|
78
|
+
| [isPow2] | Check if bigint is a power-of-2. |
|
|
79
|
+
| [isPow10] | Check if bigint is a power-of-10. |
|
|
80
|
+
| [prevPow2] | Find largest power-of-2 less than or equal to given bigint. |
|
|
81
|
+
| [prevPow10] | Find largest power-of-10 less than or equal to given bigint. |
|
|
82
|
+
| [nextPow2] | Find smallest power-of-2 greater than or equal to given bigint. |
|
|
83
|
+
| [nextPow10] | Find smallest power-of-10 greater than or equal to given bigint. |
|
|
84
|
+
| [log2] | Find the base-2 logarithm of a bigint. |
|
|
85
|
+
| [log10] | Find the base-10 logarithm of a bigint. |
|
|
86
|
+
| | |
|
|
87
|
+
| [sqrt] | Find the square root of a bigint. |
|
|
88
|
+
| [cbrt] | Find the cube root of a bigint. |
|
|
89
|
+
| [root] | Find the nth root of a bigint. |
|
|
90
|
+
| | |
|
|
91
|
+
| [properDivisors] | List all divisors of a bigint, except itself. |
|
|
92
|
+
| [aliquotSum] | Sum all proper divisors of a bigint. |
|
|
93
|
+
| [minPrimeFactor] | Find the least prime number which divides a bigint. |
|
|
94
|
+
| [maxPrimeFactor] | Find the greatest prime number which divides a bigint. |
|
|
95
|
+
| [primeFactors] | Find the prime factors of a bigint. |
|
|
96
|
+
| [primeExponentials] | Find the prime factors and respective exponents of a bigint. |
|
|
97
|
+
| [isPrime] | Check if bigint is prime. |
|
|
98
|
+
| [gcd] | Find the greatest common divisor of bigints. |
|
|
99
|
+
| [lcm] | Find the least common multiple of bigints. |
|
|
100
|
+
| | |
|
|
101
|
+
| [factorial] | Find the factorial of a bigint. |
|
|
102
|
+
| [binomial] | Find the number of ways to choose k elements from a set of n elements. |
|
|
103
|
+
| [multinomial] | Find the number of ways to put n objects in m bins (n=sum(kᵢ)). |
|
|
104
|
+
| | |
|
|
105
|
+
| [hypot] | Find the length of hypotenuse. |
|
|
106
|
+
| | |
|
|
107
|
+
| [sum] | Find the sum of bigints (Σ). |
|
|
108
|
+
| [product] | Find the product of bigints (∏). |
|
|
109
|
+
| [median] | Find the value separating the higher and lower halves of bigints. |
|
|
110
|
+
| [modes] | Find the values that appear most often. |
|
|
111
|
+
| [min] | Find the smallest bigint. |
|
|
112
|
+
| [max] | Find the largest bigint. |
|
|
113
|
+
| [range] | Find the minimum and maximum bigint. |
|
|
114
|
+
| [variance] | Find the mean of squared deviation of bigints from its mean. |
|
|
115
|
+
| | |
|
|
116
|
+
| [arithmeticMean] | Find the arithmetic mean of bigints (µ). |
|
|
117
|
+
| [geometricMean] | Find the geometric mean of bigints. |
|
|
118
|
+
| [harmonicMean] | Find the harmonic mean of bigints. |
|
|
119
|
+
| [quadriaticMean] | Find the quadriatic mean of bigints. |
|
|
120
|
+
| [cubicMean] | Find the cubic mean of bigints. |
|
|
121
|
+
|
|
122
|
+
<br>
|
|
123
|
+
<br>
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
[](https://wolfram77.github.io)<br>
|
|
127
|
+
[](https://nodef.github.io)
|
|
128
|
+

|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
[is]: https://jsr.io/@nodef/extra-bigint/doc/~/is
|
|
132
|
+
[compare]: https://jsr.io/@nodef/extra-bigint/doc/~/compare
|
|
133
|
+
[abs]: https://jsr.io/@nodef/extra-bigint/doc/~/abs
|
|
134
|
+
[sign]: https://jsr.io/@nodef/extra-bigint/doc/~/sign
|
|
135
|
+
[floorDiv]: https://jsr.io/@nodef/extra-bigint/doc/~/floorDiv
|
|
136
|
+
[ceilDiv]: https://jsr.io/@nodef/extra-bigint/doc/~/ceilDiv
|
|
137
|
+
[roundDiv]: https://jsr.io/@nodef/extra-bigint/doc/~/roundDiv
|
|
138
|
+
[rem]: https://jsr.io/@nodef/extra-bigint/doc/~/rem
|
|
139
|
+
[mod]: https://jsr.io/@nodef/extra-bigint/doc/~/mod
|
|
140
|
+
[modp]: https://jsr.io/@nodef/extra-bigint/doc/~/modp
|
|
141
|
+
[constrain]: https://jsr.io/@nodef/extra-bigint/doc/~/constrain
|
|
142
|
+
[remap]: https://jsr.io/@nodef/extra-bigint/doc/~/remap
|
|
143
|
+
[lerp]: https://jsr.io/@nodef/extra-bigint/doc/~/lerp
|
|
144
|
+
[isPow2]: https://jsr.io/@nodef/extra-bigint/doc/~/isPow2
|
|
145
|
+
[isPow10]: https://jsr.io/@nodef/extra-bigint/doc/~/isPow10
|
|
146
|
+
[prevPow2]: https://jsr.io/@nodef/extra-bigint/doc/~/prevPow2
|
|
147
|
+
[prevPow10]: https://jsr.io/@nodef/extra-bigint/doc/~/prevPow10
|
|
148
|
+
[nextPow2]: https://jsr.io/@nodef/extra-bigint/doc/~/nextPow2
|
|
149
|
+
[nextPow10]: https://jsr.io/@nodef/extra-bigint/doc/~/nextPow10
|
|
150
|
+
[log2]: https://jsr.io/@nodef/extra-bigint/doc/~/log2
|
|
151
|
+
[log10]: https://jsr.io/@nodef/extra-bigint/doc/~/log10
|
|
152
|
+
[sqrt]: https://jsr.io/@nodef/extra-bigint/doc/~/sqrt
|
|
153
|
+
[cbrt]: https://jsr.io/@nodef/extra-bigint/doc/~/cbrt
|
|
154
|
+
[root]: https://jsr.io/@nodef/extra-bigint/doc/~/root
|
|
155
|
+
[properDivisors]: https://jsr.io/@nodef/extra-bigint/doc/~/properDivisors
|
|
156
|
+
[aliquotSum]: https://jsr.io/@nodef/extra-bigint/doc/~/aliquotSum
|
|
157
|
+
[minPrimeFactor]: https://jsr.io/@nodef/extra-bigint/doc/~/minPrimeFactor
|
|
158
|
+
[maxPrimeFactor]: https://jsr.io/@nodef/extra-bigint/doc/~/maxPrimeFactor
|
|
159
|
+
[primeFactors]: https://jsr.io/@nodef/extra-bigint/doc/~/primeFactors
|
|
160
|
+
[primeExponentials]: https://jsr.io/@nodef/extra-bigint/doc/~/primeExponentials
|
|
161
|
+
[isPrime]: https://jsr.io/@nodef/extra-bigint/doc/~/isPrime
|
|
162
|
+
[gcd]: https://jsr.io/@nodef/extra-bigint/doc/~/gcd
|
|
163
|
+
[lcm]: https://jsr.io/@nodef/extra-bigint/doc/~/lcm
|
|
164
|
+
[factorial]: https://jsr.io/@nodef/extra-bigint/doc/~/factorial
|
|
165
|
+
[binomial]: https://jsr.io/@nodef/extra-bigint/doc/~/binomial
|
|
166
|
+
[multinomial]: https://jsr.io/@nodef/extra-bigint/doc/~/multinomial
|
|
167
|
+
[hypot]: https://jsr.io/@nodef/extra-bigint/doc/~/hypot
|
|
168
|
+
[sum]: https://jsr.io/@nodef/extra-bigint/doc/~/sum
|
|
169
|
+
[product]: https://jsr.io/@nodef/extra-bigint/doc/~/product
|
|
170
|
+
[median]: https://jsr.io/@nodef/extra-bigint/doc/~/median
|
|
171
|
+
[modes]: https://jsr.io/@nodef/extra-bigint/doc/~/modes
|
|
172
|
+
[min]: https://jsr.io/@nodef/extra-bigint/doc/~/min
|
|
173
|
+
[max]: https://jsr.io/@nodef/extra-bigint/doc/~/max
|
|
174
|
+
[range]: https://jsr.io/@nodef/extra-bigint/doc/~/range
|
|
175
|
+
[variance]: https://jsr.io/@nodef/extra-bigint/doc/~/variance
|
|
176
|
+
[arithmeticMean]: https://jsr.io/@nodef/extra-bigint/doc/~/arithmeticMean
|
|
177
|
+
[geometricMean]: https://jsr.io/@nodef/extra-bigint/doc/~/geometricMean
|
|
178
|
+
[harmonicMean]: https://jsr.io/@nodef/extra-bigint/doc/~/harmonicMean
|
|
179
|
+
[quadriaticMean]: https://jsr.io/@nodef/extra-bigint/doc/~/quadriaticMean
|
|
180
|
+
[cubicMean]: https://jsr.io/@nodef/extra-bigint/doc/~/cubicMean
|
package/deno.lock
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "5",
|
|
3
|
+
"specifiers": {
|
|
4
|
+
"jsr:@std/assert@^1.0.19": "1.0.19",
|
|
5
|
+
"jsr:@std/cli@^1.0.32": "1.0.32",
|
|
6
|
+
"jsr:@std/fmt@^1.0.10": "1.0.10",
|
|
7
|
+
"jsr:@std/internal@^1.0.12": "1.0.14",
|
|
8
|
+
"jsr:@std/internal@^1.0.14": "1.0.14"
|
|
9
|
+
},
|
|
10
|
+
"jsr": {
|
|
11
|
+
"@std/assert@1.0.19": {
|
|
12
|
+
"integrity": "eaada96ee120cb980bc47e040f82814d786fe8162ecc53c91d8df60b8755991e",
|
|
13
|
+
"dependencies": [
|
|
14
|
+
"jsr:@std/internal@^1.0.12"
|
|
15
|
+
]
|
|
16
|
+
},
|
|
17
|
+
"@std/cli@1.0.32": {
|
|
18
|
+
"integrity": "188b3a100d6202d64e3f5bd3d799c7fa4f6d77f92cc65eb7f641c1fa0aa92a66",
|
|
19
|
+
"dependencies": [
|
|
20
|
+
"jsr:@std/fmt",
|
|
21
|
+
"jsr:@std/internal@^1.0.14"
|
|
22
|
+
]
|
|
23
|
+
},
|
|
24
|
+
"@std/fmt@1.0.10": {
|
|
25
|
+
"integrity": "90dfba288802ac6de82fb31d0917eb9e4450b9925b954d5e51fc29ac07419db5"
|
|
26
|
+
},
|
|
27
|
+
"@std/internal@1.0.14": {
|
|
28
|
+
"integrity": "291516b3d4c35024d6ffbc0a9df5bf4c64116e05b50012cf846710152d2ffdf7"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"workspace": {
|
|
32
|
+
"dependencies": [
|
|
33
|
+
"jsr:@std/assert@^1.0.19",
|
|
34
|
+
"jsr:@std/cli@^1.0.32"
|
|
35
|
+
]
|
|
36
|
+
}
|
|
37
|
+
}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if value is a bigint.
|
|
3
|
+
* @param x a value
|
|
4
|
+
* @returns is bigint?
|
|
5
|
+
*/ export declare function is(x: unknown): x is bigint;
|
|
6
|
+
/**
|
|
7
|
+
* Compare two bigints.
|
|
8
|
+
* @param x a bigint
|
|
9
|
+
* @param y another bigint
|
|
10
|
+
* @returns x<y: -ve, x=y: 0, x>y: +ve
|
|
11
|
+
*/ export declare function compare(x: bigint, y: bigint): number;
|
|
12
|
+
/**
|
|
13
|
+
* Get the absolute of a bigint.
|
|
14
|
+
* @param x a bigint
|
|
15
|
+
* @returns |x|
|
|
16
|
+
*/ export declare function abs(x: bigint): bigint;
|
|
17
|
+
/**
|
|
18
|
+
* Get the sign of a bigint.
|
|
19
|
+
* @param x a bigint
|
|
20
|
+
* @returns x>0: 1n, x<0: -1n, x=0: 0n
|
|
21
|
+
*/ export declare function sign(x: bigint): bigint;
|
|
22
|
+
/**
|
|
23
|
+
* Perform floor-divison of two bigints (\\).
|
|
24
|
+
* @param x dividend
|
|
25
|
+
* @param y divisor
|
|
26
|
+
* @returns ⌊x/y⌋
|
|
27
|
+
*/ export declare function floorDiv(x: bigint, y: bigint): bigint;
|
|
28
|
+
/**
|
|
29
|
+
* Perform ceiling-divison of two bigints.
|
|
30
|
+
* @param x dividend
|
|
31
|
+
* @param y divisor
|
|
32
|
+
* @returns ⌈x/y⌉
|
|
33
|
+
*/ export declare function ceilDiv(x: bigint, y: bigint): bigint;
|
|
34
|
+
/**
|
|
35
|
+
* Perform rounded-divison of two bigints.
|
|
36
|
+
* @param x divisor
|
|
37
|
+
* @param y dividend
|
|
38
|
+
* @returns [x/y]
|
|
39
|
+
*/ export declare function roundDiv(x: bigint, y: bigint): bigint;
|
|
40
|
+
/**
|
|
41
|
+
* Find the remainder of x/y with sign of x (truncated division).
|
|
42
|
+
* @param x dividend
|
|
43
|
+
* @param y divisor
|
|
44
|
+
* @returns trunc(x % y)
|
|
45
|
+
*/ export declare function rem(x: bigint, y: bigint): bigint;
|
|
46
|
+
/**
|
|
47
|
+
* Find the remainder of x/y with sign of y (floored division).
|
|
48
|
+
* @param x dividend
|
|
49
|
+
* @param y divisor
|
|
50
|
+
* @returns floor(x % y)
|
|
51
|
+
*/ export declare function mod(x: bigint, y: bigint): bigint;
|
|
52
|
+
/**
|
|
53
|
+
* Find the remainder of x/y with +ve sign (euclidean division).
|
|
54
|
+
* @param x dividend
|
|
55
|
+
* @param y divisor
|
|
56
|
+
* @returns x/y>0: floor(x % y), x/y<0: ceil(x % y)
|
|
57
|
+
*/ export declare function modp(x: bigint, y: bigint): bigint;
|
|
58
|
+
/**
|
|
59
|
+
* Constrain a bigint within a minimum and a maximum value.
|
|
60
|
+
* @param x a bigint
|
|
61
|
+
* @param minv minimum value
|
|
62
|
+
* @param maxv maximum value
|
|
63
|
+
* @returns x<min: min, x>max: max, x
|
|
64
|
+
*/ export declare function constrain(x: bigint, minv: bigint, maxv: bigint): bigint;
|
|
65
|
+
export { constrain as clamp };
|
|
66
|
+
/**
|
|
67
|
+
* Re-map a bigint from one range to another.
|
|
68
|
+
* @param x a bigint
|
|
69
|
+
* @param r lower bound of current range
|
|
70
|
+
* @param R upper bound of current range
|
|
71
|
+
* @param t lower bound of target range
|
|
72
|
+
* @param T upper bound of target range
|
|
73
|
+
* @returns ∈ [ymin, ymax]
|
|
74
|
+
*/ export declare function remap(x: bigint, r: bigint, R: bigint, t: bigint, T: bigint): bigint;
|
|
75
|
+
export { remap as map };
|
|
76
|
+
/**
|
|
77
|
+
* Linearly interpolate a bigint between two bigints.
|
|
78
|
+
* @param x start bigint
|
|
79
|
+
* @param y stop bigint
|
|
80
|
+
* @param t interpolant ∈ [0, 1]
|
|
81
|
+
* @returns ∈ [x, y]
|
|
82
|
+
*/ export declare function lerp(x: bigint, y: bigint, t: number): bigint;
|
|
83
|
+
/**
|
|
84
|
+
* Check if bigint is a power-of-2.
|
|
85
|
+
* @param x a bigint
|
|
86
|
+
* @returns 2ⁱ = x? | i = +ve integer
|
|
87
|
+
*/ export declare function isPow2(x: bigint): boolean;
|
|
88
|
+
/**
|
|
89
|
+
* Check if bigint is a power-of-10.
|
|
90
|
+
* @param x a bigint
|
|
91
|
+
* @returns 10ⁱ = x? | i = +ve integer
|
|
92
|
+
*/ export declare function isPow10(x: bigint): boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Find largest power-of-2 less than or equal to given bigint.
|
|
95
|
+
* @param x a bigint
|
|
96
|
+
* @returns 2ⁱ | 2ⁱ ≤ x and 2ⁱ > x/2
|
|
97
|
+
*/ export declare function prevPow2(x: bigint): bigint;
|
|
98
|
+
/**
|
|
99
|
+
* Find largest power-of-10 less than or equal to given bigint.
|
|
100
|
+
* @param x a bigint
|
|
101
|
+
* @returns 10ⁱ | 10ⁱ ≤ x and 10ⁱ > x/10
|
|
102
|
+
*/ export declare function prevPow10(x: bigint): bigint;
|
|
103
|
+
/**
|
|
104
|
+
* Find smallest power-of-2 greater than or equal to given bigint.
|
|
105
|
+
* @param x a bigint
|
|
106
|
+
* @returns 2ⁱ | 2ⁱ ≥ x and 2ⁱ < 2x
|
|
107
|
+
*/ export declare function nextPow2(x: bigint): bigint;
|
|
108
|
+
/**
|
|
109
|
+
* Find smallest power-of-10 greater than or equal to given bigint.
|
|
110
|
+
* @param x a bigint
|
|
111
|
+
* @returns 10ⁱ | 10ⁱ ≥ x and 10ⁱ < 10x
|
|
112
|
+
*/ export declare function nextPow10(x: bigint): bigint;
|
|
113
|
+
/**
|
|
114
|
+
* Find the base-2 logarithm of a bigint.
|
|
115
|
+
* @param x a bigint
|
|
116
|
+
* @returns log₂(x)
|
|
117
|
+
*/ export declare function log2(x: bigint): bigint;
|
|
118
|
+
/**
|
|
119
|
+
* Find the base-10 logarithm of a bigint.
|
|
120
|
+
* @param x a bigint
|
|
121
|
+
* @returns log₁₀(x)
|
|
122
|
+
*/ export declare function log10(x: bigint): bigint;
|
|
123
|
+
/**
|
|
124
|
+
* Find the square root of a bigint.
|
|
125
|
+
* @param x a bigint
|
|
126
|
+
* @returns √x
|
|
127
|
+
*/ export declare function sqrt(x: bigint): bigint | null;
|
|
128
|
+
/**
|
|
129
|
+
* Find the cube root of a bigint.
|
|
130
|
+
* @param x a bigint
|
|
131
|
+
* @returns ³√x
|
|
132
|
+
*/ export declare function cbrt(x: bigint): bigint | null;
|
|
133
|
+
/**
|
|
134
|
+
* Find the nth root of a bigint.
|
|
135
|
+
* @param x a bigint
|
|
136
|
+
* @param n nth root (1n)
|
|
137
|
+
* @returns ⁿ√x
|
|
138
|
+
*/ export declare function root(x: bigint, n?: bigint): bigint | null;
|
|
139
|
+
/**
|
|
140
|
+
* List all divisors of a bigint, except itself.
|
|
141
|
+
* @param x a bigint
|
|
142
|
+
* @returns proper divisors (factors)
|
|
143
|
+
*/ export declare function properDivisors(x: bigint): bigint[];
|
|
144
|
+
export { properDivisors as aliquotParts };
|
|
145
|
+
/**
|
|
146
|
+
* Sum all proper divisors of a bigint.
|
|
147
|
+
* @param x a bigint
|
|
148
|
+
* @returns Σdᵢ | dᵢ is a divisor of x and ≠x
|
|
149
|
+
*/ export declare function aliquotSum(x: bigint): bigint;
|
|
150
|
+
/**
|
|
151
|
+
* Find the least prime number which divides a bigint.
|
|
152
|
+
* @param x a bigint
|
|
153
|
+
* @returns least prime factor
|
|
154
|
+
*/ export declare function minPrimeFactor(x: bigint): bigint;
|
|
155
|
+
export { minPrimeFactor as leastPrimeFactor };
|
|
156
|
+
/**
|
|
157
|
+
* Find the greatest prime number which divides a bigint.
|
|
158
|
+
* @param x a bigint
|
|
159
|
+
* @returns greatest prime factor
|
|
160
|
+
*/ export declare function maxPrimeFactor(x: bigint): bigint;
|
|
161
|
+
export { maxPrimeFactor as greatestPrimeFactor };
|
|
162
|
+
/**
|
|
163
|
+
* Find the prime factors of a bigint.
|
|
164
|
+
* @param x a bigint
|
|
165
|
+
* @returns [f₀, f₁, ...] | fᵢ divides x and is prime
|
|
166
|
+
*/ export declare function primeFactors(x: bigint): bigint[];
|
|
167
|
+
/**
|
|
168
|
+
* Find the prime factors and respective exponents of a bigint.
|
|
169
|
+
* @param x a bigint
|
|
170
|
+
* @returns [[f₀, e₀], [f₁, e₁], ...] | fᵢ is a prime factor of x and eᵢ is its exponent
|
|
171
|
+
*/ export declare function primeExponentials(x: bigint): [bigint, bigint][];
|
|
172
|
+
/**
|
|
173
|
+
* Check if bigint is prime.
|
|
174
|
+
* @param x a bigint
|
|
175
|
+
* @returns is divisible by 1n and itself only?
|
|
176
|
+
*/ export declare function isPrime(x: bigint): boolean;
|
|
177
|
+
/**
|
|
178
|
+
* Find the greatest common divisor of bigints.
|
|
179
|
+
* @param xs a list of bigints
|
|
180
|
+
* @returns gcd(x₁, x₂, ...)
|
|
181
|
+
*/ export declare function gcd(...xs: bigint[]): bigint;
|
|
182
|
+
export { gcd as hcf };
|
|
183
|
+
/**
|
|
184
|
+
* Find the least common multiple of bigints.
|
|
185
|
+
* @param xs a list of bigints
|
|
186
|
+
* @returns lcm(x₁, x₂, ...)
|
|
187
|
+
*/ export declare function lcm(...xs: bigint[]): bigint;
|
|
188
|
+
/**
|
|
189
|
+
* Find the factorial of a bigint.
|
|
190
|
+
* @param n a bigint
|
|
191
|
+
* @param k denominator factorial [0]
|
|
192
|
+
* @returns P(n, k); k=0: n!, k>0: n!/k!
|
|
193
|
+
*/ export declare function factorial(n: bigint, k?: bigint): bigint;
|
|
194
|
+
/**
|
|
195
|
+
* Find the number of ways to choose k elements from a set of n elements.
|
|
196
|
+
* @param n elements in source set
|
|
197
|
+
* @param k elements in choose set
|
|
198
|
+
* @returns C(n, k)
|
|
199
|
+
*/ export declare function binomial(n: bigint, k: bigint): bigint;
|
|
200
|
+
/**
|
|
201
|
+
* Find the number of ways to put n objects in m bins (n=sum(kᵢ)).
|
|
202
|
+
* @param ks objects per bin (kᵢ)
|
|
203
|
+
* @returns n!/(k₁!k₂!...) | n=sum(kᵢ)
|
|
204
|
+
*/ export declare function multinomial(...ks: bigint[]): bigint;
|
|
205
|
+
/**
|
|
206
|
+
* Find the length of hypotenuse.
|
|
207
|
+
* @param xs lengths of perpendicular sides (x, y, z, ...)
|
|
208
|
+
* @returns √(x² + y² + z²)
|
|
209
|
+
*/ export declare function hypot(...xs: bigint[]): bigint;
|
|
210
|
+
/**
|
|
211
|
+
* Find the sum of bigints (Σ).
|
|
212
|
+
* @param xs bigints
|
|
213
|
+
* @returns Σxᵢ
|
|
214
|
+
*/ export declare function sum(...xs: bigint[]): bigint;
|
|
215
|
+
/**
|
|
216
|
+
* Find the product of bigints (∏).
|
|
217
|
+
* @param xs bigints
|
|
218
|
+
* @returns ∏xᵢ
|
|
219
|
+
*/ export declare function product(...xs: bigint[]): bigint;
|
|
220
|
+
/**
|
|
221
|
+
* Find the value separating the higher and lower halves of bigints.
|
|
222
|
+
* @param xs a list of bigints
|
|
223
|
+
* @returns xₘ | sort(xs) = [..., xₘ, ...]
|
|
224
|
+
*/ export declare function median(...xs: bigint[]): bigint;
|
|
225
|
+
/**
|
|
226
|
+
* Find the values that appear most often.
|
|
227
|
+
* @param xs a list of bigints
|
|
228
|
+
* @returns [xₘ₁, xₘ₂, ...] | count(xₘᵢ) ≥ count(xᵢ) ∀ xᵢ ∈ xs
|
|
229
|
+
*/ export declare function modes(...xs: bigint[]): bigint[];
|
|
230
|
+
/**
|
|
231
|
+
* Find the smallest bigint.
|
|
232
|
+
* @param xs bigints
|
|
233
|
+
* @returns min(xs)
|
|
234
|
+
*/ export declare function min(...xs: bigint[]): bigint;
|
|
235
|
+
/**
|
|
236
|
+
* Find the largest bigint.
|
|
237
|
+
* @param xs bigints
|
|
238
|
+
* @returns max(xs)
|
|
239
|
+
*/ export declare function max(...xs: bigint[]): bigint;
|
|
240
|
+
/**
|
|
241
|
+
* Find the minimum and maximum bigint.
|
|
242
|
+
* @param xs bigints
|
|
243
|
+
* @returns [min, max]
|
|
244
|
+
*/ export declare function range(...xs: bigint[]): [bigint, bigint];
|
|
245
|
+
/**
|
|
246
|
+
* Find the mean of squared deviation of bigints from its mean.
|
|
247
|
+
* @param xs a list of bigints
|
|
248
|
+
* @returns σ² = E[(xs - µ)²] | µ = mean(xs)
|
|
249
|
+
*/ export declare function variance(...xs: bigint[]): bigint;
|
|
250
|
+
/**
|
|
251
|
+
* Find the arithmetic mean of bigints (µ).
|
|
252
|
+
* @param xs bigints
|
|
253
|
+
* @returns µ = (Σxᵢ)/n | n = size(xs)
|
|
254
|
+
*/ export declare function arithmeticMean(...xs: bigint[]): bigint;
|
|
255
|
+
export { arithmeticMean as mean };
|
|
256
|
+
/**
|
|
257
|
+
* Find the geometric mean of bigints.
|
|
258
|
+
* @param xs bigints
|
|
259
|
+
* @returns ⁿ√(∏xᵢ) | n = size(xs)
|
|
260
|
+
*/ export declare function geometricMean(...xs: bigint[]): bigint | null;
|
|
261
|
+
/**
|
|
262
|
+
* Find the harmonic mean of bigints.
|
|
263
|
+
* @param xs bigints
|
|
264
|
+
* @returns n/Σ(1/xᵢ) | n = size(xs)
|
|
265
|
+
*/ export declare function harmonicMean(...xs: bigint[]): bigint;
|
|
266
|
+
/**
|
|
267
|
+
* Find the quadriatic mean of bigints.
|
|
268
|
+
* @param xs bigints
|
|
269
|
+
* @returns √(Σxᵢ²)/n | n = size(xs)
|
|
270
|
+
*/ export declare function quadriaticMean(...xs: bigint[]): bigint;
|
|
271
|
+
export { quadriaticMean as rootMeanSquare };
|
|
272
|
+
/**
|
|
273
|
+
* Find the cubic mean of bigints.
|
|
274
|
+
* @param xs bigints
|
|
275
|
+
* @returns ³√(Σxᵢ³)/n | n = size(xs)
|
|
276
|
+
*/ export declare function cubicMean(...xs: bigint[]): bigint | null;
|
package/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function $(n){return typeof n=="bigint"}function a(n,t){return Number(n-t)}function i(n){return n<0n?-n:n}function E(n){return n<0n?-1n:n>0n?1n:0n}function g(n,t){return t<0n&&(n=-n,t=-t),n>=0n?n/t:(n-t+1n)/t}function N(n,t){return t<0n&&(n=-n,t=-t),n>=0n?(n+t-1n)/t:n/t}function R(n,t){return t<0n&&(n=-n,t=-t),n>=0n?(n+t/2n)/t:(n-t/2n)/t}function T(n,t){return n%t}function j(n,t){return n-t*g(n,t)}function z(n,t){return n-i(t)*g(n,i(t))}function A(n,t,r){return v(F(n,t),r)}function C(n,t,r,e,o){return e+(n-t)*(o-e)/(r-t)}function G(n,t,r){return n+BigInt(Math.floor(r*Number(t-n)))}function H(n){return/^10*$/.test(n.toString(2))}function J(n){return/^10*$/.test(n.toString())}function K(n){if(n<1n)return 0n;let t=n.toString(2).length;return BigInt("0b1"+"0".repeat(t-1))}function L(n){if(n<1n)return 0n;let t=n.toString(10).length;return BigInt("1"+"0".repeat(t-1))}function O(n){if(n<=1n)return 1n;let t=(n-1n).toString(2).length;return BigInt("0b1"+"0".repeat(t))}function Q(n){if(n<=1n)return 1n;let t=(n-1n).toString(10).length;return BigInt("1"+"0".repeat(t))}function h(n){let t=n.toString(2).length-1;return n<=0n?0n:BigInt(t)}function U(n){let t=n.toString().length-1;return n<=0n?0n:BigInt(t)}function u(n){return n===0n?0n:n>0n?B(n):null}function B(n){let t=1n<<h(n)/2n+1n,r=1n+t;for(;t<r;)r=t,t=(r+n/r)/2n;return r}function d(n){return m(n,3n)}function m(n,t=1n){return n===0n?0n:n>0n?p(n,t):t%2n!==0n?-p(-n,t):null}function p(n,t){let r=1n<<h(n)/t+1n,e=1n+r,o=t-1n;if(r===2n)return 1n;for(;r<e;)e=r,r=(o*e+n/e**o)/t;return e}function V(n){n=i(n);let t=[];for(let r=1n;r<n;r++)n%r===0n&&t.push(r);return t}function W(n){n=i(n);let t=0n;for(let r=1n;r<n;r++)n%r===0n&&(t+=r);return t}function w(n){if(n=i(n),n<=1n)return 0n;if(n<=3n)return n;if(n%2n===0n)return 2n;if(n%3n===0n)return 3n;for(let t=6n,r=u(n)+1n;t<=r;t+=6n){if(n%(t-1n)===0n)return t-1n;if(n%(t+1n)===0n)return t+1n}return n}function X(n){n=i(n);let t=0n;if(n<=1n)return 0n;if(n<=3n)return n;for(;n%2n===0n;t=2n)n/=2n;for(;n%3n===0n;t=3n)n/=3n;for(let r=6n,e=u(n)+1n;n>1n&&r<=e;r+=6n){for(;n%(r-1n)==0n;t=r-1n)n/=r-1n;for(;n%(r+1n)==0n;t=r+1n)n/=r+1n}return n<=1n?t:n}function Y(n){n=i(n);let t=[];if(n<=1n)return[];if(n<=3n)return[n];n=f(t,n,2n),n=f(t,n,3n);for(let r=6n,e=u(n)+1n;n>1n&&r<=e;r+=6n)n=f(t,n,r-1n),n=f(t,n,r+1n);return n>1n&&t.push(n),t}function f(n,t,r){if(t%r!==0n)return t;do t/=r;while(t%r===0n);return n.push(r),t}function Z(n){n=i(n);let t=[];if(n<=1n)return[];if(n<=3n)return[[n,1n]];n=c(t,n,2n),n=c(t,n,3n);for(let r=6n,e=u(n)+1n;n>1n&&r<=e;r+=6n)n=c(t,n,r-1n),n=c(t,n,r+1n);return n>1n&&t.push([n,1n]),t}function c(n,t,r){if(t%r!==0n)return t;let e=0n;do t/=r,++e;while(t%r===0n);return n.push([r,e]),t}function _(n){return n!==0n&&w(n)===i(n)}function k(...n){let t=n.length?i(n[0]):1n;for(let r=1,e=n.length;r<e;r++)t=s(t,n[r]);return t}function s(n,t){for(n=i(n),t=i(t);t!==0n;){let r=t;t=n%t,n=r}return n}function y(...n){let t=n.length?i(n[0]):1n;for(let r=1,e=n.length;r<e;r++){if(t===0n||n[r]===0n)return 0n;t=i(t*n[r])/s(t,n[r])}return t}function x(n,t=0n){let r=1n;if(n<0n)return 0n;for(let e=t+1n;e<=n;e++)r*=e;return r}function M(n,t){if(t<0n)return 0n;if(n<0n)return(t%2n===0n?1n:-1n)*M(t-n-1n,t);if(t>n)return 0n;t=t>n-t?n-t:t;let r=1n,e=1n;for(let o=1n;o<=t;o++,n--)r*=n,e*=o;return r/e}function nn(...n){let t=I(...n),r=1n,e=1n;for(let o=0,l=0n,b=n.length;o<b;)l<=0n?l=n[o++]:(r*=t--,e*=l--);return r/e}function tn(...n){let t=0n;for(let r of n)t+=r*r;return u(t)}function I(...n){let t=0n;for(let r of n)t+=r;return t}function P(...n){let t=1n;for(let r of n)t*=r;return t}function rn(...n){if(n.length===0)return 0n;n.sort(a);let t=n.length>>1;return(n.length&1)===1?n[t]:(n[t-1]+n[t])/2n}function en(...n){n.sort(a);let t=S(n);return q(n,t)}function S(n){let t=Math.min(n.length,1),r=t;for(let e=1,o=n.length;e<o;e++)n[e-1]===n[e]?t++:(r=Math.max(r,t),t=1);return Math.max(r,t)}function q(n,t){let r=[];t--;for(let e=0,o=n.length-t;e<o;e++)n[e]===n[e+t]&&r.push(n[e+=t]);return r}function v(...n){if(n.length===0)return 0n;let t=n[0];for(let r of n)t=r<t?r:t;return t}function F(...n){if(n.length===0)return 0n;let t=n[0];for(let r of n)t=r>t?r:t;return t}function on(...n){if(n.length===0)return[0n,0n];let t=n[0],r=t;for(let e of n)t=e<t?e:t,r=e>r?e:r;return[t,r]}function un(...n){if(n.length===0)return 0n;let t=D(...n),r=0n;for(let e of n)r+=(e-t)**2n;return r/BigInt(n.length)}function D(...n){let t=BigInt(n.length);return I(...n)/t}function fn(...n){let t=BigInt(n.length);return m(P(...n),t)}function cn(...n){let t=BigInt(n.length),r=P(...n),e=0n;for(let o of n)e+=r/o;return t*r/e}function ln(...n){let t=BigInt(n.length),r=0n;for(let e of n)r+=e*e;return u(r/t)}function pn(...n){let t=BigInt(n.length),r=0n;for(let e of n)r+=e**3n;return d(r/t)}export{i as abs,V as aliquotParts,W as aliquotSum,D as arithmeticMean,M as binomial,d as cbrt,N as ceilDiv,A as clamp,a as compare,A as constrain,pn as cubicMean,x as factorial,g as floorDiv,k as gcd,fn as geometricMean,X as greatestPrimeFactor,cn as harmonicMean,k as hcf,tn as hypot,$ as is,J as isPow10,H as isPow2,_ as isPrime,y as lcm,w as leastPrimeFactor,G as lerp,U as log10,h as log2,C as map,F as max,X as maxPrimeFactor,D as mean,rn as median,v as min,w as minPrimeFactor,j as mod,en as modes,z as modp,nn as multinomial,Q as nextPow10,O as nextPow2,L as prevPow10,K as prevPow2,Z as primeExponentials,Y as primeFactors,P as product,V as properDivisors,ln as quadriaticMean,on as range,T as rem,C as remap,m as root,ln as rootMeanSquare,R as roundDiv,E as sign,u as sqrt,I as sum,un as variance};
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
package/index.js.map
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../index.ts"],
|
|
4
|
+
"sourcesContent": ["// METHODS\n// =======\n\n// ABOUT\n// -----\n\n/**\n * Check if value is a bigint.\n * @param x a value\n * @returns is bigint?\n */\nexport function is(x: unknown): x is bigint {\n return typeof x===\"bigint\";\n}\n\n\n\n\n// COMPARE\n// -------\n\n/**\n * Compare two bigints.\n * @param x a bigint\n * @param y another bigint\n * @returns x<y: -ve, x=y: 0, x>y: +ve\n */\nexport function compare(x: bigint, y: bigint): number {\n return Number(x-y);\n}\n\n\n\n\n// SIGN\n// ----\n\n/**\n * Get the absolute of a bigint.\n * @param x a bigint\n * @returns |x|\n */\nexport function abs(x: bigint): bigint {\n return x<0n? -x : x;\n}\n\n\n/**\n * Get the sign of a bigint.\n * @param x a bigint\n * @returns x>0: 1n, x<0: -1n, x=0: 0n\n */\nexport function sign(x: bigint): bigint {\n return x<0n? -1n : (x>0n? 1n : 0n);\n}\n\n\n\n\n// ROUNDED DIVISION\n// ----------------\n\n/**\n * Perform floor-divison of two bigints (\\\\).\n * @param x dividend\n * @param y divisor\n * @returns ⌊x/y⌋\n */\nexport function floorDiv(x: bigint, y: bigint): bigint {\n if (y<0n) { x = -x; y = -y; }\n return x>=0n? x/y : (x-y+1n)/y;\n}\n// - https://python-reference.readthedocs.io/en/latest/docs/operators/floor_division.html\n\n\n/**\n * Perform ceiling-divison of two bigints.\n * @param x dividend\n * @param y divisor\n * @returns ⌈x/y⌉\n */\nexport function ceilDiv(x: bigint, y: bigint): bigint {\n if (y<0n) { x = -x; y = -y; }\n return x>=0n? (x+y-1n)/y : x/y;\n}\n\n\n/**\n * Perform rounded-divison of two bigints.\n * @param x divisor\n * @param y dividend\n * @returns [x/y]\n */\nexport function roundDiv(x: bigint, y: bigint): bigint {\n if (y<0n) { x = -x; y = -y; }\n return x>=0n? (x+y/2n)/y : (x-y/2n)/y;\n}\n\n\n\n\n// MODULO\n// ------\n\n/**\n * Find the remainder of x/y with sign of x (truncated division).\n * @param x dividend\n * @param y divisor\n * @returns trunc(x % y)\n */\nexport function rem(x: bigint, y: bigint): bigint {\n return x % y;\n}\n// - https://en.wikipedia.org/wiki/Modulo_operation\n\n\n/**\n * Find the remainder of x/y with sign of y (floored division).\n * @param x dividend\n * @param y divisor\n * @returns floor(x % y)\n */\nexport function mod(x: bigint, y: bigint): bigint {\n return x - y*floorDiv(x, y);\n}\n// - https://en.wikipedia.org/wiki/Modulo_operation\n\n\n/**\n * Find the remainder of x/y with +ve sign (euclidean division).\n * @param x dividend\n * @param y divisor\n * @returns x/y>0: floor(x % y), x/y<0: ceil(x % y)\n */\nexport function modp(x: bigint, y: bigint): bigint {\n return x - abs(y)*floorDiv(x, abs(y));\n}\n// - https://en.wikipedia.org/wiki/Modulo_operation\n\n\n\n\n// RANGE CONTROL\n// -------------\n\n/**\n * Constrain a bigint within a minimum and a maximum value.\n * @param x a bigint\n * @param minv minimum value\n * @param maxv maximum value\n * @returns x<min: min, x>max: max, x\n */\nexport function constrain(x: bigint, minv: bigint, maxv: bigint): bigint {\n return min(max(x, minv), maxv);\n}\nexport {constrain as clamp};\n// - https://processing.org/reference/constrain_.html\n// - https://www.npmjs.com/package/clamp\n// - https://en.cppreference.com/w/cpp/algorithm/clamp\n// - https://dlang.org/library/std/algorithm/comparison/clamp.html\n// - https://www.rdocumentation.org/packages/raster/versions/3.0-12/topics/clamp\n// - https://docs.microsoft.com/en-us/dotnet/api/system.math.clamp?view=netcore-3.1\n// - https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-clamp\n// - https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/clamp.xhtml\n// - https://docs.unity3d.com/ScriptReference/Mathf.Clamp.html\n// - https://en.wikipedia.org/wiki/Clamping_(graphics)\n\n\n/**\n * Re-map a bigint from one range to another.\n * @param x a bigint\n * @param r lower bound of current range\n * @param R upper bound of current range\n * @param t lower bound of target range\n * @param T upper bound of target range\n * @returns ∈ [ymin, ymax]\n */\nexport function remap(x: bigint, r: bigint, R: bigint, t: bigint, T: bigint): bigint {\n return t + (x - r)*(T - t)/(R - r);\n}\nexport {remap as map};\n// - https://processing.org/reference/map_.html\n\n\n/**\n * Linearly interpolate a bigint between two bigints.\n * @param x start bigint\n * @param y stop bigint\n * @param t interpolant ∈ [0, 1]\n * @returns ∈ [x, y]\n */\nexport function lerp(x: bigint, y: bigint, t: number): bigint {\n return x + BigInt(Math.floor(t*Number(y - x)));\n}\n// - https://processing.org/reference/lerp_.html\n// - https://docs.unity3d.com/ScriptReference/Vector3.Lerp.html\n// - https://stackoverflow.com/questions/53970655/how-to-convert-bigint-to-number-in-javascript\n\n\n\n\n// POWER / LOGARITHM\n// -----------------\n\n/**\n * Check if bigint is a power-of-2.\n * @param x a bigint\n * @returns 2ⁱ = x? | i = +ve integer\n */\nexport function isPow2(x: bigint): boolean {\n return /^10*$/.test(x.toString(2));\n}\n\n\n/**\n * Check if bigint is a power-of-10.\n * @param x a bigint\n * @returns 10ⁱ = x? | i = +ve integer\n */\nexport function isPow10(x: bigint): boolean {\n return /^10*$/.test(x.toString());\n}\n\n\n/**\n * Find largest power-of-2 less than or equal to given bigint.\n * @param x a bigint\n * @returns 2ⁱ | 2ⁱ ≤ x and 2ⁱ > x/2\n */\nexport function prevPow2(x: bigint): bigint {\n if (x < 1n) return 0n;\n const n = x.toString(2).length;\n return BigInt(\"0b1\" + \"0\".repeat(n - 1));\n}\n\n\n/**\n * Find largest power-of-10 less than or equal to given bigint.\n * @param x a bigint\n * @returns 10ⁱ | 10ⁱ ≤ x and 10ⁱ > x/10\n */\nexport function prevPow10(x: bigint): bigint {\n if (x < 1n) return 0n;\n const n = x.toString(10).length;\n return BigInt(\"1\" + \"0\".repeat(n - 1));\n}\n\n\n/**\n * Find smallest power-of-2 greater than or equal to given bigint.\n * @param x a bigint\n * @returns 2ⁱ | 2ⁱ ≥ x and 2ⁱ < 2x\n */\nexport function nextPow2(x: bigint): bigint {\n if (x <= 1n) return 1n;\n const n = (x - 1n).toString(2).length;\n return BigInt(\"0b1\" + \"0\".repeat(n));\n}\n\n\n/**\n * Find smallest power-of-10 greater than or equal to given bigint.\n * @param x a bigint\n * @returns 10ⁱ | 10ⁱ ≥ x and 10ⁱ < 10x\n */\nexport function nextPow10(x: bigint): bigint {\n if (x <= 1n) return 1n;\n const n = (x - 1n).toString(10).length;\n return BigInt(\"1\" + \"0\".repeat(n));\n}\n\n\n/**\n * Find the base-2 logarithm of a bigint.\n * @param x a bigint\n * @returns log₂(x)\n */\nexport function log2(x: bigint): bigint {\n const n = x.toString(2).length - 1;\n return x<=0n? 0n : BigInt(n);\n}\n\n\n/**\n * Find the base-10 logarithm of a bigint.\n * @param x a bigint\n * @returns log₁₀(x)\n */\nexport function log10(x: bigint): bigint {\n const n = x.toString().length - 1;\n return x<=0n? 0n : BigInt(n);\n}\n\n\n// TODO: isPow() based on accelerated search\n// TODO: prevPow() based on accelerated search\n// TODO: nextPow() based on accelerated search\n// TODO: log() based on accelerated search\n\n\n\n\n// ROOT\n// ----\n\n/**\n * Find the square root of a bigint.\n * @param x a bigint\n * @returns √x\n */\nexport function sqrt(x: bigint): bigint | null {\n if (x===0n) return 0n;\n return x>0n? sqrtPos(x) : null;\n}\n\nfunction sqrtPos(x: bigint): bigint {\n let a = 1n << (log2(x)/2n + 1n); // initial guess\n let b = 1n + a;\n while (a<b) {\n b = a;\n a = (b + x/b)/2n;\n }\n return b;\n}\n\n\n/**\n * Find the cube root of a bigint.\n * @param x a bigint\n * @returns ³√x\n */\nexport function cbrt(x: bigint): bigint | null {\n return root(x, 3n);\n}\n\n\n/**\n * Find the nth root of a bigint.\n * @param x a bigint\n * @param n nth root (1n)\n * @returns ⁿ√x\n */\nexport function root(x: bigint, n: bigint=1n): bigint | null {\n if (x===0n) return 0n;\n else if (x>0n) return rootPos(x, n);\n return n % 2n!==0n? -rootPos(-x, n) : null;\n}\n\nfunction rootPos(x: bigint, n: bigint): bigint {\n let a = 1n << (log2(x)/n + 1n); // initial guess\n let b = 1n + a; const m = n - 1n;\n if (a===2n) return 1n;\n while (a<b) {\n b = a;\n a = (m*b + x/b**m)/n;\n }\n return b;\n}\n\n\n\n\n// DIVISORS\n// --------\n\n/**\n * List all divisors of a bigint, except itself.\n * @param x a bigint\n * @returns proper divisors (factors)\n */\nexport function properDivisors(x: bigint): bigint[] {\n x = abs(x); const a = [];\n for (let i=1n; i<x; i++)\n if (x % i===0n) a.push(i);\n return a;\n}\nexport {properDivisors as aliquotParts};\n// - https://mathworld.wolfram.com/ProperDivisor.html\n// - https://en.wikipedia.org/wiki/Divisor#Further_notions_and_facts\n\n\n/**\n * Sum all proper divisors of a bigint.\n * @param x a bigint\n * @returns Σdᵢ | dᵢ is a divisor of x and ≠x\n */\nexport function aliquotSum(x: bigint): bigint {\n x = abs(x); let a = 0n;\n for (let i=1n; i<x; i++)\n if (x % i===0n) a += i;\n return a;\n}\n\n\n/**\n * Find the least prime number which divides a bigint.\n * @param x a bigint\n * @returns least prime factor\n */\nexport function minPrimeFactor(x: bigint): bigint {\n x = abs(x);\n // 1. LPF of 2, 3 is the number itself.\n if (x<=1n) return 0n;\n if (x<=3n) return x;\n // 2. LPF for multiples of 2, 3.\n if (x % 2n===0n) return 2n;\n if (x % 3n===0n) return 3n;\n // 3. LPF can be 6k-1 or 6k+1.\n for (let i=6n, I=(sqrt(x) as bigint)+1n; i<=I; i+=6n) {\n if (x % (i-1n)===0n) return i-1n;\n if (x % (i+1n)===0n) return i+1n;\n }\n return x;\n}\nexport {minPrimeFactor as leastPrimeFactor};\n// - https://mathworld.wolfram.com/LeastPrimeFactor.html\n\n\n/**\n * Find the greatest prime number which divides a bigint.\n * @param x a bigint\n * @returns greatest prime factor\n */\nexport function maxPrimeFactor(x: bigint): bigint {\n x = abs(x); let a = 0n;\n // 1. GPF of 2, 3 is the number itself.\n if (x<=1n) return 0n;\n if (x<=3n) return x;\n // 2. Remove factors 2, 3.\n for (; x % 2n===0n; a=2n)\n x /= 2n;\n for (; x % 3n===0n; a=3n)\n x /= 3n;\n // 3. Remove factors 6k-1, 6k+1.\n for (let i=6n, I=(sqrt(x) as bigint)+1n; x>1n && i<=I; i+=6n) {\n for (; x % (i-1n)==0n; a=i-1n)\n x /= i-1n;\n for (; x % (i+1n)==0n; a=i+1n)\n x /= i+1n;\n }\n if (x<=1n) return a;\n return x;\n}\nexport {maxPrimeFactor as greatestPrimeFactor};\n// - https://mathworld.wolfram.com/GreatestPrimeFactor.html\n// - https://www.geeksforgeeks.org/find-largest-prime-factor-number/\n\n\n/**\n * Find the prime factors of a bigint.\n * @param x a bigint\n * @returns [f₀, f₁, ...] | fᵢ divides x and is prime\n */\nexport function primeFactors(x: bigint): bigint[] {\n x = abs(x); const a: bigint[] = [];\n if (x<=1n) return [];\n if (x<=3n) return [x];\n // 2. Try factors 2, 3.\n x = pushPrimeFactorTo$(a, x, 2n);\n x = pushPrimeFactorTo$(a, x, 3n);\n // 3. Try factors 6k-1, 6k+1.\n for (let i=6n, I=(sqrt(x) as bigint)+1n; x>1n && i<=I; i+=6n) {\n x = pushPrimeFactorTo$(a, x, i-1n);\n x = pushPrimeFactorTo$(a, x, i+1n);\n }\n if (x>1n) a.push(x);\n return a;\n}\n\nfunction pushPrimeFactorTo$(a: bigint[], x: bigint, f: bigint): bigint {\n if (x % f!==0n) return x;\n do {\n x /= f;\n } while (x % f===0n);\n a.push(f);\n return x;\n}\n// - https://www.geeksforgeeks.org/prime-factors-big-number/\n// - https://mathworld.wolfram.com/PrimeFactor.html\n\n\n/**\n * Find the prime factors and respective exponents of a bigint.\n * @param x a bigint\n * @returns [[f₀, e₀], [f₁, e₁], ...] | fᵢ is a prime factor of x and eᵢ is its exponent\n */\nexport function primeExponentials(x: bigint): [bigint, bigint][] {\n x = abs(x); const a: [bigint, bigint][] = [];\n if (x<=1n) return [];\n if (x<=3n) return [[x, 1n]];\n // 2. Try factors 2, 3.\n x = pushPrimeExponentialTo$(a, x, 2n);\n x = pushPrimeExponentialTo$(a, x, 3n);\n // 3. Try factors 6k-1, 6k+1.\n for (let i=6n, I=(sqrt(x) as bigint)+1n; x>1n && i<=I; i+=6n) {\n x = pushPrimeExponentialTo$(a, x, i-1n);\n x = pushPrimeExponentialTo$(a, x, i+1n);\n }\n if (x>1n) a.push([x, 1n]);\n return a;\n}\n\nfunction pushPrimeExponentialTo$(a: [bigint, bigint][], x: bigint, f: bigint): bigint {\n if (x % f!==0n) return x;\n let e = 0n;\n do {\n x /= f; ++e;\n } while (x % f===0n);\n a.push([f, e]);\n return x;\n}\n// - https://www.geeksforgeeks.org/prime-factors-big-number/\n// - https://reference.wolfram.com/language/ref/FactorInteger.html\n// - https://mathworld.wolfram.com/PrimeFactorization.html\n// - https://mathworld.wolfram.com/PrimeFactor.html\n\n\n/**\n * Check if bigint is prime.\n * @param x a bigint\n * @returns is divisible by 1n and itself only?\n */\nexport function isPrime(x: bigint): boolean {\n return x!==0n && minPrimeFactor(x) === abs(x);\n}\n\n\n/**\n * Find the greatest common divisor of bigints.\n * @param xs a list of bigints\n * @returns gcd(x₁, x₂, ...)\n */\nexport function gcd(...xs: bigint[]): bigint {\n let a = xs.length? abs(xs[0]) : 1n;\n for (let i = 1, I = xs.length; i < I; i++)\n a = gcdPair(a, xs[i]);\n return a;\n}\nexport {gcd as hcf};\n\n// Find the greatest common divisor of a pair of bigints.\nfunction gcdPair(x: bigint, y: bigint): bigint {\n x = abs(x);\n y = abs(y);\n while (y !== 0n) {\n const t = y;\n y = x % y;\n x = t;\n }\n return x;\n}\n// - https://lemire.me/blog/2013/12/26/fastest-way-to-compute-the-greatest-common-divisor/\n// - https://en.wikipedia.org/wiki/Euclidean_algorithm\n\n\n/**\n * Find the least common multiple of bigints.\n * @param xs a list of bigints\n * @returns lcm(x₁, x₂, ...)\n */\nexport function lcm(...xs: bigint[]): bigint {\n let a = xs.length? abs(xs[0]) : 1n;\n for (let i = 1, I = xs.length; i < I; i++) {\n if (a === 0n || xs[i] === 0n) return 0n;\n a = abs(a * xs[i]) / gcdPair(a, xs[i]);\n }\n return a;\n}\n// - https://en.wikipedia.org/wiki/Least_common_multiple\n\n\n\n\n// ARRANGEMENTS\n// ------------\n\n/**\n * Find the factorial of a bigint.\n * @param n a bigint\n * @param k denominator factorial [0]\n * @returns P(n, k); k=0: n!, k>0: n!/k!\n */\nexport function factorial(n: bigint, k: bigint=0n): bigint {\n let a = 1n;\n if (n<0n) return 0n;\n for (let i=k+1n; i<=n; i++)\n a *= i;\n return a;\n}\n// - https://github.com/alawatthe/MathLib/blob/master/src/Functn/functions/factorial.ts\n// - https://en.wikipedia.org/wiki/Permutation\n\n\n/**\n * Find the number of ways to choose k elements from a set of n elements.\n * @param n elements in source set\n * @param k elements in choose set\n * @returns C(n, k)\n */\nexport function binomial(n: bigint, k: bigint): bigint {\n if (k < 0n) return 0n;\n // Negative-integer generalization:\n // C(n, k) = (-1)^k * C(-n + k - 1, k)\n if (n < 0n) {\n const sign = k % 2n === 0n? 1n : -1n;\n return sign * binomial(k - n - 1n, k);\n }\n if (k > n) return 0n;\n // Take advantage of symmetry\n k = k > n - k? n - k : k;\n let a = 1n;\n let b = 1n;\n for (let i = 1n; i <= k; i++, n--) {\n a *= n;\n b *= i;\n }\n return a / b;\n}\n// - https://github.com/alawatthe/MathLib/blob/master/src/Functn/functions/binomial.ts\n// - https://en.wikipedia.org/wiki/Binomial_coefficient\n\n\n/**\n * Find the number of ways to put n objects in m bins (n=sum(kᵢ)).\n * @param ks objects per bin (kᵢ)\n * @returns n!/(k₁!k₂!...) | n=sum(kᵢ)\n */\nexport function multinomial(...ks: bigint[]): bigint {\n let n = sum(...ks), a = 1n, b = 1n;\n for (let i=0, j=0n, I=ks.length; i<I;) {\n if (j<=0n) j = ks[i++];\n else { a *= n--; b*= j--; }\n }\n return a/b;\n}\n// - https://en.wikipedia.org/wiki/Multinomial_distribution\n\n\n\n\n// GEOMETRY\n// --------\n\n/**\n * Find the length of hypotenuse.\n * @param xs lengths of perpendicular sides (x, y, z, ...)\n * @returns √(x² + y² + z²)\n */\nexport function hypot(...xs: bigint[]): bigint {\n let a = 0n;\n for (const x of xs)\n a += x*x;\n return sqrt(a) as bigint;\n}\n\n\n\n\n// STATISTICS\n// ----------\n\n/**\n * Find the sum of bigints (Σ).\n * @param xs bigints\n * @returns Σxᵢ\n */\nexport function sum(...xs: bigint[]): bigint {\n let a = 0n;\n for (const x of xs)\n a += x;\n return a;\n}\n\n\n/**\n * Find the product of bigints (∏).\n * @param xs bigints\n * @returns ∏xᵢ\n */\nexport function product(...xs: bigint[]): bigint {\n let a = 1n;\n for (const x of xs)\n a *= x;\n return a;\n}\n\n\n/**\n * Find the value separating the higher and lower halves of bigints.\n * @param xs a list of bigints\n * @returns xₘ | sort(xs) = [..., xₘ, ...]\n */\nexport function median(...xs: bigint[]): bigint {\n if (xs.length===0) return 0n;\n xs.sort(compare);\n const i = xs.length>>1;\n if ((xs.length & 1)===1) return xs[i];\n return (xs[i-1] + xs[i])/2n;\n}\n// - https://stackoverflow.com/questions/45309447/calculating-median-javascript\n// - https://en.wikipedia.org/wiki/Median\n\n\n/**\n * Find the values that appear most often.\n * @param xs a list of bigints\n * @returns [xₘ₁, xₘ₂, ...] | count(xₘᵢ) ≥ count(xᵢ) ∀ xᵢ ∈ xs\n */\nexport function modes(...xs: bigint[]): bigint[] {\n xs.sort(compare);\n const r = maxRepeat(xs);\n return getRepeats(xs, r);\n}\n// - https://en.wikipedia.org/wiki/Mode_(statistics)\n\n// Get the maximum number of times any bigint has repeated in a sorted array.\nfunction maxRepeat(xs: bigint[]): number {\n let count = Math.min(xs.length, 1), max = count;\n for (let i=1, I=xs.length; i<I; i++) {\n if (xs[i-1]===xs[i]) count++;\n else { max = Math.max(max, count); count = 1; }\n }\n return Math.max(max, count);\n}\n\n// Get the numbers which have been repeated atleast given number of times.\nfunction getRepeats(xs: bigint[], r: number): bigint[] {\n const a: bigint[] = []; r--;\n for (let i=0, I=xs.length-r; i<I; i++)\n if (xs[i]===xs[i+r]) a.push(xs[i+=r]);\n return a;\n}\n\n\n/**\n * Find the smallest bigint.\n * @param xs bigints\n * @returns min(xs)\n */\nexport function min(...xs: bigint[]): bigint {\n if (xs.length===0) return 0n;\n let a = xs[0];\n for (const x of xs)\n a = x<a? x : a;\n return a;\n}\n\n\n/**\n * Find the largest bigint.\n * @param xs bigints\n * @returns max(xs)\n */\nexport function max(...xs: bigint[]): bigint {\n if (xs.length===0) return 0n;\n let a = xs[0];\n for (const x of xs)\n a = x>a? x : a;\n return a;\n}\n\n\n/**\n * Find the minimum and maximum bigint.\n * @param xs bigints\n * @returns [min, max]\n */\nexport function range(...xs: bigint[]): [bigint, bigint] {\n if (xs.length===0) return [0n, 0n];\n let a = xs[0], b = a;\n for (const x of xs) {\n a = x<a? x : a;\n b = x>b? x : b;\n }\n return [a, b];\n}\n\n\n/**\n * Find the mean of squared deviation of bigints from its mean.\n * @param xs a list of bigints\n * @returns σ² = E[(xs - µ)²] | µ = mean(xs)\n */\nexport function variance(...xs: bigint[]): bigint {\n if (xs.length===0) return 0n;\n const m = arithmeticMean(...xs); let a = 0n;\n for (const x of xs)\n a += (x-m)**2n;\n return a/BigInt(xs.length);\n}\n// - https://en.wikipedia.org/wiki/Variance\n\n\n\n\n// MEAN (STATISTICS)\n// -----------------\n\n/**\n * Find the arithmetic mean of bigints (µ).\n * @param xs bigints\n * @returns µ = (Σxᵢ)/n | n = size(xs)\n */\nexport function arithmeticMean(...xs: bigint[]): bigint {\n const n = BigInt(xs.length);\n return sum(...xs)/n;\n}\nexport {arithmeticMean as mean};\n\n\n/**\n * Find the geometric mean of bigints.\n * @param xs bigints\n * @returns ⁿ√(∏xᵢ) | n = size(xs)\n */\nexport function geometricMean(...xs: bigint[]): bigint | null {\n const n = BigInt(xs.length);\n return root(product(...xs), n);\n}\n\n\n/**\n * Find the harmonic mean of bigints.\n * @param xs bigints\n * @returns n/Σ(1/xᵢ) | n = size(xs)\n */\nexport function harmonicMean(...xs: bigint[]): bigint {\n const n = BigInt(xs.length);\n const p = product(...xs); let q = 0n;\n for (const x of xs)\n q += p/x;\n return n*p/q;\n}\n\n\n/**\n * Find the quadriatic mean of bigints.\n * @param xs bigints\n * @returns √(Σxᵢ²)/n | n = size(xs)\n */\nexport function quadriaticMean(...xs: bigint[]): bigint {\n const n = BigInt(xs.length);\n let a = 0n;\n for (const x of xs)\n a += x*x;\n return sqrt(a/n) as bigint;\n}\nexport {quadriaticMean as rootMeanSquare};\n\n\n/**\n * Find the cubic mean of bigints.\n * @param xs bigints\n * @returns ³√(Σxᵢ³)/n | n = size(xs)\n */\nexport function cubicMean(...xs: bigint[]): bigint | null {\n const n = BigInt(xs.length);\n let a = 0n;\n for (const x of xs)\n a += x**3n;\n return cbrt(a/n);\n}\n"],
|
|
5
|
+
"mappings": "AAWO,SAASA,EAAGC,EAAU,CAC3B,OAAO,OAAOA,GAAI,QACpB,CAcO,SAASC,EAAQD,EAAWE,EAAS,CAC1C,OAAO,OAAOF,EAAEE,CAAA,CAClB,CAaO,SAASC,EAAIH,EAAS,CAC3B,OAAOA,EAAE,GAAI,CAACA,EAAIA,CACpB,CAQO,SAASI,EAAKJ,EAAS,CAC5B,OAAOA,EAAE,GAAI,CAAC,GAAMA,EAAE,GAAI,GAAK,EACjC,CAcO,SAASK,EAASL,EAAWE,EAAS,CAC3C,OAAIA,EAAE,KAAMF,EAAI,CAACA,EAAGE,EAAI,CAACA,GAClBF,GAAG,GAAIA,EAAEE,GAAKF,EAAEE,EAAE,IAAIA,CAC/B,CAUO,SAASI,EAAQN,EAAWE,EAAS,CAC1C,OAAIA,EAAE,KAAMF,EAAI,CAACA,EAAGE,EAAI,CAACA,GAClBF,GAAG,IAAKA,EAAEE,EAAE,IAAIA,EAAIF,EAAEE,CAC/B,CASO,SAASK,EAASP,EAAWE,EAAS,CAC3C,OAAIA,EAAE,KAAMF,EAAI,CAACA,EAAGE,EAAI,CAACA,GAClBF,GAAG,IAAKA,EAAEE,EAAE,IAAIA,GAAKF,EAAEE,EAAE,IAAIA,CACtC,CAcO,SAASM,EAAIR,EAAWE,EAAS,CACtC,OAAOF,EAAIE,CACb,CAUO,SAASO,EAAIT,EAAWE,EAAS,CACtC,OAAOF,EAAIE,EAAEG,EAASL,EAAGE,CAAA,CAC3B,CAUO,SAASQ,EAAKV,EAAWE,EAAS,CACvC,OAAOF,EAAIG,EAAID,CAAA,EAAGG,EAASL,EAAGG,EAAID,CAAA,CAA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AIU,CACpB,CASO,SAASmB,MAAiBC,EAAY,CAC3C,IAAMC,EAAI,OAAOD,EAAG,MAAM,EAC1B,OAAOE,EAAKC,EAAA,GAAWH,CAAA,EAAKC,CAAA,CAC9B,CAQO,SAASG,MAAgBJ,EAAY,CAC1C,IAAMC,EAAI,OAAOD,EAAG,MAAM,EACpBK,EAAIF,EAAA,GAAWH,CAAA,EAASM,EAAI,GAClC,QAAWC,KAAKP,EACdM,GAAKD,EAAEE,EACT,OAAON,EAAEI,EAAEC,CACb,CAQO,SAASE,MAAkBR,EAAY,CAC5C,IAAMC,EAAI,OAAOD,EAAG,MAAM,EACtBS,EAAI,GACR,QAAWF,KAAKP,EACdS,GAAKF,EAAEA,EACT,OAAOG,EAAKD,EAAER,CAAA,CAChB,CASO,SAASU,MAAaC,EAAY,CACvC,IAAMC,EAAI,OAAOD,EAAG,MAAM,EACtBE,EAAI,GACR,QAAWC,KAAKH,EACdE,GAAKC,GAAG,GACV,OAAOC,EAAKF,EAAED,CAAA,CAChB",
|
|
6
|
+
"names": ["is", "x", "compare", "y", "abs", "sign", "floorDiv", "ceilDiv", "roundDiv", "rem", "mod", "modp", "constrain", "minv", "maxv", "min", "max", "remap", "x", "r", "R", "t", "T", "lerp", "x", "y", "t", "isPow2", "isPow10", "prevPow2", "n", "prevPow10", "nextPow2", "nextPow10", "log2", "log10", "sqrt", "sqrtPos", "a", "b", "cbrt", "root", "rootPos", "m", "properDivisors", "abs", "i", "aliquotSum", "x", "abs", "a", "i", "minPrimeFactor", "I", "sqrt", "maxPrimeFactor", "x", "abs", "a", "i", "I", "sqrt", "primeFactors", "x", "abs", "a", "pushPrimeFactorTo$", "i", "I", "sqrt", "f", "primeExponentials", "pushPrimeExponentialTo$", "isPrime", "minPrimeFactor", "gcd", "xs", "gcdPair", "gcdPair", "x", "y", "abs", "t", "lcm", "xs", "a", "i", "I", "factorial", "k", "binomial", "b", "multinomial", "ks", "n", "sum", "j", "hypot", "sqrt", "product", "median", "compare", "modes", "r", "maxRepeat", "getRepeats", "count", "max", "min", "range", "variance", "m", "arithmeticMean", "geometricMean", "xs", "n", "root", "product", "harmonicMean", "p", "q", "x", "quadriaticMean", "a", "sqrt", "cubicMean", "xs", "n", "a", "x", "cbrt"]
|
|
7
|
+
}
|
package/index.test.ts
ADDED
|
@@ -0,0 +1,743 @@
|
|
|
1
|
+
import {assertEquals} from "@std/assert";
|
|
2
|
+
import * as xbigint from "./index.ts";
|
|
3
|
+
import {
|
|
4
|
+
is,
|
|
5
|
+
compare,
|
|
6
|
+
abs,
|
|
7
|
+
sign,
|
|
8
|
+
floorDiv,
|
|
9
|
+
ceilDiv,
|
|
10
|
+
roundDiv,
|
|
11
|
+
rem,
|
|
12
|
+
mod,
|
|
13
|
+
modp,
|
|
14
|
+
constrain,
|
|
15
|
+
remap,
|
|
16
|
+
lerp,
|
|
17
|
+
isPow2,
|
|
18
|
+
isPow10,
|
|
19
|
+
prevPow2,
|
|
20
|
+
prevPow10,
|
|
21
|
+
nextPow2,
|
|
22
|
+
nextPow10,
|
|
23
|
+
log2,
|
|
24
|
+
log10,
|
|
25
|
+
sqrt,
|
|
26
|
+
cbrt,
|
|
27
|
+
root,
|
|
28
|
+
properDivisors,
|
|
29
|
+
aliquotSum,
|
|
30
|
+
minPrimeFactor,
|
|
31
|
+
maxPrimeFactor,
|
|
32
|
+
primeFactors,
|
|
33
|
+
primeExponentials,
|
|
34
|
+
isPrime,
|
|
35
|
+
gcd,
|
|
36
|
+
lcm,
|
|
37
|
+
factorial,
|
|
38
|
+
binomial,
|
|
39
|
+
multinomial,
|
|
40
|
+
hypot,
|
|
41
|
+
sum,
|
|
42
|
+
product,
|
|
43
|
+
median,
|
|
44
|
+
modes,
|
|
45
|
+
min,
|
|
46
|
+
max,
|
|
47
|
+
range,
|
|
48
|
+
variance,
|
|
49
|
+
arithmeticMean,
|
|
50
|
+
geometricMean,
|
|
51
|
+
harmonicMean,
|
|
52
|
+
quadriaticMean,
|
|
53
|
+
cubicMean,
|
|
54
|
+
} from "./index.ts";
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
Deno.test("example1", () => {
|
|
60
|
+
const b = xbigint.isPrime(113n);
|
|
61
|
+
assertEquals(b, true);
|
|
62
|
+
// → true
|
|
63
|
+
|
|
64
|
+
let a;
|
|
65
|
+
a = xbigint.floorDiv(7n, 3n);
|
|
66
|
+
assertEquals(a, 2n);
|
|
67
|
+
// → 2n
|
|
68
|
+
|
|
69
|
+
a = xbigint.sqrt(81n);
|
|
70
|
+
assertEquals(a, 9n);
|
|
71
|
+
// → 9n
|
|
72
|
+
|
|
73
|
+
a = xbigint.lcm(2n, 3n, 4n);
|
|
74
|
+
assertEquals(a, 12n);
|
|
75
|
+
// → 12n
|
|
76
|
+
|
|
77
|
+
a = xbigint.log2(8n);
|
|
78
|
+
assertEquals(a, 3n);
|
|
79
|
+
// → 3n
|
|
80
|
+
|
|
81
|
+
a = xbigint.sum(1n, 2n, 3n, 4n);
|
|
82
|
+
assertEquals(a, 10n);
|
|
83
|
+
// → 10n
|
|
84
|
+
|
|
85
|
+
a = xbigint.mean(1n, 7n, 8n);
|
|
86
|
+
assertEquals(a, 5n);
|
|
87
|
+
// → 5n
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
// ABOUT
|
|
94
|
+
// -----
|
|
95
|
+
|
|
96
|
+
Deno.test("is", () => {
|
|
97
|
+
let a;
|
|
98
|
+
a = is(314n);
|
|
99
|
+
assertEquals(a, true);
|
|
100
|
+
a = is(-707n);
|
|
101
|
+
assertEquals(a, true);
|
|
102
|
+
a = is("314n");
|
|
103
|
+
assertEquals(a, false);
|
|
104
|
+
a = is({"value": 314n});
|
|
105
|
+
assertEquals(a, false);
|
|
106
|
+
a = is(null);
|
|
107
|
+
assertEquals(a, false);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
// COMPARE
|
|
114
|
+
// -------
|
|
115
|
+
|
|
116
|
+
Deno.test("compare", () => {
|
|
117
|
+
let a;
|
|
118
|
+
a = compare(10n, 12n);
|
|
119
|
+
assertEquals(a, -2);
|
|
120
|
+
a = compare(12n, 12n);
|
|
121
|
+
assertEquals(a, 0);
|
|
122
|
+
a = compare(17n, 12n);
|
|
123
|
+
assertEquals(a, 5);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
// SIGN
|
|
130
|
+
// ----
|
|
131
|
+
|
|
132
|
+
Deno.test("abs", () => {
|
|
133
|
+
let a;
|
|
134
|
+
a = abs(-2n);
|
|
135
|
+
assertEquals(a, 2n);
|
|
136
|
+
a = abs(0n);
|
|
137
|
+
assertEquals(a, 0n);
|
|
138
|
+
a = abs(5n);
|
|
139
|
+
assertEquals(a, 5n);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
Deno.test("sign", () => {
|
|
144
|
+
let a;
|
|
145
|
+
a = sign(-2n);
|
|
146
|
+
assertEquals(a, -1n);
|
|
147
|
+
a = sign(0n);
|
|
148
|
+
assertEquals(a, 0n);
|
|
149
|
+
a = sign(5n);
|
|
150
|
+
assertEquals(a, 1n);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
// ROUNDED DIVISION
|
|
157
|
+
// ----------------
|
|
158
|
+
|
|
159
|
+
Deno.test("floorDiv", () => {
|
|
160
|
+
let a;
|
|
161
|
+
a = floorDiv(15n, 4n);
|
|
162
|
+
assertEquals(a, 3n);
|
|
163
|
+
a = floorDiv(2n, 2n);
|
|
164
|
+
assertEquals(a, 1n);
|
|
165
|
+
a = floorDiv(-15n, 4n);
|
|
166
|
+
assertEquals(a, -4n);
|
|
167
|
+
});
|
|
168
|
+
// - https://www.learndatasci.com/solutions/python-double-slash-operator-floor-division/
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
Deno.test("ceilDiv", () => {
|
|
172
|
+
let a;
|
|
173
|
+
a = ceilDiv(15n, 4n);
|
|
174
|
+
assertEquals(a, 4n);
|
|
175
|
+
a = ceilDiv(2n, 2n);
|
|
176
|
+
assertEquals(a, 1n);
|
|
177
|
+
a = ceilDiv(-15n, 4n);
|
|
178
|
+
assertEquals(a, -3n);
|
|
179
|
+
});
|
|
180
|
+
// - https://www.learndatasci.com/solutions/python-double-slash-operator-floor-division/
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
Deno.test("roundDiv", () => {
|
|
184
|
+
let a;
|
|
185
|
+
a = roundDiv(15n, 4n);
|
|
186
|
+
assertEquals(a, 4n);
|
|
187
|
+
a = roundDiv(2n, 2n);
|
|
188
|
+
assertEquals(a, 1n);
|
|
189
|
+
a = roundDiv(-15n, 4n);
|
|
190
|
+
assertEquals(a, -4n);
|
|
191
|
+
});
|
|
192
|
+
// - https://www.learndatasci.com/solutions/python-double-slash-operator-floor-division/
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
// MODULO
|
|
198
|
+
// ------
|
|
199
|
+
|
|
200
|
+
Deno.test("rem", () => {
|
|
201
|
+
let a;
|
|
202
|
+
a = rem(1n, 10n);
|
|
203
|
+
assertEquals(a, 1n);
|
|
204
|
+
a = rem(-1n, 10n);
|
|
205
|
+
assertEquals(a, -1n);
|
|
206
|
+
a = rem(1n, -10n);
|
|
207
|
+
assertEquals(a, 1n);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
Deno.test("mod", () => {
|
|
212
|
+
let a;
|
|
213
|
+
a = mod(1n, 10n);
|
|
214
|
+
assertEquals(a, 1n);
|
|
215
|
+
a = mod(-1n, 10n);
|
|
216
|
+
assertEquals(a, 9n);
|
|
217
|
+
a = mod(1n, -10n);
|
|
218
|
+
assertEquals(a, -9n);
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
Deno.test("modp", () => {
|
|
223
|
+
let a;
|
|
224
|
+
a = modp(1n, 10n);
|
|
225
|
+
assertEquals(a, 1n);
|
|
226
|
+
a = modp(-1n, 10n);
|
|
227
|
+
assertEquals(a, 9n);
|
|
228
|
+
a = modp(1n, -10n);
|
|
229
|
+
assertEquals(a, 1n);
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
// RANGE CONTROL
|
|
236
|
+
// -------------
|
|
237
|
+
|
|
238
|
+
Deno.test("constrain", () => {
|
|
239
|
+
let a;
|
|
240
|
+
a = constrain(20n, 0n, 50n);
|
|
241
|
+
assertEquals(a, 20n);
|
|
242
|
+
a = constrain(-10n, 0n, 100n);
|
|
243
|
+
assertEquals(a, 0n);
|
|
244
|
+
a = constrain(120n, 0n, 100n);
|
|
245
|
+
assertEquals(a, 100n);
|
|
246
|
+
});
|
|
247
|
+
// - https://processing.org/reference/norm_.html
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
Deno.test("remap", () => {
|
|
251
|
+
let a;
|
|
252
|
+
a = remap(25n, 0n, 100n, 0n, 1366n);
|
|
253
|
+
assertEquals(a, 341n);
|
|
254
|
+
a = remap(110n, 0n, 100n, -20n, -10n);
|
|
255
|
+
assertEquals(a, -9n);
|
|
256
|
+
});
|
|
257
|
+
// - https://processing.org/reference/map_.html
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
Deno.test("lerp", () => {
|
|
261
|
+
let a;
|
|
262
|
+
a = lerp(80n, 320n, 0.8);
|
|
263
|
+
assertEquals(a, 272n);
|
|
264
|
+
a = lerp(80n, 320n, 0.20);
|
|
265
|
+
assertEquals(a, 128n);
|
|
266
|
+
a = lerp(80n, 320n, 0.32);
|
|
267
|
+
assertEquals(a, 156n);
|
|
268
|
+
});
|
|
269
|
+
// - https://processing.org/reference/lerp_.html
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
// POWER / LOGARITHM
|
|
275
|
+
// -----------------
|
|
276
|
+
|
|
277
|
+
Deno.test("isPow2", () => {
|
|
278
|
+
let a;
|
|
279
|
+
a = isPow2(32n);
|
|
280
|
+
assertEquals(a, true);
|
|
281
|
+
a = isPow2(1023n);
|
|
282
|
+
assertEquals(a, false);
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
Deno.test("isPow10", () => {
|
|
287
|
+
let a;
|
|
288
|
+
a = isPow10(10n);
|
|
289
|
+
assertEquals(a, true);
|
|
290
|
+
a = isPow10(999n);
|
|
291
|
+
assertEquals(a, false);
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
Deno.test("prevPow2", () => {
|
|
296
|
+
let a;
|
|
297
|
+
a = prevPow2(32n);
|
|
298
|
+
assertEquals(a, 32n);
|
|
299
|
+
a = prevPow2(1023n);
|
|
300
|
+
assertEquals(a, 512n);
|
|
301
|
+
assertEquals(prevPow2(1n), 1n);
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
Deno.test("prevPow10", () => {
|
|
306
|
+
let a;
|
|
307
|
+
a = prevPow10(10n);
|
|
308
|
+
assertEquals(a, 10n);
|
|
309
|
+
a = prevPow10(999n);
|
|
310
|
+
assertEquals(a, 100n);
|
|
311
|
+
assertEquals(prevPow10(1n), 1n);
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
Deno.test("nextPow2", () => {
|
|
316
|
+
let a;
|
|
317
|
+
a = nextPow2(32n);
|
|
318
|
+
assertEquals(a, 32n);
|
|
319
|
+
a = nextPow2(1023n);
|
|
320
|
+
assertEquals(a, 1024n);
|
|
321
|
+
assertEquals(nextPow2(1n), 1n);
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
Deno.test("nextPow10", () => {
|
|
326
|
+
let a;
|
|
327
|
+
a = nextPow10(10n);
|
|
328
|
+
assertEquals(a, 10n);
|
|
329
|
+
a = nextPow10(999n);
|
|
330
|
+
assertEquals(a, 1000n);
|
|
331
|
+
assertEquals(nextPow10(1n), 1n);
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
Deno.test("log2", () => {
|
|
336
|
+
let a;
|
|
337
|
+
a = log2(32n);
|
|
338
|
+
assertEquals(a, 5n);
|
|
339
|
+
a = log2(127n);
|
|
340
|
+
assertEquals(a, 6n);
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
Deno.test("log10", () => {
|
|
345
|
+
let a;
|
|
346
|
+
a = log10(81n);
|
|
347
|
+
assertEquals(a, 1n);
|
|
348
|
+
a = log10(999n);
|
|
349
|
+
assertEquals(a, 2n);
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
// ROOT
|
|
356
|
+
// ----
|
|
357
|
+
|
|
358
|
+
Deno.test("sqrt", () => {
|
|
359
|
+
let a;
|
|
360
|
+
a = sqrt(81n);
|
|
361
|
+
assertEquals(a, 9n);
|
|
362
|
+
a = sqrt(99n);
|
|
363
|
+
assertEquals(a, 9n);
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
Deno.test("cbrt", () => {
|
|
368
|
+
let a;
|
|
369
|
+
a = cbrt(27n);
|
|
370
|
+
assertEquals(a, 3n);
|
|
371
|
+
a = cbrt(99n);
|
|
372
|
+
assertEquals(a, 4n);
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
Deno.test("root", () => {
|
|
377
|
+
let a;
|
|
378
|
+
a = root(25n, 2n);
|
|
379
|
+
assertEquals(a, 5n);
|
|
380
|
+
a = root(-8n, 3n);
|
|
381
|
+
assertEquals(a, -2n);
|
|
382
|
+
a = root(81n, 4n);
|
|
383
|
+
assertEquals(a, 3n);
|
|
384
|
+
a = root(99n, 4n);
|
|
385
|
+
assertEquals(a, 3n);
|
|
386
|
+
});
|
|
387
|
+
// - https://en.wikipedia.org/wiki/Nth_root
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
// DIVISORS
|
|
393
|
+
// --------
|
|
394
|
+
|
|
395
|
+
Deno.test("properDivisors", () => {
|
|
396
|
+
let a;
|
|
397
|
+
a = properDivisors(6n);
|
|
398
|
+
assertEquals(a, [1n, 2n, 3n]);
|
|
399
|
+
a = properDivisors(1n);
|
|
400
|
+
assertEquals(a, []);
|
|
401
|
+
a = properDivisors(0n);
|
|
402
|
+
assertEquals(a, []);
|
|
403
|
+
a = properDivisors(-24n);
|
|
404
|
+
assertEquals(a, [1n, 2n, 3n, 4n, 6n, 8n, 12n]);
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
Deno.test("aliquotSum", () => {
|
|
409
|
+
let a;
|
|
410
|
+
a = aliquotSum(6n);
|
|
411
|
+
assertEquals(a, 6n); // (1+2+3)
|
|
412
|
+
a = aliquotSum(1n);
|
|
413
|
+
assertEquals(a, 0n);
|
|
414
|
+
a = aliquotSum(0n);
|
|
415
|
+
assertEquals(a, 0n);
|
|
416
|
+
a = aliquotSum(-24n);
|
|
417
|
+
assertEquals(a, 36n); // (1+2+3+4+6+8+12)
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
|
|
421
|
+
Deno.test("minPrimeFactor", () => {
|
|
422
|
+
let a;
|
|
423
|
+
a = minPrimeFactor(1n);
|
|
424
|
+
assertEquals(a, 0n);
|
|
425
|
+
a = minPrimeFactor(3n);
|
|
426
|
+
assertEquals(a, 3n);
|
|
427
|
+
a = minPrimeFactor(21n);
|
|
428
|
+
assertEquals(a, 3n);
|
|
429
|
+
a = minPrimeFactor(55n);
|
|
430
|
+
assertEquals(a, 5n);
|
|
431
|
+
a = minPrimeFactor(53n);
|
|
432
|
+
assertEquals(a, 53n);
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
Deno.test("maxPrimeFactor", () => {
|
|
437
|
+
let a;
|
|
438
|
+
a = maxPrimeFactor(1n);
|
|
439
|
+
assertEquals(a, 0n);
|
|
440
|
+
a = maxPrimeFactor(3n);
|
|
441
|
+
assertEquals(a, 3n);
|
|
442
|
+
a = maxPrimeFactor(21n);
|
|
443
|
+
assertEquals(a, 7n);
|
|
444
|
+
a = maxPrimeFactor(55n);
|
|
445
|
+
assertEquals(a, 11n);
|
|
446
|
+
a = maxPrimeFactor(53n);
|
|
447
|
+
assertEquals(a, 53n);
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
Deno.test("primeFactors", () => {
|
|
452
|
+
let a;
|
|
453
|
+
a = primeFactors(1n);
|
|
454
|
+
assertEquals(a, []);
|
|
455
|
+
a = primeFactors(3n);
|
|
456
|
+
assertEquals(a, [3n]);
|
|
457
|
+
a = primeFactors(21n);
|
|
458
|
+
assertEquals(a, [3n, 7n]);
|
|
459
|
+
a = primeFactors(55n);
|
|
460
|
+
assertEquals(a, [5n, 11n]);
|
|
461
|
+
a = primeFactors(53n);
|
|
462
|
+
assertEquals(a, [53n]);
|
|
463
|
+
});
|
|
464
|
+
|
|
465
|
+
|
|
466
|
+
Deno.test("primeExponentials", () => {
|
|
467
|
+
let a;
|
|
468
|
+
a = primeExponentials(1n);
|
|
469
|
+
assertEquals(a, []);
|
|
470
|
+
a = primeExponentials(9n);
|
|
471
|
+
assertEquals(a, [[3n, 2n]]);
|
|
472
|
+
a = primeExponentials(63n);
|
|
473
|
+
assertEquals(a, [[3n, 2n], [7n, 1n]]);
|
|
474
|
+
a = primeExponentials(605n);
|
|
475
|
+
assertEquals(a, [[5n, 1n], [11n, 2n]]);
|
|
476
|
+
a = primeExponentials(53n);
|
|
477
|
+
assertEquals(a, [[53n, 1n]]);
|
|
478
|
+
});
|
|
479
|
+
|
|
480
|
+
|
|
481
|
+
Deno.test("isPrime", () => {
|
|
482
|
+
let a;
|
|
483
|
+
a = isPrime(7n);
|
|
484
|
+
assertEquals(a, true);
|
|
485
|
+
a = isPrime(53n);
|
|
486
|
+
assertEquals(a, true);
|
|
487
|
+
a = isPrime(4n);
|
|
488
|
+
assertEquals(a, false);
|
|
489
|
+
a = isPrime(1n);
|
|
490
|
+
assertEquals(a, false);
|
|
491
|
+
a = isPrime(0n);
|
|
492
|
+
assertEquals(a, false);
|
|
493
|
+
});
|
|
494
|
+
|
|
495
|
+
|
|
496
|
+
Deno.test("gcd", () => {
|
|
497
|
+
let a;
|
|
498
|
+
a = gcd(6n, 15n);
|
|
499
|
+
assertEquals(a, 3n);
|
|
500
|
+
a = gcd(6n, 15n, 21n);
|
|
501
|
+
assertEquals(a, 3n);
|
|
502
|
+
a = gcd(6n, 15n, 20n);
|
|
503
|
+
assertEquals(a, 1n);
|
|
504
|
+
a = gcd(); // sp
|
|
505
|
+
assertEquals(a, 1n); // sp
|
|
506
|
+
assertEquals(gcd(0n, 6n), 6n);
|
|
507
|
+
assertEquals(gcd(6n, 0n), 6n);
|
|
508
|
+
assertEquals(gcd(0n, 0n), 0n);
|
|
509
|
+
assertEquals(gcd(4n, -6n), 2n);
|
|
510
|
+
});
|
|
511
|
+
|
|
512
|
+
|
|
513
|
+
Deno.test("lcm", () => {
|
|
514
|
+
let a;
|
|
515
|
+
a = lcm(2n, 3n);
|
|
516
|
+
assertEquals(a, 6n);
|
|
517
|
+
a = lcm(2n, 3n, 4n);
|
|
518
|
+
assertEquals(a, 12n);
|
|
519
|
+
a = lcm(2n, 3n, 4n, 5n);
|
|
520
|
+
assertEquals(a, 60n);
|
|
521
|
+
a = lcm(); // sp
|
|
522
|
+
assertEquals(a, 1n); // sp
|
|
523
|
+
assertEquals(lcm(0n, 5n), 0n);
|
|
524
|
+
assertEquals(lcm(5n, 0n, 0n), 0n);
|
|
525
|
+
assertEquals(lcm(-4n, 6n), 12n);
|
|
526
|
+
});
|
|
527
|
+
|
|
528
|
+
|
|
529
|
+
|
|
530
|
+
|
|
531
|
+
// ARRANGEMENTS
|
|
532
|
+
// ------------
|
|
533
|
+
|
|
534
|
+
Deno.test("factorial", () => {
|
|
535
|
+
let a;
|
|
536
|
+
a = factorial(5n);
|
|
537
|
+
assertEquals(a, 120n);
|
|
538
|
+
a = factorial(6n);
|
|
539
|
+
assertEquals(a, 720n);
|
|
540
|
+
a = factorial(7n);
|
|
541
|
+
assertEquals(a, 5040n);
|
|
542
|
+
a = factorial(-1n); // sp
|
|
543
|
+
assertEquals(a, 0n); // sp
|
|
544
|
+
});
|
|
545
|
+
// - https://en.wikipedia.org/wiki/Factorial
|
|
546
|
+
|
|
547
|
+
|
|
548
|
+
Deno.test("binomial", () => {
|
|
549
|
+
let a;
|
|
550
|
+
a = binomial(4n, 1n);
|
|
551
|
+
assertEquals(a, 4n);
|
|
552
|
+
a = binomial(4n, 2n);
|
|
553
|
+
assertEquals(a, 6n);
|
|
554
|
+
a = binomial(4n, 3n);
|
|
555
|
+
assertEquals(a, 4n);
|
|
556
|
+
a = binomial(4n, -1n); // sp
|
|
557
|
+
assertEquals(a, 0n); // sp
|
|
558
|
+
a = binomial(-4n, 1n); // sp
|
|
559
|
+
assertEquals(a, -4n); // sp
|
|
560
|
+
assertEquals(binomial(-2n, 2n), 3n);
|
|
561
|
+
assertEquals(binomial(-1n, 2n), 1n);
|
|
562
|
+
assertEquals(binomial(-2n, 3n), -4n);
|
|
563
|
+
});
|
|
564
|
+
|
|
565
|
+
|
|
566
|
+
Deno.test("multinomial", () => {
|
|
567
|
+
let a;
|
|
568
|
+
a = multinomial(1n, 2n);
|
|
569
|
+
assertEquals(a, 3n);
|
|
570
|
+
a = multinomial(1n, 2n, 3n);
|
|
571
|
+
assertEquals(a, 60n);
|
|
572
|
+
a = multinomial(1n, 2n, 3n, 4n);
|
|
573
|
+
assertEquals(a, 12600n);
|
|
574
|
+
});
|
|
575
|
+
|
|
576
|
+
|
|
577
|
+
|
|
578
|
+
|
|
579
|
+
// GEOMETRY
|
|
580
|
+
// --------
|
|
581
|
+
|
|
582
|
+
Deno.test("hypot", () => {
|
|
583
|
+
let a;
|
|
584
|
+
a = hypot(3n, 4n);
|
|
585
|
+
assertEquals(a, 5n);
|
|
586
|
+
a = hypot(8n, 15n);
|
|
587
|
+
assertEquals(a, 17n);
|
|
588
|
+
a = hypot(6n, 8n);
|
|
589
|
+
assertEquals(a, 10n);
|
|
590
|
+
});
|
|
591
|
+
|
|
592
|
+
|
|
593
|
+
|
|
594
|
+
|
|
595
|
+
// STATISTICS
|
|
596
|
+
// ----------
|
|
597
|
+
|
|
598
|
+
Deno.test("sum", () => {
|
|
599
|
+
let a;
|
|
600
|
+
a = sum(1n, 2n);
|
|
601
|
+
assertEquals(a, 3n);
|
|
602
|
+
a = sum(1n, 2n, 3n);
|
|
603
|
+
assertEquals(a, 6n);
|
|
604
|
+
a = sum(1n, 2n, 3n, 4n);
|
|
605
|
+
assertEquals(a, 10n);
|
|
606
|
+
});
|
|
607
|
+
|
|
608
|
+
|
|
609
|
+
Deno.test("product", () => {
|
|
610
|
+
let a;
|
|
611
|
+
a = product(1n, 2n);
|
|
612
|
+
assertEquals(a, 2n);
|
|
613
|
+
a = product(1n, 2n, 3n);
|
|
614
|
+
assertEquals(a, 6n);
|
|
615
|
+
a = product(1n, 2n, 3n, 4n);
|
|
616
|
+
assertEquals(a, 24n);
|
|
617
|
+
});
|
|
618
|
+
|
|
619
|
+
|
|
620
|
+
Deno.test("median", () => {
|
|
621
|
+
let a;
|
|
622
|
+
a = median(1n, 7n);
|
|
623
|
+
assertEquals(a, 4n);
|
|
624
|
+
a = median(1n, 7n, 8n);
|
|
625
|
+
assertEquals(a, 7n);
|
|
626
|
+
a = median(1n, 7n, 8n, 10n);
|
|
627
|
+
assertEquals(a, 7n);
|
|
628
|
+
});
|
|
629
|
+
|
|
630
|
+
|
|
631
|
+
Deno.test("modes", () => {
|
|
632
|
+
let a;
|
|
633
|
+
a = modes(1n, 2n);
|
|
634
|
+
assertEquals(a, [1n, 2n]);
|
|
635
|
+
a = modes(1n, 2n, 2n);
|
|
636
|
+
assertEquals(a, [2n]);
|
|
637
|
+
a = modes(1n, 2n, 2n, 3n, 3n);
|
|
638
|
+
assertEquals(a, [2n, 3n]);
|
|
639
|
+
});
|
|
640
|
+
|
|
641
|
+
|
|
642
|
+
Deno.test("min", () => {
|
|
643
|
+
let a;
|
|
644
|
+
a = min(1n, 7n);
|
|
645
|
+
assertEquals(a, 1n);
|
|
646
|
+
a = min(8n, 7n, 6n);
|
|
647
|
+
assertEquals(a, 6n);
|
|
648
|
+
a = min(7n, 8n, 6n);
|
|
649
|
+
assertEquals(a, 6n);
|
|
650
|
+
});
|
|
651
|
+
|
|
652
|
+
|
|
653
|
+
Deno.test("max", () => {
|
|
654
|
+
let a;
|
|
655
|
+
a = max(1n, 7n);
|
|
656
|
+
assertEquals(a, 7n);
|
|
657
|
+
a = max(8n, 7n, 6n);
|
|
658
|
+
assertEquals(a, 8n);
|
|
659
|
+
a = max(7n, 8n, 6n);
|
|
660
|
+
assertEquals(a, 8n);
|
|
661
|
+
});
|
|
662
|
+
|
|
663
|
+
|
|
664
|
+
Deno.test("range", () => {
|
|
665
|
+
let a;
|
|
666
|
+
a = range(1n, 7n);
|
|
667
|
+
assertEquals(a, [1n, 7n]);
|
|
668
|
+
a = range(1n, 7n, 6n);
|
|
669
|
+
assertEquals(a, [1n, 7n]);
|
|
670
|
+
a = range(1n, 7n, 8n, 6n);
|
|
671
|
+
assertEquals(a, [1n, 8n]);
|
|
672
|
+
});
|
|
673
|
+
|
|
674
|
+
|
|
675
|
+
Deno.test("variance", () => {
|
|
676
|
+
let a;
|
|
677
|
+
a = variance(1n, 2n);
|
|
678
|
+
assertEquals(a, BigInt(Math.floor(0.25)));
|
|
679
|
+
a = variance(1n, 2n, 3n);
|
|
680
|
+
assertEquals(a, BigInt(Math.floor(0.6666666666666666)));
|
|
681
|
+
a = variance(1n, 2n, 3n, 4n);
|
|
682
|
+
assertEquals(a, BigInt(Math.floor(1.25)));
|
|
683
|
+
});
|
|
684
|
+
|
|
685
|
+
|
|
686
|
+
|
|
687
|
+
|
|
688
|
+
// MEAN (STATISTICS)
|
|
689
|
+
// -----------------
|
|
690
|
+
|
|
691
|
+
Deno.test("arithmeticMean", () => {
|
|
692
|
+
let a;
|
|
693
|
+
a = arithmeticMean(1n, 2n);
|
|
694
|
+
assertEquals(a, BigInt(Math.floor(1.5)));
|
|
695
|
+
a = arithmeticMean(1n, 2n, 3n);
|
|
696
|
+
assertEquals(a, BigInt(Math.floor(2)));
|
|
697
|
+
a = arithmeticMean(1n, 2n, 3n, 4n);
|
|
698
|
+
assertEquals(a, BigInt(Math.floor(2.5)));
|
|
699
|
+
});
|
|
700
|
+
|
|
701
|
+
|
|
702
|
+
Deno.test("geometricMean", () => {
|
|
703
|
+
let a;
|
|
704
|
+
a = geometricMean(1n, 2n);
|
|
705
|
+
assertEquals(a, BigInt(Math.floor(Math.sqrt(2))));
|
|
706
|
+
a = geometricMean(1n, 2n, 3n);
|
|
707
|
+
assertEquals(a, BigInt(Math.floor(Math.cbrt(6))));
|
|
708
|
+
a = geometricMean(1n, 2n, 3n, 4n);
|
|
709
|
+
assertEquals(a, BigInt(Math.floor(Math.pow(24, 1/4))));
|
|
710
|
+
});
|
|
711
|
+
|
|
712
|
+
|
|
713
|
+
Deno.test("harmonicMean", () => {
|
|
714
|
+
let a;
|
|
715
|
+
a = harmonicMean(1n, 2n);
|
|
716
|
+
assertEquals(a, BigInt(Math.floor(4/3)));
|
|
717
|
+
a = harmonicMean(1n, 2n, 3n);
|
|
718
|
+
assertEquals(a, BigInt(Math.floor(18/11)));
|
|
719
|
+
a = harmonicMean(1n, 2n, 3n, 4n);
|
|
720
|
+
assertEquals(a, BigInt(Math.floor(48/25)));
|
|
721
|
+
});
|
|
722
|
+
|
|
723
|
+
|
|
724
|
+
Deno.test("quadriaticMean", () => {
|
|
725
|
+
let a;
|
|
726
|
+
a = quadriaticMean(1n, 2n);
|
|
727
|
+
assertEquals(a, BigInt(Math.floor(Math.sqrt(5/2))));
|
|
728
|
+
a = quadriaticMean(1n, 2n, 3n);
|
|
729
|
+
assertEquals(a, BigInt(Math.floor(Math.sqrt(14/3))));
|
|
730
|
+
a = quadriaticMean(1n, 2n, 3n, 4n);
|
|
731
|
+
assertEquals(a, BigInt(Math.floor(Math.sqrt(30/4))));
|
|
732
|
+
});
|
|
733
|
+
|
|
734
|
+
|
|
735
|
+
Deno.test("cubicMean", () => {
|
|
736
|
+
let a;
|
|
737
|
+
a = cubicMean(1n, 2n);
|
|
738
|
+
assertEquals(a, BigInt(Math.floor(Math.cbrt(9/2))));
|
|
739
|
+
a = cubicMean(1n, 2n, 3n);
|
|
740
|
+
assertEquals(a, BigInt(Math.floor(Math.cbrt(36/3))));
|
|
741
|
+
a = cubicMean(1n, 2n, 3n, 4n);
|
|
742
|
+
assertEquals(a, BigInt(Math.floor(Math.cbrt(100/4))));
|
|
743
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nodef/extra-bigint.web",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.4.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"main": "./index.js",
|
|
7
|
+
"types": "./index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./index.d.ts",
|
|
11
|
+
"import": "./index.js",
|
|
12
|
+
"default": "./index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {}
|
|
6
16
|
}
|