extra-math 1.3.11 → 1.3.14
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 +4 -5
- package/index.d.ts +17 -17
- package/index.js +14 -11
- package/index.mjs +13 -10
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -24,16 +24,16 @@ const math = require('extra-math');
|
|
|
24
24
|
// import * as math from "https://unpkg.com/extra-math/index.mjs"; (deno)
|
|
25
25
|
|
|
26
26
|
math.sum(1, 2, 3, 4);
|
|
27
|
-
// 10
|
|
27
|
+
// → 10
|
|
28
28
|
|
|
29
29
|
math.median(1, 7, 8);
|
|
30
|
-
// 7
|
|
30
|
+
// → 7
|
|
31
31
|
|
|
32
32
|
math.variance(1, 2, 3, 4);
|
|
33
|
-
// 1.25
|
|
33
|
+
// → 1.25
|
|
34
34
|
|
|
35
35
|
math.lcm(2, 3, 4);
|
|
36
|
-
// 12
|
|
36
|
+
// → 12
|
|
37
37
|
```
|
|
38
38
|
|
|
39
39
|
<br>
|
|
@@ -101,7 +101,6 @@ math.lcm(2, 3, 4);
|
|
|
101
101
|
[](https://www.youtube.com/watch?v=dW8Cy6WrO94)
|
|
102
102
|
|
|
103
103
|
|
|
104
|
-
[a]: https://nodef.github.io/extra-math/modules.html#sum
|
|
105
104
|
[rem]: https://nodef.github.io/extra-math/modules.html#rem
|
|
106
105
|
[mod]: https://nodef.github.io/extra-math/modules.html#mod
|
|
107
106
|
[modp]: https://nodef.github.io/extra-math/modules.html#modp
|
package/index.d.ts
CHANGED
|
@@ -59,20 +59,6 @@ declare function multinomial(...ks: number[]): number;
|
|
|
59
59
|
* @returns x<min: min, x>max: max, x
|
|
60
60
|
*/
|
|
61
61
|
declare function constrain(x: number, min: number, max: number): number;
|
|
62
|
-
/**
|
|
63
|
-
* Find the nth root of a number (ⁿ√).
|
|
64
|
-
* @param x a number
|
|
65
|
-
* @param n root
|
|
66
|
-
* @returns ⁿ√x
|
|
67
|
-
*/
|
|
68
|
-
declare function root(x: number, n: number): number;
|
|
69
|
-
/**
|
|
70
|
-
* Find the logarithm of a number with a given base.
|
|
71
|
-
* @param x a number
|
|
72
|
-
* @param b logarithm base [e]
|
|
73
|
-
* @returns log_b (x)
|
|
74
|
-
*/
|
|
75
|
-
declare function log(x: number, b?: number): number;
|
|
76
62
|
/**
|
|
77
63
|
* Normalize a number from its current range into a value between 0 and 1.
|
|
78
64
|
* @param x a number
|
|
@@ -99,6 +85,20 @@ declare function map(x: number, r: number, R: number, t: number, T: number): num
|
|
|
99
85
|
* @returns ∈ [x, y]
|
|
100
86
|
*/
|
|
101
87
|
declare function lerp(x: number, y: number, t: number): number;
|
|
88
|
+
/**
|
|
89
|
+
* Find the nth root of a number (ⁿ√).
|
|
90
|
+
* @param x a number
|
|
91
|
+
* @param n root
|
|
92
|
+
* @returns ⁿ√x
|
|
93
|
+
*/
|
|
94
|
+
declare function root(x: number, n: number): number;
|
|
95
|
+
/**
|
|
96
|
+
* Find the logarithm of a number with a given base.
|
|
97
|
+
* @param x a number
|
|
98
|
+
* @param b logarithm base [e]
|
|
99
|
+
* @returns log_b (x)
|
|
100
|
+
*/
|
|
101
|
+
declare function log(x: number, b?: number): number;
|
|
102
102
|
/**
|
|
103
103
|
* Compute the gamma function of a number (Γ).
|
|
104
104
|
* @param x a number
|
|
@@ -140,14 +140,14 @@ declare function radians(x: number): number;
|
|
|
140
140
|
* @param xs vector ([x, y, z, ...])
|
|
141
141
|
* @returns √(x² + y² + z²)
|
|
142
142
|
*/
|
|
143
|
-
declare function
|
|
143
|
+
declare function magnitude(xs: number[]): number;
|
|
144
144
|
/**
|
|
145
145
|
* Calculate the distance between two points.
|
|
146
146
|
* @param xs first point ([x, y, z, ...])
|
|
147
147
|
* @param ys second point ([x, y, z, ...])
|
|
148
148
|
* @returns √(Δx² + Δy² + Δz²)
|
|
149
149
|
*/
|
|
150
|
-
declare function
|
|
150
|
+
declare function distance(xs: number[], ys: number[]): number;
|
|
151
151
|
/**
|
|
152
152
|
* Find the sum of numbers (Σ).
|
|
153
153
|
* @param xs a list of numbers
|
|
@@ -191,4 +191,4 @@ declare function range(...xs: number[]): number;
|
|
|
191
191
|
*/
|
|
192
192
|
declare function variance(...xs: number[]): number;
|
|
193
193
|
|
|
194
|
-
export { binomial, constrain, degrees,
|
|
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 };
|
package/index.js
CHANGED
|
@@ -26,7 +26,10 @@ function gcd(...xs) {
|
|
|
26
26
|
return a;
|
|
27
27
|
}
|
|
28
28
|
function lcm(...xs) {
|
|
29
|
-
|
|
29
|
+
var a = xs[0] || 1;
|
|
30
|
+
for (var i = 1, I = xs.length; i < I; i++)
|
|
31
|
+
a = a * xs[i] / gcdPair(a, xs[i]);
|
|
32
|
+
return a;
|
|
30
33
|
}
|
|
31
34
|
function factorial(n, k = 0) {
|
|
32
35
|
if (n < 0)
|
|
@@ -58,12 +61,6 @@ function multinomial(...ks) {
|
|
|
58
61
|
function constrain(x, min, max) {
|
|
59
62
|
return Math.min(Math.max(x, min), max);
|
|
60
63
|
}
|
|
61
|
-
function root(x, n) {
|
|
62
|
-
return Math.pow(x, 1 / n);
|
|
63
|
-
}
|
|
64
|
-
function log(x, b = Math.E) {
|
|
65
|
-
return Math.log(x) / Math.log(b);
|
|
66
|
-
}
|
|
67
64
|
function norm(x, r, R) {
|
|
68
65
|
return (x - r) / (R - r);
|
|
69
66
|
}
|
|
@@ -73,6 +70,12 @@ function map(x, r, R, t, T) {
|
|
|
73
70
|
function lerp(x, y, t) {
|
|
74
71
|
return x + t * (y - x);
|
|
75
72
|
}
|
|
73
|
+
function root(x, n) {
|
|
74
|
+
return Math.pow(x, 1 / n);
|
|
75
|
+
}
|
|
76
|
+
function log(x, b = Math.E) {
|
|
77
|
+
return Math.log(x) / Math.log(b);
|
|
78
|
+
}
|
|
76
79
|
function gamma(x) {
|
|
77
80
|
var x = x - 1;
|
|
78
81
|
var e1 = Math.sqrt(2 * Math.PI * x);
|
|
@@ -126,13 +129,13 @@ function degrees(x) {
|
|
|
126
129
|
function radians(x) {
|
|
127
130
|
return x * (Math.PI / 180);
|
|
128
131
|
}
|
|
129
|
-
function
|
|
132
|
+
function magnitude(xs) {
|
|
130
133
|
var a = 0;
|
|
131
134
|
for (var i = 0, I = xs.length; i < I; i++)
|
|
132
135
|
a += xs[i] ** 2;
|
|
133
136
|
return Math.sqrt(a);
|
|
134
137
|
}
|
|
135
|
-
function
|
|
138
|
+
function distance(xs, ys) {
|
|
136
139
|
var a = 0;
|
|
137
140
|
for (var i = 0, I = xs.length; i < I; i++)
|
|
138
141
|
a += (xs[i] - ys[i]) ** 2;
|
|
@@ -204,7 +207,7 @@ function variance(...xs) {
|
|
|
204
207
|
exports.binomial = binomial;
|
|
205
208
|
exports.constrain = constrain;
|
|
206
209
|
exports.degrees = degrees;
|
|
207
|
-
exports.
|
|
210
|
+
exports.distance = distance;
|
|
208
211
|
exports.erf = erf;
|
|
209
212
|
exports.erfc = erfc;
|
|
210
213
|
exports.factorial = factorial;
|
|
@@ -214,7 +217,7 @@ exports.lcm = lcm;
|
|
|
214
217
|
exports.lerp = lerp;
|
|
215
218
|
exports.lgamma = lgamma;
|
|
216
219
|
exports.log = log;
|
|
217
|
-
exports.
|
|
220
|
+
exports.magnitude = magnitude;
|
|
218
221
|
exports.map = map;
|
|
219
222
|
exports.mean = mean;
|
|
220
223
|
exports.median = median;
|
package/index.mjs
CHANGED
|
@@ -22,7 +22,10 @@ function gcd(...xs) {
|
|
|
22
22
|
return a;
|
|
23
23
|
}
|
|
24
24
|
function lcm(...xs) {
|
|
25
|
-
|
|
25
|
+
var a = xs[0] || 1;
|
|
26
|
+
for (var i = 1, I = xs.length; i < I; i++)
|
|
27
|
+
a = a * xs[i] / gcdPair(a, xs[i]);
|
|
28
|
+
return a;
|
|
26
29
|
}
|
|
27
30
|
function factorial(n, k = 0) {
|
|
28
31
|
if (n < 0)
|
|
@@ -54,12 +57,6 @@ function multinomial(...ks) {
|
|
|
54
57
|
function constrain(x, min, max) {
|
|
55
58
|
return Math.min(Math.max(x, min), max);
|
|
56
59
|
}
|
|
57
|
-
function root(x, n) {
|
|
58
|
-
return Math.pow(x, 1 / n);
|
|
59
|
-
}
|
|
60
|
-
function log(x, b = Math.E) {
|
|
61
|
-
return Math.log(x) / Math.log(b);
|
|
62
|
-
}
|
|
63
60
|
function norm(x, r, R) {
|
|
64
61
|
return (x - r) / (R - r);
|
|
65
62
|
}
|
|
@@ -69,6 +66,12 @@ function map(x, r, R, t, T) {
|
|
|
69
66
|
function lerp(x, y, t) {
|
|
70
67
|
return x + t * (y - x);
|
|
71
68
|
}
|
|
69
|
+
function root(x, n) {
|
|
70
|
+
return Math.pow(x, 1 / n);
|
|
71
|
+
}
|
|
72
|
+
function log(x, b = Math.E) {
|
|
73
|
+
return Math.log(x) / Math.log(b);
|
|
74
|
+
}
|
|
72
75
|
function gamma(x) {
|
|
73
76
|
var x = x - 1;
|
|
74
77
|
var e1 = Math.sqrt(2 * Math.PI * x);
|
|
@@ -122,13 +125,13 @@ function degrees(x) {
|
|
|
122
125
|
function radians(x) {
|
|
123
126
|
return x * (Math.PI / 180);
|
|
124
127
|
}
|
|
125
|
-
function
|
|
128
|
+
function magnitude(xs) {
|
|
126
129
|
var a = 0;
|
|
127
130
|
for (var i = 0, I = xs.length; i < I; i++)
|
|
128
131
|
a += xs[i] ** 2;
|
|
129
132
|
return Math.sqrt(a);
|
|
130
133
|
}
|
|
131
|
-
function
|
|
134
|
+
function distance(xs, ys) {
|
|
132
135
|
var a = 0;
|
|
133
136
|
for (var i = 0, I = xs.length; i < I; i++)
|
|
134
137
|
a += (xs[i] - ys[i]) ** 2;
|
|
@@ -197,4 +200,4 @@ function variance(...xs) {
|
|
|
197
200
|
return a / xs.length;
|
|
198
201
|
}
|
|
199
202
|
|
|
200
|
-
export { binomial, constrain, degrees,
|
|
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 };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "extra-math",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.14",
|
|
4
4
|
"description": "Mathematics is the classification and study of all possible patterns.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.mjs",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"binomial",
|
|
21
21
|
"constrain",
|
|
22
22
|
"degrees",
|
|
23
|
-
"
|
|
23
|
+
"distance",
|
|
24
24
|
"erf",
|
|
25
25
|
"erfc",
|
|
26
26
|
"factorial",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"lerp",
|
|
31
31
|
"lgamma",
|
|
32
32
|
"log",
|
|
33
|
-
"
|
|
33
|
+
"magnitude",
|
|
34
34
|
"map",
|
|
35
35
|
"mean",
|
|
36
36
|
"median",
|