extra-math 1.3.19 โ 1.3.22
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/README.md +2 -1
- package/index.d.ts +90 -30
- package/index.js +2 -0
- package/index.mjs +1 -1
- package/package.json +6 -3
package/README.md
CHANGED
|
@@ -122,7 +122,8 @@ math.lcm(2, 3, 4);
|
|
|
122
122
|
<br>
|
|
123
123
|
|
|
124
124
|
|
|
125
|
-
[](https://www.youtube.com/watch?v=dW8Cy6WrO94)
|
|
125
|
+
[](https://www.youtube.com/watch?v=dW8Cy6WrO94)<br>
|
|
126
|
+
[](https://zenodo.org/badge/latestdoi/141781770)
|
|
126
127
|
|
|
127
128
|
|
|
128
129
|
[rem]: https://nodef.github.io/extra-math/modules.html#rem
|
package/index.d.ts
CHANGED
|
@@ -1,194 +1,254 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Find the remainder of x/y with sign of x (truncated division).
|
|
3
|
+
* [๐](https://github.com/nodef/extra-math/wiki/rem)
|
|
3
4
|
* @param x dividend
|
|
4
5
|
* @param y divisor
|
|
5
6
|
* @returns trunc(x/y)
|
|
6
|
-
*/
|
|
7
|
+
* */
|
|
8
|
+
|
|
7
9
|
declare function rem(x: number, y: number): number;
|
|
8
10
|
/**
|
|
9
11
|
* Find the remainder of x/y with sign of y (floored division).
|
|
12
|
+
* [๐](https://github.com/nodef/extra-math/wiki/mod)
|
|
10
13
|
* @param x dividend
|
|
11
14
|
* @param y divisor
|
|
12
15
|
* @returns floor(x/y)
|
|
13
|
-
*/
|
|
16
|
+
* */
|
|
17
|
+
|
|
14
18
|
declare function mod(x: number, y: number): number;
|
|
15
19
|
/**
|
|
16
20
|
* Find the remainder of x/y with +ve sign (euclidean division).
|
|
21
|
+
* [๐](https://github.com/nodef/extra-math/wiki/modp)
|
|
17
22
|
* @param x dividend
|
|
18
23
|
* @param y divisor
|
|
19
24
|
* @returns n>0: floor(x/y), n<0: ceil(x/y)
|
|
20
|
-
*/
|
|
25
|
+
* */
|
|
26
|
+
|
|
21
27
|
declare function modp(x: number, y: number): number;
|
|
22
28
|
/**
|
|
23
29
|
* Find the greatest common divisor of numbers.
|
|
30
|
+
* [๐](https://github.com/nodef/extra-math/wiki/gcd)
|
|
24
31
|
* @param xs a list of numbers
|
|
25
32
|
* @returns gcd(xโ, xโ, ...)
|
|
26
|
-
*/
|
|
33
|
+
* */
|
|
34
|
+
|
|
27
35
|
declare function gcd(...xs: number[]): number;
|
|
36
|
+
|
|
28
37
|
/**
|
|
29
38
|
* Find the least common multiple of numbers.
|
|
39
|
+
* [๐](https://github.com/nodef/extra-math/wiki/lcm)
|
|
30
40
|
* @param xs a list of numbers
|
|
31
41
|
* @returns lcm(xโ, xโ, ...)
|
|
32
|
-
*/
|
|
42
|
+
* */
|
|
43
|
+
|
|
33
44
|
declare function lcm(...xs: number[]): number;
|
|
34
45
|
/**
|
|
35
46
|
* Find the factorial of a number.
|
|
47
|
+
* [๐](https://github.com/nodef/extra-math/wiki/factorial)
|
|
36
48
|
* @param n a number
|
|
37
49
|
* @param k denominator factorial [0]
|
|
38
50
|
* @returns P(n, k); k=0: n!, k>0: n!/k!
|
|
39
|
-
*/
|
|
51
|
+
* */
|
|
52
|
+
|
|
40
53
|
declare function factorial(n: number, k?: number): number;
|
|
41
54
|
/**
|
|
42
55
|
* Find the number of ways to choose k elements from a set of n elements.
|
|
56
|
+
* [๐](https://github.com/nodef/extra-math/wiki/binomial)
|
|
43
57
|
* @param n elements in source set
|
|
44
58
|
* @param k elements in choose set
|
|
45
59
|
* @returns C(n, k)
|
|
46
|
-
*/
|
|
60
|
+
* */
|
|
61
|
+
|
|
47
62
|
declare function binomial(n: number, k: number): number;
|
|
48
63
|
/**
|
|
49
64
|
* Find the number of ways to put n objects in m bins (n=sum(kแตข)).
|
|
65
|
+
* [๐](https://github.com/nodef/extra-math/wiki/multinomial)
|
|
50
66
|
* @param ks objects per bin (kแตข)
|
|
51
67
|
* @returns n!/(kโ!kโ!...) | n=sum(kแตข)
|
|
52
|
-
*/
|
|
68
|
+
* */
|
|
69
|
+
|
|
53
70
|
declare function multinomial(...ks: number[]): number;
|
|
54
71
|
/**
|
|
55
72
|
* Constrain a number within a minimum and a maximum value.
|
|
73
|
+
* [๐](https://github.com/nodef/extra-math/wiki/constrain)
|
|
56
74
|
* @param x a number
|
|
57
75
|
* @param min minimum value
|
|
58
76
|
* @param max maximum value
|
|
59
77
|
* @returns x<min: min, x>max: max, x
|
|
60
|
-
*/
|
|
78
|
+
* */
|
|
79
|
+
|
|
61
80
|
declare function constrain(x: number, min: number, max: number): number;
|
|
81
|
+
|
|
62
82
|
/**
|
|
63
83
|
* Normalize a number from its current range into a value between 0 and 1.
|
|
84
|
+
* [๐](https://github.com/nodef/extra-math/wiki/norm)
|
|
64
85
|
* @param x a number
|
|
65
86
|
* @param r lower bound of current range
|
|
66
87
|
* @param R upper bound of current range
|
|
67
88
|
* @returns โ [0, 1]
|
|
68
|
-
*/
|
|
89
|
+
* */
|
|
90
|
+
|
|
69
91
|
declare function norm(x: number, r: number, R: number): number;
|
|
70
92
|
/**
|
|
71
93
|
* Re-map a number from one range to another.
|
|
94
|
+
* [๐](https://github.com/nodef/extra-math/wiki/map)
|
|
72
95
|
* @param x a number
|
|
73
96
|
* @param r lower bound of current range
|
|
74
97
|
* @param R upper bound of current range
|
|
75
98
|
* @param t lower bound of target range
|
|
76
99
|
* @param T upper bound of target range
|
|
77
100
|
* @returns โ [ymin, ymax]
|
|
78
|
-
*/
|
|
101
|
+
* */
|
|
102
|
+
|
|
79
103
|
declare function map(x: number, r: number, R: number, t: number, T: number): number;
|
|
80
104
|
/**
|
|
81
105
|
* Linearly interpolate a number between two numbers.
|
|
106
|
+
* [๐](https://github.com/nodef/extra-math/wiki/lerp)
|
|
82
107
|
* @param x start number
|
|
83
108
|
* @param y stop number
|
|
84
109
|
* @param t interpolant โ [0, 1]
|
|
85
110
|
* @returns โ [x, y]
|
|
86
|
-
*/
|
|
111
|
+
* */
|
|
112
|
+
|
|
87
113
|
declare function lerp(x: number, y: number, t: number): number;
|
|
88
114
|
/**
|
|
89
115
|
* Find the nth root of a number (โฟโ).
|
|
116
|
+
* [๐](https://github.com/nodef/extra-math/wiki/root)
|
|
90
117
|
* @param x a number
|
|
91
118
|
* @param n root
|
|
92
119
|
* @returns โฟโx
|
|
93
|
-
*/
|
|
120
|
+
* */
|
|
121
|
+
|
|
94
122
|
declare function root(x: number, n: number): number;
|
|
95
123
|
/**
|
|
96
124
|
* Find the logarithm of a number with a given base.
|
|
125
|
+
* [๐](https://github.com/nodef/extra-math/wiki/log)
|
|
97
126
|
* @param x a number
|
|
98
127
|
* @param b logarithm base [e]
|
|
99
128
|
* @returns log_b (x)
|
|
100
|
-
*/
|
|
129
|
+
* */
|
|
130
|
+
|
|
101
131
|
declare function log(x: number, b?: number): number;
|
|
102
132
|
/**
|
|
103
133
|
* Compute the gamma function of a number (ฮ).
|
|
134
|
+
* [๐](https://github.com/nodef/extra-math/wiki/gamma)
|
|
104
135
|
* @param x a number
|
|
105
136
|
* @returns ฮ(x); for +ve integer ฮ(x) = x!
|
|
106
|
-
*/
|
|
137
|
+
* */
|
|
138
|
+
|
|
107
139
|
declare function gamma(x: number): number;
|
|
108
140
|
/**
|
|
109
141
|
* Compute the natural logarithm of the absolute value of the gamma function of a number (log-ฮ).
|
|
142
|
+
* [๐](https://github.com/nodef/extra-math/wiki/lgamma)
|
|
110
143
|
* @param x a number
|
|
111
144
|
* @returns log(|ฮ(x)|)
|
|
112
|
-
*/
|
|
145
|
+
* */
|
|
146
|
+
|
|
113
147
|
declare function lgamma(x: number): number;
|
|
114
148
|
/**
|
|
115
149
|
* Find error function value of number (approximation).
|
|
150
|
+
* [๐](https://github.com/nodef/extra-math/wiki/erf)
|
|
116
151
|
* @param x a number
|
|
117
152
|
* @returns erf(x)
|
|
118
|
-
*/
|
|
153
|
+
* */
|
|
154
|
+
|
|
119
155
|
declare function erf(x: number): number;
|
|
120
156
|
/**
|
|
121
157
|
* Find the complementary error function value of number (approximation).
|
|
158
|
+
* [๐](https://github.com/nodef/extra-math/wiki/erfc)
|
|
122
159
|
* @param x a number
|
|
123
160
|
* @returns erfc(x)
|
|
124
|
-
*/
|
|
161
|
+
* */
|
|
162
|
+
|
|
125
163
|
declare function erfc(x: number): number;
|
|
126
164
|
/**
|
|
127
165
|
* Convert radians to degrees.
|
|
166
|
+
* [๐](https://github.com/nodef/extra-math/wiki/degrees)
|
|
128
167
|
* @param x radians
|
|
129
168
|
* @returns 2ฯ โ 360
|
|
130
|
-
*/
|
|
169
|
+
* */
|
|
170
|
+
|
|
131
171
|
declare function degrees(x: number): number;
|
|
132
172
|
/**
|
|
133
173
|
* Convert degrees to radians.
|
|
174
|
+
* [๐](https://github.com/nodef/extra-math/wiki/radians)
|
|
134
175
|
* @param x degrees
|
|
135
176
|
* @returns 360 โ 2ฯ
|
|
136
|
-
*/
|
|
177
|
+
* */
|
|
178
|
+
|
|
137
179
|
declare function radians(x: number): number;
|
|
138
180
|
/**
|
|
139
181
|
* Calculate the magnitude (length) of a vector.
|
|
182
|
+
* [๐](https://github.com/nodef/extra-math/wiki/magnitude)
|
|
140
183
|
* @param xs vector ([x, y, z, ...])
|
|
141
184
|
* @returns โ(xยฒ + yยฒ + zยฒ)
|
|
142
|
-
*/
|
|
185
|
+
* */
|
|
186
|
+
|
|
143
187
|
declare function magnitude(xs: number[]): number;
|
|
144
188
|
/**
|
|
145
189
|
* Calculate the distance between two points.
|
|
190
|
+
* [๐](https://github.com/nodef/extra-math/wiki/distance)
|
|
146
191
|
* @param xs first point ([x, y, z, ...])
|
|
147
192
|
* @param ys second point ([x, y, z, ...])
|
|
148
193
|
* @returns โ(ฮxยฒ + ฮyยฒ + ฮzยฒ)
|
|
149
|
-
*/
|
|
194
|
+
* */
|
|
195
|
+
|
|
150
196
|
declare function distance(xs: number[], ys: number[]): number;
|
|
151
197
|
/**
|
|
152
198
|
* Find the sum of numbers (ฮฃ).
|
|
199
|
+
* [๐](https://github.com/nodef/extra-math/wiki/sum)
|
|
153
200
|
* @param xs a list of numbers
|
|
154
201
|
* @returns ฮฃxแตข
|
|
155
|
-
*/
|
|
202
|
+
* */
|
|
203
|
+
|
|
156
204
|
declare function sum(...xs: number[]): number;
|
|
157
205
|
/**
|
|
158
206
|
* Find the product of numbers (โ).
|
|
207
|
+
* [๐](https://github.com/nodef/extra-math/wiki/product)
|
|
159
208
|
* @param xs a list of numbers
|
|
160
209
|
* @returns โxแตข
|
|
161
|
-
*/
|
|
210
|
+
* */
|
|
211
|
+
|
|
162
212
|
declare function product(...xs: number[]): number;
|
|
163
213
|
/**
|
|
164
214
|
* Find the average of numbers.
|
|
215
|
+
* [๐](https://github.com/nodef/extra-math/wiki/mean)
|
|
165
216
|
* @param xs a list of numbers
|
|
166
217
|
* @returns ฮฃxแตข/n | n = size(xs)
|
|
167
|
-
*/
|
|
218
|
+
* */
|
|
219
|
+
|
|
168
220
|
declare function mean(...xs: number[]): number;
|
|
169
221
|
/**
|
|
170
222
|
* Find the value separating the higher and lower halves of numbers.
|
|
223
|
+
* [๐](https://github.com/nodef/extra-math/wiki/median)
|
|
171
224
|
* @param xs a list of numbers
|
|
172
225
|
* @returns xโ | sort(xs) = [..., xโ, ...]
|
|
173
|
-
*/
|
|
226
|
+
* */
|
|
227
|
+
|
|
174
228
|
declare function median(...xs: number[]): number;
|
|
175
229
|
/**
|
|
176
230
|
* Find the values that appear most often.
|
|
231
|
+
* [๐](https://github.com/nodef/extra-math/wiki/modes)
|
|
177
232
|
* @param xs a list of numbers
|
|
178
233
|
* @returns [xโโ, xโโ, ...] | count(xโแตข) โฅ count(xแตข) โ xแตข โ xs
|
|
179
|
-
*/
|
|
234
|
+
* */
|
|
235
|
+
|
|
180
236
|
declare function modes(...xs: number[]): number[];
|
|
181
237
|
/**
|
|
182
238
|
* Find the difference between the largest and smallest values.
|
|
239
|
+
* [๐](https://github.com/nodef/extra-math/wiki/range)
|
|
183
240
|
* @param xs a list of numbers
|
|
184
241
|
* @returns max(xs) - min(xs)
|
|
185
|
-
*/
|
|
242
|
+
* */
|
|
243
|
+
|
|
186
244
|
declare function range(...xs: number[]): number;
|
|
187
245
|
/**
|
|
188
246
|
* Find the mean of squared deviation of numbers from its mean.
|
|
247
|
+
* [๐](https://github.com/nodef/extra-math/wiki/variance)
|
|
189
248
|
* @param xs a list of numbers
|
|
190
249
|
* @returns ฯยฒ = E[(xs - ยต)ยฒ] | ยต = mean(xs)
|
|
191
|
-
*/
|
|
250
|
+
* */
|
|
251
|
+
|
|
192
252
|
declare function variance(...xs: number[]): number;
|
|
193
253
|
|
|
194
|
-
export { binomial, constrain, degrees, distance, erf, erfc, factorial, gamma, gcd, lcm, lerp, lgamma, log, magnitude, map, mean, median, mod, modes, modp, multinomial, norm, product, radians, range, rem, root, sum, variance };
|
|
254
|
+
export { binomial, constrain as clamp, constrain, degrees, distance, erf, erfc, factorial, gamma, gcd, gcd as hcf, lcm, lerp, lgamma, log, magnitude, map, mean, median, mod, modes, modp, multinomial, norm, product, radians, range, rem, root, sum, variance };
|
package/index.js
CHANGED
|
@@ -205,6 +205,7 @@ function variance(...xs) {
|
|
|
205
205
|
}
|
|
206
206
|
|
|
207
207
|
exports.binomial = binomial;
|
|
208
|
+
exports.clamp = constrain;
|
|
208
209
|
exports.constrain = constrain;
|
|
209
210
|
exports.degrees = degrees;
|
|
210
211
|
exports.distance = distance;
|
|
@@ -213,6 +214,7 @@ exports.erfc = erfc;
|
|
|
213
214
|
exports.factorial = factorial;
|
|
214
215
|
exports.gamma = gamma;
|
|
215
216
|
exports.gcd = gcd;
|
|
217
|
+
exports.hcf = gcd;
|
|
216
218
|
exports.lcm = lcm;
|
|
217
219
|
exports.lerp = lerp;
|
|
218
220
|
exports.lgamma = lgamma;
|
package/index.mjs
CHANGED
|
@@ -200,4 +200,4 @@ function variance(...xs) {
|
|
|
200
200
|
return a / xs.length;
|
|
201
201
|
}
|
|
202
202
|
|
|
203
|
-
export { binomial, constrain, degrees, distance, erf, erfc, factorial, gamma, gcd, lcm, lerp, lgamma, log, magnitude, map, mean, median, mod, modes, modp, multinomial, norm, product, radians, range, rem, root, sum, variance };
|
|
203
|
+
export { binomial, constrain as clamp, constrain, degrees, distance, erf, erfc, factorial, gamma, gcd, gcd as hcf, lcm, lerp, lgamma, log, magnitude, map, mean, median, mod, modes, modp, multinomial, norm, product, radians, range, rem, root, sum, variance };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "extra-math",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.22",
|
|
4
4
|
"description": "A collection of common mathematical functions.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.mjs",
|
|
@@ -12,11 +12,14 @@
|
|
|
12
12
|
"scripts": {
|
|
13
13
|
"test": "exit",
|
|
14
14
|
"build": "node ./build",
|
|
15
|
-
"
|
|
15
|
+
"publish-docs": "node ./build publish-docs",
|
|
16
|
+
"publish-packages": "node ./build publish-packages"
|
|
16
17
|
},
|
|
17
18
|
"keywords": [
|
|
18
19
|
"extra",
|
|
19
20
|
"math",
|
|
21
|
+
"clamp",
|
|
22
|
+
"hcf",
|
|
20
23
|
"binomial",
|
|
21
24
|
"constrain",
|
|
22
25
|
"degrees",
|
|
@@ -60,7 +63,7 @@
|
|
|
60
63
|
"devDependencies": {
|
|
61
64
|
"@rollup/plugin-commonjs": "^22.0.1",
|
|
62
65
|
"@rollup/plugin-node-resolve": "^13.3.0",
|
|
63
|
-
"extra-build": "^2.
|
|
66
|
+
"extra-build": "^2.2.21",
|
|
64
67
|
"rollup-plugin-cleanup": "^3.2.1",
|
|
65
68
|
"rollup-plugin-dts": "^4.2.2"
|
|
66
69
|
}
|