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