extra-math 1.2.15 → 1.3.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/README.md +17 -0
- package/index.d.ts +27 -18
- package/index.js +8 -8
- package/index.mjs +8 -8
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -59,8 +59,25 @@ math.lcm(2, 3, 4);
|
|
|
59
59
|
<br>
|
|
60
60
|
<br>
|
|
61
61
|
|
|
62
|
+
|
|
63
|
+
## Reference
|
|
64
|
+
|
|
65
|
+
- [MathLib by @alawatthe](https://github.com/alawatthe/MathLib)
|
|
66
|
+
- [Processing Reference](https://processing.org/reference)
|
|
67
|
+
- [Modulo operation](https://en.wikipedia.org/wiki/Modulo_operation)
|
|
68
|
+
- [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)
|
|
69
|
+
- [Least common multiple](https://en.wikipedia.org/wiki/Least_common_multiple)
|
|
70
|
+
- [Permutation](https://en.wikipedia.org/wiki/Permutation)
|
|
71
|
+
- [Binomial coefficient](https://en.wikipedia.org/wiki/Binomial_coefficient)
|
|
72
|
+
- [Multinomial distribution](https://en.wikipedia.org/wiki/Multinomial_distribution)
|
|
73
|
+
|
|
74
|
+
<br>
|
|
75
|
+
<br>
|
|
76
|
+
|
|
77
|
+
|
|
62
78
|
[](https://www.youtube.com/watch?v=dW8Cy6WrO94)
|
|
63
79
|
|
|
80
|
+
|
|
64
81
|
[(1)]: https://en.wikipedia.org/wiki/Walter_Warwick_Sawyer
|
|
65
82
|
[sum]: https://github.com/nodef/extra-math/wiki/sum
|
|
66
83
|
[product]: https://github.com/nodef/extra-math/wiki/product
|
package/index.d.ts
CHANGED
|
@@ -48,7 +48,7 @@ declare function binomial(n: number, k: number): number;
|
|
|
48
48
|
/**
|
|
49
49
|
* Find the number of ways to put n objects in m bins (n=sum(kᵢ)).
|
|
50
50
|
* @param ks objects per bin (kᵢ)
|
|
51
|
-
* @returns n!/(k₁!k₂!...)
|
|
51
|
+
* @returns n!/(k₁!k₂!...) | n=sum(kᵢ)
|
|
52
52
|
*/
|
|
53
53
|
declare function multinomial(...ks: number[]): number;
|
|
54
54
|
/**
|
|
@@ -69,44 +69,46 @@ declare function root(x: number, n: number): number;
|
|
|
69
69
|
/**
|
|
70
70
|
* Find the logarithm of a number with a given base.
|
|
71
71
|
* @param x a number
|
|
72
|
-
* @param b logarithm base
|
|
72
|
+
* @param b logarithm base [e]
|
|
73
73
|
* @returns log_b (x)
|
|
74
74
|
*/
|
|
75
|
-
declare function
|
|
75
|
+
declare function log(x: number, b?: number): number;
|
|
76
76
|
/**
|
|
77
77
|
* Normalize a number from its current range into a value between 0 and 1.
|
|
78
78
|
* @param x a number
|
|
79
|
-
* @param
|
|
80
|
-
* @param
|
|
79
|
+
* @param r lower bound of current range
|
|
80
|
+
* @param R upper bound of current range
|
|
81
81
|
* @returns ∈ [0, 1]
|
|
82
82
|
*/
|
|
83
|
-
declare function norm(x: number,
|
|
83
|
+
declare function norm(x: number, r: number, R: number): number;
|
|
84
84
|
/**
|
|
85
85
|
* Re-map a number from one range to another.
|
|
86
86
|
* @param x a number
|
|
87
|
-
* @param
|
|
88
|
-
* @param
|
|
89
|
-
* @param
|
|
90
|
-
* @param
|
|
87
|
+
* @param r lower bound of current range
|
|
88
|
+
* @param R upper bound of current range
|
|
89
|
+
* @param t lower bound of target range
|
|
90
|
+
* @param T upper bound of target range
|
|
91
91
|
* @returns ∈ [ymin, ymax]
|
|
92
92
|
*/
|
|
93
|
-
declare function map(x: number,
|
|
93
|
+
declare function map(x: number, r: number, R: number, t: number, T: number): number;
|
|
94
94
|
/**
|
|
95
|
-
*
|
|
96
|
-
* @param
|
|
97
|
-
* @param
|
|
98
|
-
* @param
|
|
99
|
-
* @returns ∈ [
|
|
95
|
+
* Linearly interpolate a number between two numbers.
|
|
96
|
+
* @param x start number
|
|
97
|
+
* @param y stop number
|
|
98
|
+
* @param t interpolant ∈ [0, 1]
|
|
99
|
+
* @returns ∈ [x, y]
|
|
100
100
|
*/
|
|
101
|
-
declare function lerp(
|
|
101
|
+
declare function lerp(x: number, y: number, t: number): number;
|
|
102
102
|
/**
|
|
103
103
|
* Convert radians to degrees.
|
|
104
104
|
* @param x radians
|
|
105
|
+
* @returns 2π → 360
|
|
105
106
|
*/
|
|
106
107
|
declare function degrees(x: number): number;
|
|
107
108
|
/**
|
|
108
109
|
* Convert degrees to radians.
|
|
109
110
|
* @param x degrees
|
|
111
|
+
* @returns 360 → 2π
|
|
110
112
|
*/
|
|
111
113
|
declare function radians(x: number): number;
|
|
112
114
|
/**
|
|
@@ -131,36 +133,43 @@ declare function dist(x1: number, y1: number, z1: number, x2: number, y2: number
|
|
|
131
133
|
/**
|
|
132
134
|
* Find the sum of numbers (Σ).
|
|
133
135
|
* @param xs a list of numbers
|
|
136
|
+
* @returns Σxᵢ
|
|
134
137
|
*/
|
|
135
138
|
declare function sum(...xs: number[]): number;
|
|
136
139
|
/**
|
|
137
140
|
* Find the product of numbers (∏).
|
|
138
141
|
* @param xs a list of numbers
|
|
142
|
+
* @returns ∏xᵢ
|
|
139
143
|
*/
|
|
140
144
|
declare function product(...xs: number[]): number;
|
|
141
145
|
/**
|
|
142
146
|
* Find the average of numbers.
|
|
143
147
|
* @param xs a list of numbers
|
|
148
|
+
* @returns Σxᵢ/n | n = size(xs)
|
|
144
149
|
*/
|
|
145
150
|
declare function mean(...xs: number[]): number;
|
|
146
151
|
/**
|
|
147
152
|
* Find the value separating the higher and lower halves of numbers.
|
|
148
153
|
* @param xs a list of numbers
|
|
154
|
+
* @returns xₘ | sort(xs) = [..., xₘ, ...]
|
|
149
155
|
*/
|
|
150
156
|
declare function median(...xs: number[]): number;
|
|
151
157
|
/**
|
|
152
158
|
* Find the values that appear most often.
|
|
153
159
|
* @param xs a list of numbers
|
|
160
|
+
* @returns [xₘ₁, xₘ₂, ...] | count(xₘᵢ) ≥ count(xᵢ) ∀ xᵢ ∈ xs
|
|
154
161
|
*/
|
|
155
162
|
declare function modes(...xs: number[]): number[];
|
|
156
163
|
/**
|
|
157
164
|
* Find the difference between the largest and smallest values.
|
|
158
165
|
* @param xs a list of numbers
|
|
166
|
+
* @returns max(xs) - min(xs)
|
|
159
167
|
*/
|
|
160
168
|
declare function range(...xs: number[]): number;
|
|
161
169
|
/**
|
|
162
170
|
* Find the mean of squared deviation of numbers from its mean.
|
|
163
171
|
* @param xs a list of numbers
|
|
172
|
+
* @returns σ² = E[(xs - µ)²] | µ = mean(xs)
|
|
164
173
|
*/
|
|
165
174
|
declare function variance(...xs: number[]): number;
|
|
166
175
|
/**
|
|
@@ -174,4 +183,4 @@ declare function erf(x: number): number;
|
|
|
174
183
|
*/
|
|
175
184
|
declare function erfc(x: number): number;
|
|
176
185
|
|
|
177
|
-
export { binomial, constrain, degrees, dist, erf, erfc, factorial, gcd, lcm, lerp,
|
|
186
|
+
export { binomial, constrain, degrees, dist, erf, erfc, factorial, gcd, lcm, lerp, log, mag, map, mean, median, mod, modes, modp, multinomial, norm, product, radians, range, rem, root, sum, variance };
|
package/index.js
CHANGED
|
@@ -61,17 +61,17 @@ function constrain(x, min, max) {
|
|
|
61
61
|
function root(x, n) {
|
|
62
62
|
return Math.pow(x, 1 / n);
|
|
63
63
|
}
|
|
64
|
-
function
|
|
64
|
+
function log(x, b = Math.E) {
|
|
65
65
|
return Math.log(x) / Math.log(b);
|
|
66
66
|
}
|
|
67
|
-
function norm(x,
|
|
68
|
-
return (x -
|
|
67
|
+
function norm(x, r, R) {
|
|
68
|
+
return (x - r) / (R - r);
|
|
69
69
|
}
|
|
70
|
-
function map(x,
|
|
71
|
-
return
|
|
70
|
+
function map(x, r, R, t, T) {
|
|
71
|
+
return t + ((x - r) / (R - r)) * (T - t);
|
|
72
72
|
}
|
|
73
|
-
function lerp(
|
|
74
|
-
return
|
|
73
|
+
function lerp(x, y, t) {
|
|
74
|
+
return x + t * (y - x);
|
|
75
75
|
}
|
|
76
76
|
function degrees(x) {
|
|
77
77
|
return x * (180 / Math.PI);
|
|
@@ -194,7 +194,7 @@ exports.factorial = factorial;
|
|
|
194
194
|
exports.gcd = gcd;
|
|
195
195
|
exports.lcm = lcm;
|
|
196
196
|
exports.lerp = lerp;
|
|
197
|
-
exports.
|
|
197
|
+
exports.log = log;
|
|
198
198
|
exports.mag = mag;
|
|
199
199
|
exports.map = map;
|
|
200
200
|
exports.mean = mean;
|
package/index.mjs
CHANGED
|
@@ -57,17 +57,17 @@ function constrain(x, min, max) {
|
|
|
57
57
|
function root(x, n) {
|
|
58
58
|
return Math.pow(x, 1 / n);
|
|
59
59
|
}
|
|
60
|
-
function
|
|
60
|
+
function log(x, b = Math.E) {
|
|
61
61
|
return Math.log(x) / Math.log(b);
|
|
62
62
|
}
|
|
63
|
-
function norm(x,
|
|
64
|
-
return (x -
|
|
63
|
+
function norm(x, r, R) {
|
|
64
|
+
return (x - r) / (R - r);
|
|
65
65
|
}
|
|
66
|
-
function map(x,
|
|
67
|
-
return
|
|
66
|
+
function map(x, r, R, t, T) {
|
|
67
|
+
return t + ((x - r) / (R - r)) * (T - t);
|
|
68
68
|
}
|
|
69
|
-
function lerp(
|
|
70
|
-
return
|
|
69
|
+
function lerp(x, y, t) {
|
|
70
|
+
return x + t * (y - x);
|
|
71
71
|
}
|
|
72
72
|
function degrees(x) {
|
|
73
73
|
return x * (180 / Math.PI);
|
|
@@ -180,4 +180,4 @@ function erfc(x) {
|
|
|
180
180
|
return y * Math.exp(-x * x + 0.5 * (ERFC_TABLE[I] + z * d) - c);
|
|
181
181
|
}
|
|
182
182
|
|
|
183
|
-
export { binomial, constrain, degrees, dist, erf, erfc, factorial, gcd, lcm, lerp,
|
|
183
|
+
export { binomial, constrain, degrees, dist, erf, erfc, factorial, gcd, lcm, lerp, log, mag, 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
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "Mathematics is the classification and study of all possible patterns.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.mjs",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"gcd",
|
|
28
28
|
"lcm",
|
|
29
29
|
"lerp",
|
|
30
|
-
"
|
|
30
|
+
"log",
|
|
31
31
|
"mag",
|
|
32
32
|
"map",
|
|
33
33
|
"mean",
|