extra-math 1.3.41 โ†’ 1.3.43

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
@@ -203,6 +203,44 @@ declare function properDivisors(x: number): number[];
203
203
 
204
204
 
205
205
  declare function aliquotSum(x: number): number;
206
+ /**
207
+ * Find the least prime number which divides a number.
208
+ * [๐Ÿ“˜](https://github.com/nodef/extra-math/wiki/minPrimeFactor)
209
+ * @param x a number
210
+ * @returns least prime factor
211
+ * */
212
+
213
+
214
+ declare function minPrimeFactor(x: number): number;
215
+
216
+ /**
217
+ * Find the greatest prime number which divides a number.
218
+ * [๐Ÿ“˜](https://github.com/nodef/extra-math/wiki/maxPrimeFactor)
219
+ * @param x a number
220
+ * @returns greatest prime factor
221
+ * */
222
+
223
+
224
+ declare function maxPrimeFactor(x: number): number;
225
+
226
+ /**
227
+ * Find the prime factors of a number.
228
+ * [๐Ÿ“˜](https://github.com/nodef/extra-math/wiki/primeFactors)
229
+ * @param x a number
230
+ * @returns [fโ‚€, fโ‚, ...] | fแตข divides x and is prime
231
+ * */
232
+
233
+
234
+ declare function primeFactors(x: number): number[];
235
+ /**
236
+ * Find the prime factors and respective exponents of a number.
237
+ * [๐Ÿ“˜](https://github.com/nodef/extra-math/wiki/primeExponentials)
238
+ * @param x a number
239
+ * @returns [[fโ‚€, eโ‚€], [fโ‚, eโ‚], ...] | fแตข is a prime factor of x and eแตข is its exponent
240
+ * */
241
+
242
+
243
+ declare function primeExponentials(x: number): [number, number][];
206
244
  /**
207
245
  * Check if number is prime.
208
246
  * [๐Ÿ“˜](https://github.com/nodef/extra-math/wiki/isPrime)
@@ -398,4 +436,4 @@ declare function magnitude(xs: number[]): number;
398
436
 
399
437
  declare function distance(xs: number[], ys: number[]): number;
400
438
 
401
- export { properDivisors as aliquotParts, aliquotSum, arithmeticMean, binomial, ceil, ceilDiv, constrain as clamp, constrain, cubicMean, degrees, distance, factorial, floor, floorDiv, gcd, geometricMean, harmonicMean, gcd as hcf, isPow, isPrime, lcm, lerp, log, magnitude, remap as map, arithmeticMean as mean, median, mod, modes, modp, multinomial, nextPow, normalize as norm, normalize, prevPow, product, properDivisors, quadriaticMean, radians, range, rem, remap, root, quadriaticMean as rootMeanSquare, round, roundDiv, sum, variance };
439
+ export { properDivisors as aliquotParts, aliquotSum, arithmeticMean, binomial, ceil, ceilDiv, constrain as clamp, constrain, cubicMean, degrees, distance, factorial, floor, floorDiv, gcd, geometricMean, maxPrimeFactor as greatestPrimeFactor, harmonicMean, gcd as hcf, isPow, isPrime, lcm, minPrimeFactor as leastPrimeFactor, lerp, log, magnitude, remap as map, maxPrimeFactor, arithmeticMean as mean, median, minPrimeFactor, mod, modes, modp, multinomial, nextPow, normalize as norm, normalize, prevPow, primeExponentials, primeFactors, product, properDivisors, quadriaticMean, radians, range, rem, remap, root, quadriaticMean as rootMeanSquare, round, roundDiv, sum, variance };
package/index.js CHANGED
@@ -99,6 +99,78 @@ function minPrimeFactor(x) {
99
99
  }
100
100
  return x;
101
101
  }
102
+ function maxPrimeFactor(x) {
103
+ var x = Math.abs(x), a = 0;
104
+ if (x <= 1)
105
+ return 0;
106
+ if (x <= 3)
107
+ return x;
108
+ for (; x % 2 === 0; a = 2)
109
+ x /= 2;
110
+ for (; x % 3 === 0; a = 3)
111
+ x /= 3;
112
+ for (var i = 6, I = Math.sqrt(x) + 1; x > 1 && i <= I; i += 6) {
113
+ for (; x % (i - 1) == 0; a = i - 1)
114
+ x /= i - 1;
115
+ for (; x % (i + 1) == 0; a = i + 1)
116
+ x /= i + 1;
117
+ }
118
+ if (x <= 1)
119
+ return a;
120
+ return x;
121
+ }
122
+ function primeFactors(x) {
123
+ var x = Math.abs(x), a = [];
124
+ if (x <= 1)
125
+ return [];
126
+ if (x <= 3)
127
+ return [x];
128
+ x = pushPrimeFactorTo$(a, x, 2);
129
+ x = pushPrimeFactorTo$(a, x, 3);
130
+ for (var i = 6, I = Math.sqrt(x) + 1; x > 1 && i <= I; i += 6) {
131
+ x = pushPrimeFactorTo$(a, x, i - 1);
132
+ x = pushPrimeFactorTo$(a, x, i + 1);
133
+ }
134
+ if (x > 1)
135
+ a.push(x);
136
+ return a;
137
+ }
138
+ function pushPrimeFactorTo$(a, x, f) {
139
+ if (x % f !== 0)
140
+ return x;
141
+ do {
142
+ x /= f;
143
+ } while (x % f === 0);
144
+ a.push(f);
145
+ return x;
146
+ }
147
+ function primeExponentials(x) {
148
+ var x = Math.abs(x), a = [];
149
+ if (x <= 1)
150
+ return [];
151
+ if (x <= 3)
152
+ return [[x, 1]];
153
+ x = pushPrimeExponentialTo$(a, x, 2);
154
+ x = pushPrimeExponentialTo$(a, x, 3);
155
+ for (var i = 6, I = Math.sqrt(x) + 1; x > 1 && i <= I; i += 6) {
156
+ x = pushPrimeExponentialTo$(a, x, i - 1);
157
+ x = pushPrimeExponentialTo$(a, x, i + 1);
158
+ }
159
+ if (x > 1)
160
+ a.push([x, 1]);
161
+ return a;
162
+ }
163
+ function pushPrimeExponentialTo$(a, x, f) {
164
+ if (x % f !== 0)
165
+ return x;
166
+ var e = 0;
167
+ do {
168
+ x /= f;
169
+ ++e;
170
+ } while (x % f === 0);
171
+ a.push([f, e]);
172
+ return x;
173
+ }
102
174
  function isPrime(x) {
103
175
  return x !== 0 && minPrimeFactor(x) === Math.abs(x);
104
176
  }
@@ -270,17 +342,21 @@ exports.floor = floor;
270
342
  exports.floorDiv = floorDiv;
271
343
  exports.gcd = gcd;
272
344
  exports.geometricMean = geometricMean;
345
+ exports.greatestPrimeFactor = maxPrimeFactor;
273
346
  exports.harmonicMean = harmonicMean;
274
347
  exports.hcf = gcd;
275
348
  exports.isPow = isPow;
276
349
  exports.isPrime = isPrime;
277
350
  exports.lcm = lcm;
351
+ exports.leastPrimeFactor = minPrimeFactor;
278
352
  exports.lerp = lerp;
279
353
  exports.log = log;
280
354
  exports.magnitude = magnitude;
281
355
  exports.map = remap;
356
+ exports.maxPrimeFactor = maxPrimeFactor;
282
357
  exports.mean = arithmeticMean;
283
358
  exports.median = median;
359
+ exports.minPrimeFactor = minPrimeFactor;
284
360
  exports.mod = mod;
285
361
  exports.modes = modes;
286
362
  exports.modp = modp;
@@ -289,6 +365,8 @@ exports.nextPow = nextPow;
289
365
  exports.norm = normalize;
290
366
  exports.normalize = normalize;
291
367
  exports.prevPow = prevPow;
368
+ exports.primeExponentials = primeExponentials;
369
+ exports.primeFactors = primeFactors;
292
370
  exports.product = product;
293
371
  exports.properDivisors = properDivisors;
294
372
  exports.quadriaticMean = quadriaticMean;
package/index.mjs CHANGED
@@ -97,6 +97,78 @@ function minPrimeFactor(x) {
97
97
  }
98
98
  return x;
99
99
  }
100
+ function maxPrimeFactor(x) {
101
+ var x = Math.abs(x), a = 0;
102
+ if (x <= 1)
103
+ return 0;
104
+ if (x <= 3)
105
+ return x;
106
+ for (; x % 2 === 0; a = 2)
107
+ x /= 2;
108
+ for (; x % 3 === 0; a = 3)
109
+ x /= 3;
110
+ for (var i = 6, I = Math.sqrt(x) + 1; x > 1 && i <= I; i += 6) {
111
+ for (; x % (i - 1) == 0; a = i - 1)
112
+ x /= i - 1;
113
+ for (; x % (i + 1) == 0; a = i + 1)
114
+ x /= i + 1;
115
+ }
116
+ if (x <= 1)
117
+ return a;
118
+ return x;
119
+ }
120
+ function primeFactors(x) {
121
+ var x = Math.abs(x), a = [];
122
+ if (x <= 1)
123
+ return [];
124
+ if (x <= 3)
125
+ return [x];
126
+ x = pushPrimeFactorTo$(a, x, 2);
127
+ x = pushPrimeFactorTo$(a, x, 3);
128
+ for (var i = 6, I = Math.sqrt(x) + 1; x > 1 && i <= I; i += 6) {
129
+ x = pushPrimeFactorTo$(a, x, i - 1);
130
+ x = pushPrimeFactorTo$(a, x, i + 1);
131
+ }
132
+ if (x > 1)
133
+ a.push(x);
134
+ return a;
135
+ }
136
+ function pushPrimeFactorTo$(a, x, f) {
137
+ if (x % f !== 0)
138
+ return x;
139
+ do {
140
+ x /= f;
141
+ } while (x % f === 0);
142
+ a.push(f);
143
+ return x;
144
+ }
145
+ function primeExponentials(x) {
146
+ var x = Math.abs(x), a = [];
147
+ if (x <= 1)
148
+ return [];
149
+ if (x <= 3)
150
+ return [[x, 1]];
151
+ x = pushPrimeExponentialTo$(a, x, 2);
152
+ x = pushPrimeExponentialTo$(a, x, 3);
153
+ for (var i = 6, I = Math.sqrt(x) + 1; x > 1 && i <= I; i += 6) {
154
+ x = pushPrimeExponentialTo$(a, x, i - 1);
155
+ x = pushPrimeExponentialTo$(a, x, i + 1);
156
+ }
157
+ if (x > 1)
158
+ a.push([x, 1]);
159
+ return a;
160
+ }
161
+ function pushPrimeExponentialTo$(a, x, f) {
162
+ if (x % f !== 0)
163
+ return x;
164
+ var e = 0;
165
+ do {
166
+ x /= f;
167
+ ++e;
168
+ } while (x % f === 0);
169
+ a.push([f, e]);
170
+ return x;
171
+ }
100
172
  function isPrime(x) {
101
173
  return x !== 0 && minPrimeFactor(x) === Math.abs(x);
102
174
  }
@@ -252,4 +324,4 @@ function distance(xs, ys) {
252
324
  return Math.sqrt(a);
253
325
  }
254
326
 
255
- export { properDivisors as aliquotParts, aliquotSum, arithmeticMean, binomial, ceil, ceilDiv, constrain as clamp, constrain, cubicMean, degrees, distance, factorial, floor, floorDiv, gcd, geometricMean, harmonicMean, gcd as hcf, isPow, isPrime, lcm, lerp, log, magnitude, remap as map, arithmeticMean as mean, median, mod, modes, modp, multinomial, nextPow, normalize as norm, normalize, prevPow, product, properDivisors, quadriaticMean, radians, range, rem, remap, root, quadriaticMean as rootMeanSquare, round, roundDiv, sum, variance };
327
+ export { properDivisors as aliquotParts, aliquotSum, arithmeticMean, binomial, ceil, ceilDiv, constrain as clamp, constrain, cubicMean, degrees, distance, factorial, floor, floorDiv, gcd, geometricMean, maxPrimeFactor as greatestPrimeFactor, harmonicMean, gcd as hcf, isPow, isPrime, lcm, minPrimeFactor as leastPrimeFactor, lerp, log, magnitude, remap as map, maxPrimeFactor, arithmeticMean as mean, median, minPrimeFactor, mod, modes, modp, multinomial, nextPow, normalize as norm, normalize, prevPow, primeExponentials, primeFactors, product, properDivisors, quadriaticMean, radians, range, rem, remap, root, quadriaticMean as rootMeanSquare, round, roundDiv, sum, variance };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "extra-math",
3
- "version": "1.3.41",
3
+ "version": "1.3.43",
4
4
  "description": "A collection of common mathematical functions.",
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",
@@ -20,7 +20,9 @@
20
20
  "math",
21
21
  "aliquotParts",
22
22
  "clamp",
23
+ "greatestPrimeFactor",
23
24
  "hcf",
25
+ "leastPrimeFactor",
24
26
  "map",
25
27
  "mean",
26
28
  "norm",
@@ -46,7 +48,9 @@
46
48
  "lerp",
47
49
  "log",
48
50
  "magnitude",
51
+ "maxPrimeFactor",
49
52
  "median",
53
+ "minPrimeFactor",
50
54
  "mod",
51
55
  "modes",
52
56
  "modp",
@@ -54,6 +58,8 @@
54
58
  "nextPow",
55
59
  "normalize",
56
60
  "prevPow",
61
+ "primeExponentials",
62
+ "primeFactors",
57
63
  "product",
58
64
  "properDivisors",
59
65
  "quadriaticMean",