extra-math 1.3.2 → 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 CHANGED
@@ -166,6 +166,18 @@ declare function range(...xs: number[]): number;
166
166
  * @returns σ² = E[(xs - µ)²] | µ = mean(xs)
167
167
  */
168
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;
169
181
  /**
170
182
  * TODO: Find error function value of number (approximation).
171
183
  * @param x a number
@@ -177,4 +189,4 @@ declare function erf(x: number): number;
177
189
  */
178
190
  declare function erfc(x: number): number;
179
191
 
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 };
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
@@ -153,6 +153,17 @@ function variance(...xs) {
153
153
  a += (x - m) ** 2;
154
154
  return a / xs.length;
155
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
+ }
156
167
  const ERF_A1 = 0.254829592;
157
168
  const ERF_A2 = -0.284496736;
158
169
  const ERF_A3 = 1.421413741;
@@ -197,9 +208,11 @@ exports.dist = dist;
197
208
  exports.erf = erf;
198
209
  exports.erfc = erfc;
199
210
  exports.factorial = factorial;
211
+ exports.gamma = gamma;
200
212
  exports.gcd = gcd;
201
213
  exports.lcm = lcm;
202
214
  exports.lerp = lerp;
215
+ exports.lgamma = lgamma;
203
216
  exports.log = log;
204
217
  exports.mag = mag;
205
218
  exports.map = map;
package/index.mjs CHANGED
@@ -149,6 +149,17 @@ function variance(...xs) {
149
149
  a += (x - m) ** 2;
150
150
  return a / xs.length;
151
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
+ }
152
163
  const ERF_A1 = 0.254829592;
153
164
  const ERF_A2 = -0.284496736;
154
165
  const ERF_A3 = 1.421413741;
@@ -186,4 +197,4 @@ function erfc(x) {
186
197
  return y * Math.exp(-x * x + 0.5 * (ERFC_TABLE[I] + z * d) - c);
187
198
  }
188
199
 
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 };
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.2",
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",