extra-math 1.2.16 → 1.3.2
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/index.d.ts +34 -31
- package/index.js +18 -12
- package/index.mjs +18 -12
- package/package.json +2 -2
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,98 +69,101 @@ 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
|
/**
|
|
113
|
-
*
|
|
114
|
-
* @param x
|
|
115
|
-
* @param y length on y-axis
|
|
116
|
-
* @param z length on x-axis
|
|
115
|
+
* Calculate the magnitude (length) of a vector.
|
|
116
|
+
* @param xs vector ([x, y, z, ...])
|
|
117
117
|
* @returns √(x² + y² + z²)
|
|
118
118
|
*/
|
|
119
|
-
declare function mag(
|
|
119
|
+
declare function mag(xs: number[]): number;
|
|
120
120
|
/**
|
|
121
|
-
*
|
|
122
|
-
* @param
|
|
123
|
-
* @param
|
|
124
|
-
* @param z1 z-coordinate of first point
|
|
125
|
-
* @param x2 x-coordinate of second point
|
|
126
|
-
* @param y2 y-coordinate of second point
|
|
127
|
-
* @param z2 z-coordinate of second point
|
|
121
|
+
* Calculate the distance between two points.
|
|
122
|
+
* @param xs first point ([x, y, z, ...])
|
|
123
|
+
* @param ys second point ([x, y, z, ...])
|
|
128
124
|
* @returns √(Δx² + Δy² + Δz²)
|
|
129
125
|
*/
|
|
130
|
-
declare function dist(
|
|
126
|
+
declare function dist(xs: number[], ys: number[]): number;
|
|
131
127
|
/**
|
|
132
128
|
* Find the sum of numbers (Σ).
|
|
133
129
|
* @param xs a list of numbers
|
|
130
|
+
* @returns Σxᵢ
|
|
134
131
|
*/
|
|
135
132
|
declare function sum(...xs: number[]): number;
|
|
136
133
|
/**
|
|
137
134
|
* Find the product of numbers (∏).
|
|
138
135
|
* @param xs a list of numbers
|
|
136
|
+
* @returns ∏xᵢ
|
|
139
137
|
*/
|
|
140
138
|
declare function product(...xs: number[]): number;
|
|
141
139
|
/**
|
|
142
140
|
* Find the average of numbers.
|
|
143
141
|
* @param xs a list of numbers
|
|
142
|
+
* @returns Σxᵢ/n | n = size(xs)
|
|
144
143
|
*/
|
|
145
144
|
declare function mean(...xs: number[]): number;
|
|
146
145
|
/**
|
|
147
146
|
* Find the value separating the higher and lower halves of numbers.
|
|
148
147
|
* @param xs a list of numbers
|
|
148
|
+
* @returns xₘ | sort(xs) = [..., xₘ, ...]
|
|
149
149
|
*/
|
|
150
150
|
declare function median(...xs: number[]): number;
|
|
151
151
|
/**
|
|
152
152
|
* Find the values that appear most often.
|
|
153
153
|
* @param xs a list of numbers
|
|
154
|
+
* @returns [xₘ₁, xₘ₂, ...] | count(xₘᵢ) ≥ count(xᵢ) ∀ xᵢ ∈ xs
|
|
154
155
|
*/
|
|
155
156
|
declare function modes(...xs: number[]): number[];
|
|
156
157
|
/**
|
|
157
158
|
* Find the difference between the largest and smallest values.
|
|
158
159
|
* @param xs a list of numbers
|
|
160
|
+
* @returns max(xs) - min(xs)
|
|
159
161
|
*/
|
|
160
162
|
declare function range(...xs: number[]): number;
|
|
161
163
|
/**
|
|
162
164
|
* Find the mean of squared deviation of numbers from its mean.
|
|
163
165
|
* @param xs a list of numbers
|
|
166
|
+
* @returns σ² = E[(xs - µ)²] | µ = mean(xs)
|
|
164
167
|
*/
|
|
165
168
|
declare function variance(...xs: number[]): number;
|
|
166
169
|
/**
|
|
@@ -174,4 +177,4 @@ declare function erf(x: number): number;
|
|
|
174
177
|
*/
|
|
175
178
|
declare function erfc(x: number): number;
|
|
176
179
|
|
|
177
|
-
export { binomial, constrain, degrees, dist, erf, erfc, factorial, gcd, lcm, lerp,
|
|
180
|
+
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);
|
|
@@ -79,11 +79,17 @@ function degrees(x) {
|
|
|
79
79
|
function radians(x) {
|
|
80
80
|
return x * (Math.PI / 180);
|
|
81
81
|
}
|
|
82
|
-
function mag(
|
|
83
|
-
|
|
82
|
+
function mag(xs) {
|
|
83
|
+
var a = 0;
|
|
84
|
+
for (var i = 0, I = xs.length; i < I; i++)
|
|
85
|
+
a += xs[i] ** 2;
|
|
86
|
+
return Math.sqrt(a);
|
|
84
87
|
}
|
|
85
|
-
function dist(
|
|
86
|
-
|
|
88
|
+
function dist(xs, ys) {
|
|
89
|
+
var a = 0;
|
|
90
|
+
for (var i = 0, I = xs.length; i < I; i++)
|
|
91
|
+
a += (xs[i] - ys[i]) ** 2;
|
|
92
|
+
return Math.sqrt(a);
|
|
87
93
|
}
|
|
88
94
|
function sum(...xs) {
|
|
89
95
|
var a = 0;
|
|
@@ -194,7 +200,7 @@ exports.factorial = factorial;
|
|
|
194
200
|
exports.gcd = gcd;
|
|
195
201
|
exports.lcm = lcm;
|
|
196
202
|
exports.lerp = lerp;
|
|
197
|
-
exports.
|
|
203
|
+
exports.log = log;
|
|
198
204
|
exports.mag = mag;
|
|
199
205
|
exports.map = map;
|
|
200
206
|
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);
|
|
@@ -75,11 +75,17 @@ function degrees(x) {
|
|
|
75
75
|
function radians(x) {
|
|
76
76
|
return x * (Math.PI / 180);
|
|
77
77
|
}
|
|
78
|
-
function mag(
|
|
79
|
-
|
|
78
|
+
function mag(xs) {
|
|
79
|
+
var a = 0;
|
|
80
|
+
for (var i = 0, I = xs.length; i < I; i++)
|
|
81
|
+
a += xs[i] ** 2;
|
|
82
|
+
return Math.sqrt(a);
|
|
80
83
|
}
|
|
81
|
-
function dist(
|
|
82
|
-
|
|
84
|
+
function dist(xs, ys) {
|
|
85
|
+
var a = 0;
|
|
86
|
+
for (var i = 0, I = xs.length; i < I; i++)
|
|
87
|
+
a += (xs[i] - ys[i]) ** 2;
|
|
88
|
+
return Math.sqrt(a);
|
|
83
89
|
}
|
|
84
90
|
function sum(...xs) {
|
|
85
91
|
var a = 0;
|
|
@@ -180,4 +186,4 @@ function erfc(x) {
|
|
|
180
186
|
return y * Math.exp(-x * x + 0.5 * (ERFC_TABLE[I] + z * d) - c);
|
|
181
187
|
}
|
|
182
188
|
|
|
183
|
-
export { binomial, constrain, degrees, dist, erf, erfc, factorial, gcd, lcm, lerp,
|
|
189
|
+
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.2
|
|
3
|
+
"version": "1.3.2",
|
|
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",
|