extra-math 1.3.10 → 1.3.11

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 CHANGED
@@ -44,6 +44,38 @@ math.lcm(2, 3, 4);
44
44
 
45
45
  | Property | Description |
46
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. |
47
79
 
48
80
  <br>
49
81
  <br>
@@ -70,3 +102,32 @@ math.lcm(2, 3, 4);
70
102
 
71
103
 
72
104
  [a]: https://nodef.github.io/extra-math/modules.html#sum
105
+ [rem]: https://nodef.github.io/extra-math/modules.html#rem
106
+ [mod]: https://nodef.github.io/extra-math/modules.html#mod
107
+ [modp]: https://nodef.github.io/extra-math/modules.html#modp
108
+ [gcd]: https://nodef.github.io/extra-math/modules.html#gcd
109
+ [lcm]: https://nodef.github.io/extra-math/modules.html#lcm
110
+ [factorial]: https://nodef.github.io/extra-math/modules.html#factorial
111
+ [binomial]: https://nodef.github.io/extra-math/modules.html#binomial
112
+ [multinomial]: https://nodef.github.io/extra-math/modules.html#multinomial
113
+ [constrain]: https://nodef.github.io/extra-math/modules.html#constrain
114
+ [root]: https://nodef.github.io/extra-math/modules.html#root
115
+ [log]: https://nodef.github.io/extra-math/modules.html#log
116
+ [norm]: https://nodef.github.io/extra-math/modules.html#norm
117
+ [map]: https://nodef.github.io/extra-math/modules.html#map
118
+ [lerp]: https://nodef.github.io/extra-math/modules.html#lerp
119
+ [gamma]: https://nodef.github.io/extra-math/modules.html#gamma
120
+ [lgamma]: https://nodef.github.io/extra-math/modules.html#lgamma
121
+ [erf]: https://nodef.github.io/extra-math/modules.html#erf
122
+ [erfc]: https://nodef.github.io/extra-math/modules.html#erfc
123
+ [degrees]: https://nodef.github.io/extra-math/modules.html#degrees
124
+ [radians]: https://nodef.github.io/extra-math/modules.html#radians
125
+ [mag]: https://nodef.github.io/extra-math/modules.html#mag
126
+ [dist]: https://nodef.github.io/extra-math/modules.html#dist
127
+ [sum]: https://nodef.github.io/extra-math/modules.html#sum
128
+ [product]: https://nodef.github.io/extra-math/modules.html#product
129
+ [mean]: https://nodef.github.io/extra-math/modules.html#mean
130
+ [median]: https://nodef.github.io/extra-math/modules.html#median
131
+ [modes]: https://nodef.github.io/extra-math/modules.html#modes
132
+ [range]: https://nodef.github.io/extra-math/modules.html#range
133
+ [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.10",
3
+ "version": "1.3.11",
4
4
  "description": "Mathematics is the classification and study of all possible patterns.",
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",