extra-math 1.3.0 → 1.3.3
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 +27 -14
- package/index.js +23 -4
- package/index.mjs +22 -5
- package/package.json +3 -1
package/index.d.ts
CHANGED
|
@@ -112,59 +112,72 @@ declare function degrees(x: number): number;
|
|
|
112
112
|
*/
|
|
113
113
|
declare function radians(x: number): number;
|
|
114
114
|
/**
|
|
115
|
-
*
|
|
116
|
-
* @param x
|
|
117
|
-
* @param y length on y-axis
|
|
118
|
-
* @param z length on x-axis
|
|
115
|
+
* Calculate the magnitude (length) of a vector.
|
|
116
|
+
* @param xs vector ([x, y, z, ...])
|
|
119
117
|
* @returns √(x² + y² + z²)
|
|
120
118
|
*/
|
|
121
|
-
declare function mag(
|
|
119
|
+
declare function mag(xs: number[]): number;
|
|
122
120
|
/**
|
|
123
|
-
*
|
|
124
|
-
* @param
|
|
125
|
-
* @param
|
|
126
|
-
* @param z1 z-coordinate of first point
|
|
127
|
-
* @param x2 x-coordinate of second point
|
|
128
|
-
* @param y2 y-coordinate of second point
|
|
129
|
-
* @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, ...])
|
|
130
124
|
* @returns √(Δx² + Δy² + Δz²)
|
|
131
125
|
*/
|
|
132
|
-
declare function dist(
|
|
126
|
+
declare function dist(xs: number[], ys: number[]): number;
|
|
133
127
|
/**
|
|
134
128
|
* Find the sum of numbers (Σ).
|
|
135
129
|
* @param xs a list of numbers
|
|
130
|
+
* @returns Σxᵢ
|
|
136
131
|
*/
|
|
137
132
|
declare function sum(...xs: number[]): number;
|
|
138
133
|
/**
|
|
139
134
|
* Find the product of numbers (∏).
|
|
140
135
|
* @param xs a list of numbers
|
|
136
|
+
* @returns ∏xᵢ
|
|
141
137
|
*/
|
|
142
138
|
declare function product(...xs: number[]): number;
|
|
143
139
|
/**
|
|
144
140
|
* Find the average of numbers.
|
|
145
141
|
* @param xs a list of numbers
|
|
142
|
+
* @returns Σxᵢ/n | n = size(xs)
|
|
146
143
|
*/
|
|
147
144
|
declare function mean(...xs: number[]): number;
|
|
148
145
|
/**
|
|
149
146
|
* Find the value separating the higher and lower halves of numbers.
|
|
150
147
|
* @param xs a list of numbers
|
|
148
|
+
* @returns xₘ | sort(xs) = [..., xₘ, ...]
|
|
151
149
|
*/
|
|
152
150
|
declare function median(...xs: number[]): number;
|
|
153
151
|
/**
|
|
154
152
|
* Find the values that appear most often.
|
|
155
153
|
* @param xs a list of numbers
|
|
154
|
+
* @returns [xₘ₁, xₘ₂, ...] | count(xₘᵢ) ≥ count(xᵢ) ∀ xᵢ ∈ xs
|
|
156
155
|
*/
|
|
157
156
|
declare function modes(...xs: number[]): number[];
|
|
158
157
|
/**
|
|
159
158
|
* Find the difference between the largest and smallest values.
|
|
160
159
|
* @param xs a list of numbers
|
|
160
|
+
* @returns max(xs) - min(xs)
|
|
161
161
|
*/
|
|
162
162
|
declare function range(...xs: number[]): number;
|
|
163
163
|
/**
|
|
164
164
|
* Find the mean of squared deviation of numbers from its mean.
|
|
165
165
|
* @param xs a list of numbers
|
|
166
|
+
* @returns σ² = E[(xs - µ)²] | µ = mean(xs)
|
|
166
167
|
*/
|
|
167
168
|
declare function variance(...xs: number[]): number;
|
|
169
|
+
/**
|
|
170
|
+
* Compute the gamma function of a number (Γ).
|
|
171
|
+
* @param x a number
|
|
172
|
+
* @returns Γ(x); for +ve integer Γ(x) = x!
|
|
173
|
+
*/
|
|
174
|
+
declare function gamma(x: number): number;
|
|
175
|
+
/**
|
|
176
|
+
* Compute the natural logarithm of the absolute value of the gamma function of a number (log-Γ).
|
|
177
|
+
* @param x a number
|
|
178
|
+
* @returns log(|Γ(x)|)
|
|
179
|
+
*/
|
|
180
|
+
declare function lgamma(x: number): number;
|
|
168
181
|
/**
|
|
169
182
|
* TODO: Find error function value of number (approximation).
|
|
170
183
|
* @param x a number
|
|
@@ -176,4 +189,4 @@ declare function erf(x: number): number;
|
|
|
176
189
|
*/
|
|
177
190
|
declare function erfc(x: number): number;
|
|
178
191
|
|
|
179
|
-
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 };
|
|
192
|
+
export { binomial, constrain, degrees, dist, erf, erfc, factorial, gamma, gcd, lcm, lerp, lgamma, log, mag, map, mean, median, mod, modes, modp, multinomial, norm, product, radians, range, rem, root, sum, variance };
|
package/index.js
CHANGED
|
@@ -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;
|
|
@@ -147,6 +153,17 @@ function variance(...xs) {
|
|
|
147
153
|
a += (x - m) ** 2;
|
|
148
154
|
return a / xs.length;
|
|
149
155
|
}
|
|
156
|
+
function gamma(x) {
|
|
157
|
+
var x = x - 1;
|
|
158
|
+
var e1 = Math.sqrt(2 * Math.PI * x);
|
|
159
|
+
var e2 = Math.pow(x / Math.E, x);
|
|
160
|
+
var e3 = Math.pow(x * Math.sinh(1 / x), x / 2);
|
|
161
|
+
var e4 = Math.exp((7 / 324) * (1 / ((x ** 3) * (35 * x ** 2 + 33))));
|
|
162
|
+
return e1 * e2 * e3 * e4;
|
|
163
|
+
}
|
|
164
|
+
function lgamma(x) {
|
|
165
|
+
return Math.log(Math.abs(gamma(x)));
|
|
166
|
+
}
|
|
150
167
|
const ERF_A1 = 0.254829592;
|
|
151
168
|
const ERF_A2 = -0.284496736;
|
|
152
169
|
const ERF_A3 = 1.421413741;
|
|
@@ -191,9 +208,11 @@ exports.dist = dist;
|
|
|
191
208
|
exports.erf = erf;
|
|
192
209
|
exports.erfc = erfc;
|
|
193
210
|
exports.factorial = factorial;
|
|
211
|
+
exports.gamma = gamma;
|
|
194
212
|
exports.gcd = gcd;
|
|
195
213
|
exports.lcm = lcm;
|
|
196
214
|
exports.lerp = lerp;
|
|
215
|
+
exports.lgamma = lgamma;
|
|
197
216
|
exports.log = log;
|
|
198
217
|
exports.mag = mag;
|
|
199
218
|
exports.map = map;
|
package/index.mjs
CHANGED
|
@@ -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;
|
|
@@ -143,6 +149,17 @@ function variance(...xs) {
|
|
|
143
149
|
a += (x - m) ** 2;
|
|
144
150
|
return a / xs.length;
|
|
145
151
|
}
|
|
152
|
+
function gamma(x) {
|
|
153
|
+
var x = x - 1;
|
|
154
|
+
var e1 = Math.sqrt(2 * Math.PI * x);
|
|
155
|
+
var e2 = Math.pow(x / Math.E, x);
|
|
156
|
+
var e3 = Math.pow(x * Math.sinh(1 / x), x / 2);
|
|
157
|
+
var e4 = Math.exp((7 / 324) * (1 / ((x ** 3) * (35 * x ** 2 + 33))));
|
|
158
|
+
return e1 * e2 * e3 * e4;
|
|
159
|
+
}
|
|
160
|
+
function lgamma(x) {
|
|
161
|
+
return Math.log(Math.abs(gamma(x)));
|
|
162
|
+
}
|
|
146
163
|
const ERF_A1 = 0.254829592;
|
|
147
164
|
const ERF_A2 = -0.284496736;
|
|
148
165
|
const ERF_A3 = 1.421413741;
|
|
@@ -180,4 +197,4 @@ function erfc(x) {
|
|
|
180
197
|
return y * Math.exp(-x * x + 0.5 * (ERFC_TABLE[I] + z * d) - c);
|
|
181
198
|
}
|
|
182
199
|
|
|
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 };
|
|
200
|
+
export { binomial, constrain, degrees, dist, erf, erfc, factorial, gamma, gcd, lcm, lerp, lgamma, 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.
|
|
3
|
+
"version": "1.3.3",
|
|
4
4
|
"description": "Mathematics is the classification and study of all possible patterns.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.mjs",
|
|
@@ -24,9 +24,11 @@
|
|
|
24
24
|
"erf",
|
|
25
25
|
"erfc",
|
|
26
26
|
"factorial",
|
|
27
|
+
"gamma",
|
|
27
28
|
"gcd",
|
|
28
29
|
"lcm",
|
|
29
30
|
"lerp",
|
|
31
|
+
"lgamma",
|
|
30
32
|
"log",
|
|
31
33
|
"mag",
|
|
32
34
|
"map",
|