UNPKG

12.6 kBTypeScriptView Raw
1/**
2 * Check if value is a bigint.
3 * [šŸ“˜](https://github.com/nodef/extra-bigint/wiki/is)
4 * @param x a value
5 * @returns is bigint?
6 */
7declare function is(x: any): x is bigint;
8/**
9 * Compare two bigints.
10 * [šŸ“˜](https://github.com/nodef/extra-bigint/wiki/compare)
11 * @param x a bigint
12 * @param y another bigint
13 * @returns x<y: -ve, x=y: 0, x>y: +ve
14 */
15declare function compare(x: bigint, y: bigint): number;
16/**
17 * Get the absolute of a bigint.
18 * [šŸ“˜](https://github.com/nodef/extra-bigint/wiki/abs)
19 * @param x a bigint
20 * @returns |x|
21 */
22declare function abs(x: bigint): bigint;
23/**
24 * Get the sign of a bigint.
25 * [šŸ“˜](https://github.com/nodef/extra-bigint/wiki/sign)
26 * @param x a bigint
27 * @returns x>0: 1n, x<0: -1n, x=0: 0n
28 */
29declare function sign(x: bigint): bigint;
30/**
31 * Perform floor-divison of two bigints (\\).
32 * [šŸ“˜](https://github.com/nodef/extra-bigint/wiki/floorDiv)
33 * @param x dividend
34 * @param y divisor
35 * @returns āŒŠx/yāŒ‹
36 */
37declare function floorDiv(x: bigint, y: bigint): bigint;
38/**
39 * Perform ceiling-divison of two bigints.
40 * [šŸ“˜](https://github.com/nodef/extra-bigint/wiki/ceilDiv)
41 * @param x dividend
42 * @param y divisor
43 * @returns āŒˆx/yāŒ‰
44 */
45declare function ceilDiv(x: bigint, y: bigint): bigint;
46/**
47 * Perform rounded-divison of two bigints.
48 * [šŸ“˜](https://github.com/nodef/extra-bigint/wiki/roundDiv)
49 * @param x divisor
50 * @param y dividend
51 * @returns [x/y]
52 */
53declare function roundDiv(x: bigint, y: bigint): bigint;
54/**
55 * Find the remainder of x/y with sign of x (truncated division).
56 * [šŸ“˜](https://github.com/nodef/extra-bigint/wiki/rem)
57 * @param x dividend
58 * @param y divisor
59 * @returns trunc(x % y)
60 */
61declare function rem(x: bigint, y: bigint): bigint;
62/**
63 * Find the remainder of x/y with sign of y (floored division).
64 * [šŸ“˜](https://github.com/nodef/extra-bigint/wiki/mod)
65 * @param x dividend
66 * @param y divisor
67 * @returns floor(x % y)
68 */
69declare function mod(x: bigint, y: bigint): bigint;
70/**
71 * Find the remainder of x/y with +ve sign (euclidean division).
72 * [šŸ“˜](https://github.com/nodef/extra-bigint/wiki/modp)
73 * @param x dividend
74 * @param y divisor
75 * @returns x/y>0: floor(x % y), x/y<0: ceil(x % y)
76 */
77declare function modp(x: bigint, y: bigint): bigint;
78/**
79 * Constrain a bigint within a minimum and a maximum value.
80 * [šŸ“˜](https://github.com/nodef/extra-bigint/wiki/constrain)
81 * @param x a bigint
82 * @param minv minimum value
83 * @param maxv maximum value
84 * @returns x<min: min, x>max: max, x
85 */
86declare function constrain(x: bigint, minv: bigint, maxv: bigint): bigint;
87
88/**
89 * Re-map a bigint from one range to another.
90 * [šŸ“˜](https://github.com/nodef/extra-bigint/wiki/remap)
91 * @param x a bigint
92 * @param r lower bound of current range
93 * @param R upper bound of current range
94 * @param t lower bound of target range
95 * @param T upper bound of target range
96 * @returns āˆˆ [ymin, ymax]
97 */
98declare function remap(x: bigint, r: bigint, R: bigint, t: bigint, T: bigint): bigint;
99
100/**
101 * Linearly interpolate a bigint between two bigints.
102 * [šŸ“˜](https://github.com/nodef/extra-bigint/wiki/lerp)
103 * @param x start bigint
104 * @param y stop bigint
105 * @param t interpolant āˆˆ [0, 1]
106 * @returns āˆˆ [x, y]
107 */
108declare function lerp(x: bigint, y: bigint, t: number): bigint;
109/**
110 * Check if bigint is a power-of-2.
111 * [šŸ“˜](https://github.com/nodef/extra-bigint/wiki/isPow2)
112 * @param x a bigint
113 * @returns 2ā± = x? | i = +ve integer
114 */
115declare function isPow2(x: bigint): boolean;
116/**
117 * Check if bigint is a power-of-10.
118 * [šŸ“˜](https://github.com/nodef/extra-bigint/wiki/isPow10)
119 * @param x a bigint
120 * @returns 10ā± = x? | i = +ve integer
121 */
122declare function isPow10(x: bigint): boolean;
123/**
124 * Find largest power-of-2 less than or equal to given bigint.
125 * [šŸ“˜](https://github.com/nodef/extra-bigint/wiki/prevPow2)
126 * @param x a bigint
127 * @returns 2ā± | 2ā± ā‰¤ x and 2ā± > x/2
128 */
129declare function prevPow2(x: bigint): bigint;
130/**
131 * Find largest power-of-10 less than or equal to given bigint.
132 * [šŸ“˜](https://github.com/nodef/extra-bigint/wiki/prevPow10)
133 * @param x a bigint
134 * @returns 10ā± | 10ā± ā‰¤ x and 10ā± > x/10
135 */
136declare function prevPow10(x: bigint): bigint;
137/**
138 * Find smallest power-of-2 greater than or equal to given bigint.
139 * [šŸ“˜](https://github.com/nodef/extra-bigint/wiki/nextPow2)
140 * @param x a bigint
141 * @returns 2ā± | 2ā± ā‰„ x and 2ā± < 2x
142 */
143declare function nextPow2(x: bigint): bigint;
144/**
145 * Find smallest power-of-10 greater than or equal to given bigint.
146 * [šŸ“˜](https://github.com/nodef/extra-bigint/wiki/nextPow10)
147 * @param x a bigint
148 * @returns 10ā± | 10ā± ā‰„ x and 10ā± < 10x
149 */
150declare function nextPow10(x: bigint): bigint;
151/**
152 * Find the base-2 logarithm of a bigint.
153 * [šŸ“˜](https://github.com/nodef/extra-bigint/wiki/log2)
154 * @param x a bigint
155 * @returns logā‚‚(x)
156 */
157declare function log2(x: bigint): bigint;
158/**
159 * Find the base-10 logarithm of a bigint.
160 * [šŸ“˜](https://github.com/nodef/extra-bigint/wiki/log10)
161 * @param x a bigint
162 * @returns logā‚ā‚€(x)
163 */
164declare function log10(x: bigint): bigint;
165/**
166 * Find the square root of a bigint.
167 * [šŸ“˜](https://github.com/nodef/extra-bigint/wiki/sqrt)
168 * @param x a bigint
169 * @returns āˆšx
170 */
171declare function sqrt(x: bigint): bigint;
172/**
173 * Find the cube root of a bigint.
174 * [šŸ“˜](https://github.com/nodef/extra-bigint/wiki/cbrt)
175 * @param x a bigint
176 * @returns Ā³āˆšx
177 */
178declare function cbrt(x: bigint): bigint;
179/**
180 * Find the nth root of a bigint.
181 * [šŸ“˜](https://github.com/nodef/extra-bigint/wiki/root)
182 * @param x a bigint
183 * @param n nth root (1n)
184 * @returns āæāˆšx
185 */
186declare function root(x: bigint, n?: bigint): bigint;
187/**
188 * List all divisors of a bigint, except itself.
189 * [šŸ“˜](https://github.com/nodef/extra-bigint/wiki/properDivisors)
190 * @param x a bigint
191 * @returns proper divisors (factors)
192 */
193declare function properDivisors(x: bigint): bigint[];
194
195/**
196 * Sum all proper divisors of a bigint.
197 * [šŸ“˜](https://github.com/nodef/extra-bigint/wiki/aliquotSum)
198 * @param x a bigint
199 * @returns Ī£dįµ¢ | dįµ¢ is a divisor of x and ā‰ x
200 */
201declare function aliquotSum(x: bigint): bigint;
202/**
203 * Find the least prime number which divides a bigint.
204 * [šŸ“˜](https://github.com/nodef/extra-bigint/wiki/minPrimeFactor)
205 * @param x a bigint
206 * @returns least prime factor
207 */
208declare function minPrimeFactor(x: bigint): bigint;
209
210/**
211 * Find the greatest prime number which divides a bigint.
212 * [šŸ“˜](https://github.com/nodef/extra-bigint/wiki/maxPrimeFactor)
213 * @param x a bigint
214 * @returns greatest prime factor
215 */
216declare function maxPrimeFactor(x: bigint): bigint;
217
218/**
219 * Find the prime factors of a bigint.
220 * [šŸ“˜](https://github.com/nodef/extra-bigint/wiki/primeFactors)
221 * @param x a bigint
222 * @returns [fā‚€, fā‚, ...] | fįµ¢ divides x and is prime
223 */
224declare function primeFactors(x: bigint): bigint[];
225/**
226 * Find the prime factors and respective exponents of a bigint.
227 * [šŸ“˜](https://github.com/nodef/extra-bigint/wiki/primeExponentials)
228 * @param x a bigint
229 * @returns [[fā‚€, eā‚€], [fā‚, eā‚], ...] | fįµ¢ is a prime factor of x and eįµ¢ is its exponent
230 */
231declare function primeExponentials(x: bigint): [bigint, bigint][];
232/**
233 * Check if bigint is prime.
234 * [šŸ“˜](https://github.com/nodef/extra-bigint/wiki/isPrime)
235 * @param x a bigint
236 * @returns is divisible by 1n and itself only?
237 */
238declare function isPrime(x: bigint): boolean;
239/**
240 * Find the greatest common divisor of bigints.
241 * [šŸ“˜](https://github.com/nodef/extra-bigint/wiki/gcd)
242 * @param xs a list of bigints
243 * @returns gcd(xā‚, xā‚‚, ...)
244 */
245declare function gcd(...xs: bigint[]): bigint;
246
247/**
248 * Find the least common multiple of bigints.
249 * [šŸ“˜](https://github.com/nodef/extra-bigint/wiki/lcm)
250 * @param xs a list of bigints
251 * @returns lcm(xā‚, xā‚‚, ...)
252 */
253declare function lcm(...xs: bigint[]): bigint;
254/**
255 * Find the factorial of a bigint.
256 * [šŸ“˜](https://github.com/nodef/extra-bigint/wiki/factorial)
257 * @param n a bigint
258 * @param k denominator factorial [0]
259 * @returns P(n, k); k=0: n!, k>0: n!/k!
260 */
261declare function factorial(n: bigint, k?: bigint): bigint;
262/**
263 * Find the number of ways to choose k elements from a set of n elements.
264 * [šŸ“˜](https://github.com/nodef/extra-bigint/wiki/binomial)
265 * @param n elements in source set
266 * @param k elements in choose set
267 * @returns C(n, k)
268 */
269declare function binomial(n: bigint, k: bigint): bigint;
270/**
271 * Find the number of ways to put n objects in m bins (n=sum(kįµ¢)).
272 * [šŸ“˜](https://github.com/nodef/extra-bigint/wiki/multinomial)
273 * @param ks objects per bin (kįµ¢)
274 * @returns n!/(kā‚!kā‚‚!...) | n=sum(kįµ¢)
275 */
276declare function multinomial(...ks: bigint[]): bigint;
277/**
278 * Find the length of hypotenuse.
279 * [šŸ“˜](https://github.com/nodef/extra-bigint/wiki/hypot)
280 * @param xs lengths of perpendicular sides (x, y, z, ...)
281 * @returns āˆš(xĀ² + yĀ² + zĀ²)
282 */
283declare function hypot(...xs: bigint[]): bigint;
284/**
285 * Find the sum of bigints (Ī£).
286 * [šŸ“˜](https://github.com/nodef/extra-bigint/wiki/sum)
287 * @param xs bigints
288 * @returns Ī£xįµ¢
289 */
290declare function sum(...xs: bigint[]): bigint;
291/**
292 * Find the product of bigints (āˆ).
293 * [šŸ“˜](https://github.com/nodef/extra-bigint/wiki/product)
294 * @param xs bigints
295 * @returns āˆxįµ¢
296 */
297declare function product(...xs: bigint[]): bigint;
298/**
299 * Find the value separating the higher and lower halves of bigints.
300 * [šŸ“˜](https://github.com/nodef/extra-bigint/wiki/median)
301 * @param xs a list of bigints
302 * @returns xā‚˜ | sort(xs) = [..., xā‚˜, ...]
303 */
304declare function median(...xs: bigint[]): bigint;
305/**
306 * Find the values that appear most often.
307 * [šŸ“˜](https://github.com/nodef/extra-bigint/wiki/modes)
308 * @param xs a list of bigints
309 * @returns [xā‚˜ā‚, xā‚˜ā‚‚, ...] | count(xā‚˜įµ¢) ā‰„ count(xįµ¢) āˆ€ xįµ¢ āˆˆ xs
310 */
311declare function modes(...xs: bigint[]): bigint[];
312/**
313 * Find the smallest bigint.
314 * [šŸ“˜](https://github.com/nodef/extra-bigint/wiki/min)
315 * @param xs bigints
316 * @returns min(xs)
317 */
318declare function min(...xs: bigint[]): bigint;
319/**
320 * Find the largest bigint.
321 * [šŸ“˜](https://github.com/nodef/extra-bigint/wiki/max)
322 * @param xs bigints
323 * @returns max(xs)
324 */
325declare function max(...xs: bigint[]): bigint;
326/**
327 * Find the minimum and maximum bigint.
328 * [šŸ“˜](https://github.com/nodef/extra-bigint/wiki/range)
329 * @param xs bigints
330 * @returns [min, max]
331 */
332declare function range(...xs: bigint[]): [bigint, bigint];
333/**
334 * Find the mean of squared deviation of bigints from its mean.
335 * [šŸ“˜](https://github.com/nodef/extra-bigint/wiki/variance)
336 * @param xs a list of bigints
337 * @returns ĻƒĀ² = E[(xs - Āµ)Ā²] | Āµ = mean(xs)
338 */
339declare function variance(...xs: bigint[]): bigint;
340/**
341 * Find the arithmetic mean of bigints (Āµ).
342 * [šŸ“˜](https://github.com/nodef/extra-bigint/wiki/arithmeticMean)
343 * @param xs bigints
344 * @returns Āµ = (Ī£xįµ¢)/n | n = size(xs)
345 */
346declare function arithmeticMean(...xs: bigint[]): bigint;
347
348/**
349 * Find the geometric mean of bigints.
350 * [šŸ“˜](https://github.com/nodef/extra-bigint/wiki/geometricMean)
351 * @param xs bigints
352 * @returns āæāˆš(āˆxįµ¢) | n = size(xs)
353 */
354declare function geometricMean(...xs: bigint[]): bigint;
355/**
356 * Find the harmonic mean of bigints.
357 * [šŸ“˜](https://github.com/nodef/extra-bigint/wiki/harmonicMean)
358 * @param xs bigints
359 * @returns n/Ī£(1/xįµ¢) | n = size(xs)
360 */
361declare function harmonicMean(...xs: bigint[]): bigint;
362/**
363 * Find the quadriatic mean of bigints.
364 * [šŸ“˜](https://github.com/nodef/extra-bigint/wiki/quadriaticMean)
365 * @param xs bigints
366 * @returns āˆš(Ī£xįµ¢Ā²)/n | n = size(xs)
367 */
368declare function quadriaticMean(...xs: bigint[]): bigint;
369
370/**
371 * Find the cubic mean of bigints.
372 * [šŸ“˜](https://github.com/nodef/extra-bigint/wiki/cubicMean)
373 * @param xs bigints
374 * @returns Ā³āˆš(Ī£xįµ¢Ā³)/n | n = size(xs)
375 */
376declare function cubicMean(...xs: bigint[]): bigint;
377
378export { abs, properDivisors as aliquotParts, aliquotSum, arithmeticMean, binomial, cbrt, ceilDiv, constrain as clamp, compare, constrain, cubicMean, factorial, floorDiv, gcd, geometricMean, maxPrimeFactor as greatestPrimeFactor, harmonicMean, gcd as hcf, hypot, is, isPow10, isPow2, isPrime, lcm, minPrimeFactor as leastPrimeFactor, lerp, log10, log2, remap as map, max, maxPrimeFactor, arithmeticMean as mean, median, min, minPrimeFactor, mod, modes, modp, multinomial, nextPow10, nextPow2, prevPow10, prevPow2, primeExponentials, primeFactors, product, properDivisors, quadriaticMean, range, rem, remap, root, quadriaticMean as rootMeanSquare, roundDiv, sign, sqrt, sum, variance };