extra-math 1.3.13 → 1.3.16
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 +32 -8
- package/index.d.ts +17 -17
- package/index.js +10 -10
- package/index.mjs +9 -9
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,11 +1,34 @@
|
|
|
1
|
-
|
|
1
|
+
A collection of common mathematical functions.<br>
|
|
2
2
|
📦 [Node.js](https://www.npmjs.com/package/extra-math),
|
|
3
3
|
🌐 [Web](https://www.npmjs.com/package/extra-math.web),
|
|
4
4
|
📜 [Files](https://unpkg.com/extra-math/),
|
|
5
5
|
📰 [JSDoc](https://nodef.github.io/extra-math/),
|
|
6
6
|
📘 [Wiki](https://github.com/nodef/extra-math/wiki/).
|
|
7
7
|
|
|
8
|
-
Mathematics is the classification and study of all possible patterns. [(1)]
|
|
8
|
+
Mathematics is the classification and study of all possible patterns. [(1)] This
|
|
9
|
+
package includes common mathematical functions related to *natural numbers*, *real*
|
|
10
|
+
*numbers*, *geometry*, and *statistics*.
|
|
11
|
+
|
|
12
|
+
**Natural numbers**: There are 3 different ways of performing the *modulo*
|
|
13
|
+
operation: [rem], [mod], and [modp]. [gcd]/`HCF` and [lcm] of a list of numbers
|
|
14
|
+
can be obtained. The calculate the number of ways of *ordering items*, use
|
|
15
|
+
[factorial]/`P(n, k)`, [binomial]/`C(n, k)`, or [multinomial]/`n!/k₁!k₂!...`.
|
|
16
|
+
|
|
17
|
+
**Real numbers**: *Range* of a number can be controlled with [constrain],
|
|
18
|
+
[norm], or [map]. Use [lerp] for *linear interpolation* (or extrapolation);
|
|
19
|
+
[root] for calculating the *n-th root* of a number; and [log] to find the
|
|
20
|
+
*logarithm* of a number with a given base. Results of *special mathematical
|
|
21
|
+
functions* (approximations) for a given number can be obtained with [gamma],
|
|
22
|
+
[lgamma], [erf], and [erfc].
|
|
23
|
+
|
|
24
|
+
**Geometry**: Perform conversion from [degrees] to [radians] and vice versa.
|
|
25
|
+
Find the [magnitude] of a vector or [distance] between two points.
|
|
26
|
+
|
|
27
|
+
**Statistics**: For a list of numbers, we can calculate the [sum], [product],
|
|
28
|
+
[mean]. [median] gives the value lying in the middle when the numbers are
|
|
29
|
+
sorted, and [modes] gives the values which are repeated most often. The
|
|
30
|
+
difference between the largest and the smallest values is the [range].
|
|
31
|
+
[variance] is a measure of variability of numbers.
|
|
9
32
|
|
|
10
33
|
This package is available in both *Node.js* and *Web* formats. The web format is
|
|
11
34
|
exposed as `extra_math` standalone variable and can be loaded from [jsDelivr CDN].
|
|
@@ -54,11 +77,11 @@ math.lcm(2, 3, 4);
|
|
|
54
77
|
| [multinomial] | Find the number of ways to put n objects in m bins (n=sum(kᵢ)). |
|
|
55
78
|
| | |
|
|
56
79
|
| [constrain] | Constrain a number within a minimum and a maximum value. |
|
|
57
|
-
| [root] | Find the nth root of a number (ⁿ√). |
|
|
58
|
-
| [log] | Find the logarithm of a number with a given base. |
|
|
59
80
|
| [norm] | Normalize a number from its current range into a value between 0 and 1. |
|
|
60
81
|
| [map] | Re-map a number from one range to another. |
|
|
61
82
|
| [lerp] | Linearly interpolate a number between two numbers. |
|
|
83
|
+
| [root] | Find the nth root of a number (ⁿ√). |
|
|
84
|
+
| [log] | Find the logarithm of a number with a given base. |
|
|
62
85
|
| [gamma] | Compute the gamma function of a number (Γ). |
|
|
63
86
|
| [lgamma] | Compute the natural logarithm of the absolute value of the gamma function of a number (log-Γ). |
|
|
64
87
|
| [erf] | Find error function value of number (approximation). |
|
|
@@ -66,8 +89,8 @@ math.lcm(2, 3, 4);
|
|
|
66
89
|
| | |
|
|
67
90
|
| [degrees] | Convert radians to degrees. |
|
|
68
91
|
| [radians] | Convert degrees to radians. |
|
|
69
|
-
| [
|
|
70
|
-
| [
|
|
92
|
+
| [magnitude] | Calculate the magnitude (length) of a vector. |
|
|
93
|
+
| [distance] | Calculate the distance between two points. |
|
|
71
94
|
| | |
|
|
72
95
|
| [sum] | Find the sum of numbers (Σ). |
|
|
73
96
|
| [product] | Find the product of numbers (∏). |
|
|
@@ -93,6 +116,7 @@ math.lcm(2, 3, 4);
|
|
|
93
116
|
- [Permutation](https://en.wikipedia.org/wiki/Permutation)
|
|
94
117
|
- [Binomial coefficient](https://en.wikipedia.org/wiki/Binomial_coefficient)
|
|
95
118
|
- [Multinomial distribution](https://en.wikipedia.org/wiki/Multinomial_distribution)
|
|
119
|
+
- [Conventional commits](https://www.conventionalcommits.org/en/v1.0.0-beta.2/)
|
|
96
120
|
|
|
97
121
|
<br>
|
|
98
122
|
<br>
|
|
@@ -121,8 +145,8 @@ math.lcm(2, 3, 4);
|
|
|
121
145
|
[erfc]: https://nodef.github.io/extra-math/modules.html#erfc
|
|
122
146
|
[degrees]: https://nodef.github.io/extra-math/modules.html#degrees
|
|
123
147
|
[radians]: https://nodef.github.io/extra-math/modules.html#radians
|
|
124
|
-
[
|
|
125
|
-
[
|
|
148
|
+
[magnitude]: https://nodef.github.io/extra-math/modules.html#magnitude
|
|
149
|
+
[distance]: https://nodef.github.io/extra-math/modules.html#distance
|
|
126
150
|
[sum]: https://nodef.github.io/extra-math/modules.html#sum
|
|
127
151
|
[product]: https://nodef.github.io/extra-math/modules.html#product
|
|
128
152
|
[mean]: https://nodef.github.io/extra-math/modules.html#mean
|
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
|
@@ -61,12 +61,6 @@ function multinomial(...ks) {
|
|
|
61
61
|
function constrain(x, min, max) {
|
|
62
62
|
return Math.min(Math.max(x, min), max);
|
|
63
63
|
}
|
|
64
|
-
function root(x, n) {
|
|
65
|
-
return Math.pow(x, 1 / n);
|
|
66
|
-
}
|
|
67
|
-
function log(x, b = Math.E) {
|
|
68
|
-
return Math.log(x) / Math.log(b);
|
|
69
|
-
}
|
|
70
64
|
function norm(x, r, R) {
|
|
71
65
|
return (x - r) / (R - r);
|
|
72
66
|
}
|
|
@@ -76,6 +70,12 @@ function map(x, r, R, t, T) {
|
|
|
76
70
|
function lerp(x, y, t) {
|
|
77
71
|
return x + t * (y - x);
|
|
78
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
|
+
}
|
|
79
79
|
function gamma(x) {
|
|
80
80
|
var x = x - 1;
|
|
81
81
|
var e1 = Math.sqrt(2 * Math.PI * x);
|
|
@@ -129,13 +129,13 @@ function degrees(x) {
|
|
|
129
129
|
function radians(x) {
|
|
130
130
|
return x * (Math.PI / 180);
|
|
131
131
|
}
|
|
132
|
-
function
|
|
132
|
+
function magnitude(xs) {
|
|
133
133
|
var a = 0;
|
|
134
134
|
for (var i = 0, I = xs.length; i < I; i++)
|
|
135
135
|
a += xs[i] ** 2;
|
|
136
136
|
return Math.sqrt(a);
|
|
137
137
|
}
|
|
138
|
-
function
|
|
138
|
+
function distance(xs, ys) {
|
|
139
139
|
var a = 0;
|
|
140
140
|
for (var i = 0, I = xs.length; i < I; i++)
|
|
141
141
|
a += (xs[i] - ys[i]) ** 2;
|
|
@@ -207,7 +207,7 @@ function variance(...xs) {
|
|
|
207
207
|
exports.binomial = binomial;
|
|
208
208
|
exports.constrain = constrain;
|
|
209
209
|
exports.degrees = degrees;
|
|
210
|
-
exports.
|
|
210
|
+
exports.distance = distance;
|
|
211
211
|
exports.erf = erf;
|
|
212
212
|
exports.erfc = erfc;
|
|
213
213
|
exports.factorial = factorial;
|
|
@@ -217,7 +217,7 @@ exports.lcm = lcm;
|
|
|
217
217
|
exports.lerp = lerp;
|
|
218
218
|
exports.lgamma = lgamma;
|
|
219
219
|
exports.log = log;
|
|
220
|
-
exports.
|
|
220
|
+
exports.magnitude = magnitude;
|
|
221
221
|
exports.map = map;
|
|
222
222
|
exports.mean = mean;
|
|
223
223
|
exports.median = median;
|
package/index.mjs
CHANGED
|
@@ -57,12 +57,6 @@ function multinomial(...ks) {
|
|
|
57
57
|
function constrain(x, min, max) {
|
|
58
58
|
return Math.min(Math.max(x, min), max);
|
|
59
59
|
}
|
|
60
|
-
function root(x, n) {
|
|
61
|
-
return Math.pow(x, 1 / n);
|
|
62
|
-
}
|
|
63
|
-
function log(x, b = Math.E) {
|
|
64
|
-
return Math.log(x) / Math.log(b);
|
|
65
|
-
}
|
|
66
60
|
function norm(x, r, R) {
|
|
67
61
|
return (x - r) / (R - r);
|
|
68
62
|
}
|
|
@@ -72,6 +66,12 @@ function map(x, r, R, t, T) {
|
|
|
72
66
|
function lerp(x, y, t) {
|
|
73
67
|
return x + t * (y - x);
|
|
74
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
|
+
}
|
|
75
75
|
function gamma(x) {
|
|
76
76
|
var x = x - 1;
|
|
77
77
|
var e1 = Math.sqrt(2 * Math.PI * x);
|
|
@@ -125,13 +125,13 @@ function degrees(x) {
|
|
|
125
125
|
function radians(x) {
|
|
126
126
|
return x * (Math.PI / 180);
|
|
127
127
|
}
|
|
128
|
-
function
|
|
128
|
+
function magnitude(xs) {
|
|
129
129
|
var a = 0;
|
|
130
130
|
for (var i = 0, I = xs.length; i < I; i++)
|
|
131
131
|
a += xs[i] ** 2;
|
|
132
132
|
return Math.sqrt(a);
|
|
133
133
|
}
|
|
134
|
-
function
|
|
134
|
+
function distance(xs, ys) {
|
|
135
135
|
var a = 0;
|
|
136
136
|
for (var i = 0, I = xs.length; i < I; i++)
|
|
137
137
|
a += (xs[i] - ys[i]) ** 2;
|
|
@@ -200,4 +200,4 @@ function variance(...xs) {
|
|
|
200
200
|
return a / xs.length;
|
|
201
201
|
}
|
|
202
202
|
|
|
203
|
-
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,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "extra-math",
|
|
3
|
-
"version": "1.3.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.3.16",
|
|
4
|
+
"description": "A collection of common mathematical functions.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.mjs",
|
|
7
7
|
"sideEffects": false,
|
|
@@ -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",
|