extra-math 1.3.9 → 1.3.12

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.
Files changed (5) hide show
  1. package/README.md +62 -34
  2. package/index.d.ts +24 -24
  3. package/index.js +47 -47
  4. package/index.mjs +47 -47
  5. package/package.json +1 -1
package/README.md CHANGED
@@ -43,24 +43,39 @@ math.lcm(2, 3, 4);
43
43
  ## Index
44
44
 
45
45
  | Property | Description |
46
- | ------ | ------- |
47
- | [sum] | Finds sum of numbers (Σ). |
48
- | [product] | Finds product of numbers (∏). |
49
- | [mean] | Finds average of numbers. |
50
- | [median] | Finds the value separating the higher and lower halves of numbers. |
51
- | [modes] | Finds the values that appear most often. |
52
- | [range] | Finds the difference between the largest and smallest values. |
53
- | [variance] | Finds the mean of squared deviation of numbers from its mean. |
54
- | [erf] | Finds error function value of number (approximation). |
55
- | [erfc] | Finds complementary error function value of number (approximation). |
56
- | |
57
- | [rem] | Finds remainder of x/y with sign of x (truncated division). |
58
- | [mod] | Finds remainder of x/y with sign of y (floored division). |
59
- | [modp] | Finds remainder of x/y with +ve sign (euclidean division). |
60
- | [gcd] | Finds greatest common divisor of numbers. |
61
- | [lcm] | Finds least common multiple of numbers. |
62
- | [binomial] | Finds ways to choose k elements from a set of n elements. |
63
- | [multinomial] | Finds ways to put n objects in m bins (n=sum(ki)). |
46
+ | ---- | ---- |
47
+ | [rem] | Find the remainder of x/y with sign of x (truncated division). |
48
+ | [mod] | Find the remainder of x/y with sign of y (floored division). |
49
+ | [modp] | Find the remainder of x/y with +ve sign (euclidean division). |
50
+ | [gcd] | Find the greatest common divisor of numbers. |
51
+ | [lcm] | Find the least common multiple of numbers. |
52
+ | [factorial] | Find the factorial of a number. |
53
+ | [binomial] | Find the number of ways to choose k elements from a set of n elements. |
54
+ | [multinomial] | Find the number of ways to put n objects in m bins (n=sum(kᵢ)). |
55
+ | | |
56
+ | [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
+ | [norm] | Normalize a number from its current range into a value between 0 and 1. |
60
+ | [map] | Re-map a number from one range to another. |
61
+ | [lerp] | Linearly interpolate a number between two numbers. |
62
+ | [gamma] | Compute the gamma function of a number (Γ). |
63
+ | [lgamma] | Compute the natural logarithm of the absolute value of the gamma function of a number (log-Γ). |
64
+ | [erf] | Find error function value of number (approximation). |
65
+ | [erfc] | Find the complementary error function value of number (approximation). |
66
+ | | |
67
+ | [degrees] | Convert radians to degrees. |
68
+ | [radians] | Convert degrees to radians. |
69
+ | [mag] | Calculate the magnitude (length) of a vector. |
70
+ | [dist] | Calculate the distance between two points. |
71
+ | | |
72
+ | [sum] | Find the sum of numbers (Σ). |
73
+ | [product] | Find the product of numbers (∏). |
74
+ | [mean] | Find the average of numbers. |
75
+ | [median] | Find the value separating the higher and lower halves of numbers. |
76
+ | [modes] | Find the values that appear most often. |
77
+ | [range] | Find the difference between the largest and smallest values. |
78
+ | [variance] | Find the mean of squared deviation of numbers from its mean. |
64
79
 
65
80
  <br>
66
81
  <br>
@@ -86,19 +101,32 @@ math.lcm(2, 3, 4);
86
101
  [![](https://img.youtube.com/vi/dW8Cy6WrO94/maxresdefault.jpg)](https://www.youtube.com/watch?v=dW8Cy6WrO94)
87
102
 
88
103
 
89
- [sum]: https://github.com/nodef/extra-math/wiki/sum
90
- [product]: https://github.com/nodef/extra-math/wiki/product
91
- [mean]: https://github.com/nodef/extra-math/wiki/mean
92
- [median]: https://github.com/nodef/extra-math/wiki/median
93
- [modes]: https://github.com/nodef/extra-math/wiki/modes
94
- [range]: https://github.com/nodef/extra-math/wiki/range
95
- [variance]: https://github.com/nodef/extra-math/wiki/variance
96
- [gcd]: https://github.com/nodef/extra-math/wiki/gcd
97
- [lcm]: https://github.com/nodef/extra-math/wiki/lcm
98
- [binomial]: https://github.com/nodef/extra-math/wiki/binomial
99
- [multinomial]: https://github.com/nodef/extra-math/wiki/multinomial
100
- [erf]: https://github.com/nodef/extra-math/wiki/erf
101
- [erfc]: https://github.com/nodef/extra-math/wiki/erfc
102
- [rem]: https://github.com/nodef/extra-math/wiki/rem
103
- [mod]: https://github.com/nodef/extra-math/wiki/mod
104
- [modp]: https://github.com/nodef/extra-math/wiki/modp
104
+ [rem]: https://nodef.github.io/extra-math/modules.html#rem
105
+ [mod]: https://nodef.github.io/extra-math/modules.html#mod
106
+ [modp]: https://nodef.github.io/extra-math/modules.html#modp
107
+ [gcd]: https://nodef.github.io/extra-math/modules.html#gcd
108
+ [lcm]: https://nodef.github.io/extra-math/modules.html#lcm
109
+ [factorial]: https://nodef.github.io/extra-math/modules.html#factorial
110
+ [binomial]: https://nodef.github.io/extra-math/modules.html#binomial
111
+ [multinomial]: https://nodef.github.io/extra-math/modules.html#multinomial
112
+ [constrain]: https://nodef.github.io/extra-math/modules.html#constrain
113
+ [root]: https://nodef.github.io/extra-math/modules.html#root
114
+ [log]: https://nodef.github.io/extra-math/modules.html#log
115
+ [norm]: https://nodef.github.io/extra-math/modules.html#norm
116
+ [map]: https://nodef.github.io/extra-math/modules.html#map
117
+ [lerp]: https://nodef.github.io/extra-math/modules.html#lerp
118
+ [gamma]: https://nodef.github.io/extra-math/modules.html#gamma
119
+ [lgamma]: https://nodef.github.io/extra-math/modules.html#lgamma
120
+ [erf]: https://nodef.github.io/extra-math/modules.html#erf
121
+ [erfc]: https://nodef.github.io/extra-math/modules.html#erfc
122
+ [degrees]: https://nodef.github.io/extra-math/modules.html#degrees
123
+ [radians]: https://nodef.github.io/extra-math/modules.html#radians
124
+ [mag]: https://nodef.github.io/extra-math/modules.html#mag
125
+ [dist]: https://nodef.github.io/extra-math/modules.html#dist
126
+ [sum]: https://nodef.github.io/extra-math/modules.html#sum
127
+ [product]: https://nodef.github.io/extra-math/modules.html#product
128
+ [mean]: https://nodef.github.io/extra-math/modules.html#mean
129
+ [median]: https://nodef.github.io/extra-math/modules.html#median
130
+ [modes]: https://nodef.github.io/extra-math/modules.html#modes
131
+ [range]: https://nodef.github.io/extra-math/modules.html#range
132
+ [variance]: https://nodef.github.io/extra-math/modules.html#variance
package/index.d.ts CHANGED
@@ -99,6 +99,30 @@ declare function map(x: number, r: number, R: number, t: number, T: number): num
99
99
  * @returns ∈ [x, y]
100
100
  */
101
101
  declare function lerp(x: number, y: number, t: number): number;
102
+ /**
103
+ * Compute the gamma function of a number (Γ).
104
+ * @param x a number
105
+ * @returns Γ(x); for +ve integer Γ(x) = x!
106
+ */
107
+ declare function gamma(x: number): number;
108
+ /**
109
+ * Compute the natural logarithm of the absolute value of the gamma function of a number (log-Γ).
110
+ * @param x a number
111
+ * @returns log(|Γ(x)|)
112
+ */
113
+ declare function lgamma(x: number): number;
114
+ /**
115
+ * Find error function value of number (approximation).
116
+ * @param x a number
117
+ * @returns erf(x)
118
+ */
119
+ declare function erf(x: number): number;
120
+ /**
121
+ * Find the complementary error function value of number (approximation).
122
+ * @param x a number
123
+ * @returns erfc(x)
124
+ */
125
+ declare function erfc(x: number): number;
102
126
  /**
103
127
  * Convert radians to degrees.
104
128
  * @param x radians
@@ -166,29 +190,5 @@ declare function range(...xs: number[]): number;
166
190
  * @returns σ² = E[(xs - µ)²] | µ = mean(xs)
167
191
  */
168
192
  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;
181
- /**
182
- * Find error function value of number (approximation).
183
- * @param x a number
184
- * @returns erf(x)
185
- */
186
- declare function erf(x: number): number;
187
- /**
188
- * Find the complementary error function value of number (approximation).
189
- * @param x a number
190
- * @returns erfc(x)
191
- */
192
- declare function erfc(x: number): number;
193
193
 
194
194
  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
@@ -73,6 +73,53 @@ function map(x, r, R, t, T) {
73
73
  function lerp(x, y, t) {
74
74
  return x + t * (y - x);
75
75
  }
76
+ function gamma(x) {
77
+ var x = x - 1;
78
+ var e1 = Math.sqrt(2 * Math.PI * x);
79
+ var e2 = Math.pow(x / Math.E, x);
80
+ var e3 = Math.pow(x * Math.sinh(1 / x), x / 2);
81
+ var e4 = Math.exp((7 / 324) * (1 / ((x ** 3) * (35 * x ** 2 + 33))));
82
+ return e1 * e2 * e3 * e4;
83
+ }
84
+ function lgamma(x) {
85
+ return Math.log(Math.abs(gamma(x)));
86
+ }
87
+ const ERF_A1 = 0.254829592;
88
+ const ERF_A2 = -0.284496736;
89
+ const ERF_A3 = 1.421413741;
90
+ const ERF_A4 = -1.453152027;
91
+ const ERF_A5 = 1.061405429;
92
+ const ERF_P = 0.3275911;
93
+ function erf(x) {
94
+ var sgn = x < 0 ? -1 : 1;
95
+ var x = Math.abs(x);
96
+ var t = 1 / (1 + ERF_P * x);
97
+ var y = 1 - (((((ERF_A5 * t + ERF_A4) * t) + ERF_A3) * t + ERF_A2) * t + ERF_A1) * t * Math.exp(-x * x);
98
+ return sgn * y;
99
+ }
100
+ const ERFC_TABLE = [
101
+ -2.8e-17, 1.21e-16, -9.4e-17, -1.523e-15, 7.106e-15,
102
+ 3.81e-16, -1.12708e-13, 3.13092e-13, 8.94487e-13,
103
+ -6.886027e-12, 2.394038e-12, 9.6467911e-11,
104
+ -2.27365122e-10, -9.91364156e-10, 5.059343495e-9,
105
+ 6.529054439e-9, -8.5238095915e-8, 1.5626441722e-8,
106
+ 1.303655835580e-6, -1.624290004647e-6,
107
+ -2.0278578112534e-5, 4.2523324806907e-5,
108
+ 3.66839497852761e-4, -9.46595344482036e-4,
109
+ -9.561514786808631e-3, 1.9476473204185836e-2,
110
+ 6.4196979235649026e-1, -1.3026537197817094
111
+ ];
112
+ function erfc(x) {
113
+ if (x < 0)
114
+ return 2 - erfc(-x);
115
+ var c = 0, d = 0, y = 2 / (2 + x), z = 4 * y - 2;
116
+ for (var i = 0, I = ERFC_TABLE.length - 1; i < I; i++) {
117
+ var t = d;
118
+ d = z * d - c + ERFC_TABLE[i];
119
+ c = t;
120
+ }
121
+ return y * Math.exp(-x * x + 0.5 * (ERFC_TABLE[I] + z * d) - c);
122
+ }
76
123
  function degrees(x) {
77
124
  return x * (180 / Math.PI);
78
125
  }
@@ -153,53 +200,6 @@ function variance(...xs) {
153
200
  a += (x - m) ** 2;
154
201
  return a / xs.length;
155
202
  }
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
- }
167
- const ERF_A1 = 0.254829592;
168
- const ERF_A2 = -0.284496736;
169
- const ERF_A3 = 1.421413741;
170
- const ERF_A4 = -1.453152027;
171
- const ERF_A5 = 1.061405429;
172
- const ERF_P = 0.3275911;
173
- function erf(x) {
174
- var sgn = x < 0 ? -1 : 1;
175
- var x = Math.abs(x);
176
- var t = 1 / (1 + ERF_P * x);
177
- var y = 1 - (((((ERF_A5 * t + ERF_A4) * t) + ERF_A3) * t + ERF_A2) * t + ERF_A1) * t * Math.exp(-x * x);
178
- return sgn * y;
179
- }
180
- const ERFC_TABLE = [
181
- -2.8e-17, 1.21e-16, -9.4e-17, -1.523e-15, 7.106e-15,
182
- 3.81e-16, -1.12708e-13, 3.13092e-13, 8.94487e-13,
183
- -6.886027e-12, 2.394038e-12, 9.6467911e-11,
184
- -2.27365122e-10, -9.91364156e-10, 5.059343495e-9,
185
- 6.529054439e-9, -8.5238095915e-8, 1.5626441722e-8,
186
- 1.303655835580e-6, -1.624290004647e-6,
187
- -2.0278578112534e-5, 4.2523324806907e-5,
188
- 3.66839497852761e-4, -9.46595344482036e-4,
189
- -9.561514786808631e-3, 1.9476473204185836e-2,
190
- 6.4196979235649026e-1, -1.3026537197817094
191
- ];
192
- function erfc(x) {
193
- if (x < 0)
194
- return 2 - erfc(-x);
195
- var c = 0, d = 0, y = 2 / (2 + x), z = 4 * y - 2;
196
- for (var i = 0, I = ERFC_TABLE.length - 1; i < I; i++) {
197
- var t = d;
198
- d = z * d - c + ERFC_TABLE[i];
199
- c = t;
200
- }
201
- return y * Math.exp(-x * x + 0.5 * (ERFC_TABLE[I] + z * d) - c);
202
- }
203
203
 
204
204
  exports.binomial = binomial;
205
205
  exports.constrain = constrain;
package/index.mjs CHANGED
@@ -69,6 +69,53 @@ function map(x, r, R, t, T) {
69
69
  function lerp(x, y, t) {
70
70
  return x + t * (y - x);
71
71
  }
72
+ function gamma(x) {
73
+ var x = x - 1;
74
+ var e1 = Math.sqrt(2 * Math.PI * x);
75
+ var e2 = Math.pow(x / Math.E, x);
76
+ var e3 = Math.pow(x * Math.sinh(1 / x), x / 2);
77
+ var e4 = Math.exp((7 / 324) * (1 / ((x ** 3) * (35 * x ** 2 + 33))));
78
+ return e1 * e2 * e3 * e4;
79
+ }
80
+ function lgamma(x) {
81
+ return Math.log(Math.abs(gamma(x)));
82
+ }
83
+ const ERF_A1 = 0.254829592;
84
+ const ERF_A2 = -0.284496736;
85
+ const ERF_A3 = 1.421413741;
86
+ const ERF_A4 = -1.453152027;
87
+ const ERF_A5 = 1.061405429;
88
+ const ERF_P = 0.3275911;
89
+ function erf(x) {
90
+ var sgn = x < 0 ? -1 : 1;
91
+ var x = Math.abs(x);
92
+ var t = 1 / (1 + ERF_P * x);
93
+ var y = 1 - (((((ERF_A5 * t + ERF_A4) * t) + ERF_A3) * t + ERF_A2) * t + ERF_A1) * t * Math.exp(-x * x);
94
+ return sgn * y;
95
+ }
96
+ const ERFC_TABLE = [
97
+ -2.8e-17, 1.21e-16, -9.4e-17, -1.523e-15, 7.106e-15,
98
+ 3.81e-16, -1.12708e-13, 3.13092e-13, 8.94487e-13,
99
+ -6.886027e-12, 2.394038e-12, 9.6467911e-11,
100
+ -2.27365122e-10, -9.91364156e-10, 5.059343495e-9,
101
+ 6.529054439e-9, -8.5238095915e-8, 1.5626441722e-8,
102
+ 1.303655835580e-6, -1.624290004647e-6,
103
+ -2.0278578112534e-5, 4.2523324806907e-5,
104
+ 3.66839497852761e-4, -9.46595344482036e-4,
105
+ -9.561514786808631e-3, 1.9476473204185836e-2,
106
+ 6.4196979235649026e-1, -1.3026537197817094
107
+ ];
108
+ function erfc(x) {
109
+ if (x < 0)
110
+ return 2 - erfc(-x);
111
+ var c = 0, d = 0, y = 2 / (2 + x), z = 4 * y - 2;
112
+ for (var i = 0, I = ERFC_TABLE.length - 1; i < I; i++) {
113
+ var t = d;
114
+ d = z * d - c + ERFC_TABLE[i];
115
+ c = t;
116
+ }
117
+ return y * Math.exp(-x * x + 0.5 * (ERFC_TABLE[I] + z * d) - c);
118
+ }
72
119
  function degrees(x) {
73
120
  return x * (180 / Math.PI);
74
121
  }
@@ -149,52 +196,5 @@ function variance(...xs) {
149
196
  a += (x - m) ** 2;
150
197
  return a / xs.length;
151
198
  }
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
- }
163
- const ERF_A1 = 0.254829592;
164
- const ERF_A2 = -0.284496736;
165
- const ERF_A3 = 1.421413741;
166
- const ERF_A4 = -1.453152027;
167
- const ERF_A5 = 1.061405429;
168
- const ERF_P = 0.3275911;
169
- function erf(x) {
170
- var sgn = x < 0 ? -1 : 1;
171
- var x = Math.abs(x);
172
- var t = 1 / (1 + ERF_P * x);
173
- var y = 1 - (((((ERF_A5 * t + ERF_A4) * t) + ERF_A3) * t + ERF_A2) * t + ERF_A1) * t * Math.exp(-x * x);
174
- return sgn * y;
175
- }
176
- const ERFC_TABLE = [
177
- -2.8e-17, 1.21e-16, -9.4e-17, -1.523e-15, 7.106e-15,
178
- 3.81e-16, -1.12708e-13, 3.13092e-13, 8.94487e-13,
179
- -6.886027e-12, 2.394038e-12, 9.6467911e-11,
180
- -2.27365122e-10, -9.91364156e-10, 5.059343495e-9,
181
- 6.529054439e-9, -8.5238095915e-8, 1.5626441722e-8,
182
- 1.303655835580e-6, -1.624290004647e-6,
183
- -2.0278578112534e-5, 4.2523324806907e-5,
184
- 3.66839497852761e-4, -9.46595344482036e-4,
185
- -9.561514786808631e-3, 1.9476473204185836e-2,
186
- 6.4196979235649026e-1, -1.3026537197817094
187
- ];
188
- function erfc(x) {
189
- if (x < 0)
190
- return 2 - erfc(-x);
191
- var c = 0, d = 0, y = 2 / (2 + x), z = 4 * y - 2;
192
- for (var i = 0, I = ERFC_TABLE.length - 1; i < I; i++) {
193
- var t = d;
194
- d = z * d - c + ERFC_TABLE[i];
195
- c = t;
196
- }
197
- return y * Math.exp(-x * x + 0.5 * (ERFC_TABLE[I] + z * d) - c);
198
- }
199
199
 
200
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.9",
3
+ "version": "1.3.12",
4
4
  "description": "Mathematics is the classification and study of all possible patterns.",
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",