extra-math 1.2.16 → 1.3.0

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
@@ -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,44 +69,46 @@ 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 logb(x: number, b: number): number;
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 min lower bound of current range
80
- * @param max upper bound of current range
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, min: number, max: number): 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 min lower bound of current range
88
- * @param max upper bound of current range
89
- * @param amin lower bound of target range
90
- * @param amax upper bound of target range
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, min: number, max: number, amin: number, amax: number): number;
93
+ declare function map(x: number, r: number, R: number, t: number, T: number): number;
94
94
  /**
95
- * TODO: (argument order ok?) Calculate a number between two numbers at a specific increment.
96
- * @param min minimum value
97
- * @param max maximum value
98
- * @param x a number between 0 to 1
99
- * @returns ∈ [min, max]
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(min: number, max: number, x: number): number;
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
  /**
@@ -174,4 +176,4 @@ declare function erf(x: number): number;
174
176
  */
175
177
  declare function erfc(x: number): number;
176
178
 
177
- export { binomial, constrain, degrees, dist, erf, erfc, factorial, gcd, lcm, lerp, logb, mag, map, mean, median, mod, modes, modp, multinomial, norm, product, radians, range, rem, root, sum, variance };
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 };
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 logb(x, b) {
64
+ function log(x, b = Math.E) {
65
65
  return Math.log(x) / Math.log(b);
66
66
  }
67
- function norm(x, min, max) {
68
- return (x - min) / (max - min);
67
+ function norm(x, r, R) {
68
+ return (x - r) / (R - r);
69
69
  }
70
- function map(x, min, max, amin, amax) {
71
- return amin + ((x - min) / (max - min)) * (amax - amin);
70
+ function map(x, r, R, t, T) {
71
+ return t + ((x - r) / (R - r)) * (T - t);
72
72
  }
73
- function lerp(min, max, x) {
74
- return min + x * (max - min);
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);
@@ -194,7 +194,7 @@ exports.factorial = factorial;
194
194
  exports.gcd = gcd;
195
195
  exports.lcm = lcm;
196
196
  exports.lerp = lerp;
197
- exports.logb = logb;
197
+ exports.log = log;
198
198
  exports.mag = mag;
199
199
  exports.map = map;
200
200
  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 logb(x, b) {
60
+ function log(x, b = Math.E) {
61
61
  return Math.log(x) / Math.log(b);
62
62
  }
63
- function norm(x, min, max) {
64
- return (x - min) / (max - min);
63
+ function norm(x, r, R) {
64
+ return (x - r) / (R - r);
65
65
  }
66
- function map(x, min, max, amin, amax) {
67
- return amin + ((x - min) / (max - min)) * (amax - amin);
66
+ function map(x, r, R, t, T) {
67
+ return t + ((x - r) / (R - r)) * (T - t);
68
68
  }
69
- function lerp(min, max, x) {
70
- return min + x * (max - min);
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);
@@ -180,4 +180,4 @@ function erfc(x) {
180
180
  return y * Math.exp(-x * x + 0.5 * (ERFC_TABLE[I] + z * d) - c);
181
181
  }
182
182
 
183
- export { binomial, constrain, degrees, dist, erf, erfc, factorial, gcd, lcm, lerp, logb, mag, map, mean, median, mod, modes, modp, multinomial, norm, product, radians, range, rem, root, sum, variance };
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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "extra-math",
3
- "version": "1.2.16",
3
+ "version": "1.3.0",
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
- "logb",
30
+ "log",
31
31
  "mag",
32
32
  "map",
33
33
  "mean",