extra-math 1.3.39 → 1.3.41
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 +9 -8
- package/index.js +38 -25
- package/index.mjs +38 -24
- package/package.json +10 -9
package/index.d.ts
CHANGED
|
@@ -60,7 +60,7 @@ declare function roundDiv(x: number, y: number): number;
|
|
|
60
60
|
* [📘](https://github.com/nodef/extra-math/wiki/rem)
|
|
61
61
|
* @param x dividend
|
|
62
62
|
* @param y divisor
|
|
63
|
-
* @returns trunc(x
|
|
63
|
+
* @returns trunc(x % y)
|
|
64
64
|
* */
|
|
65
65
|
|
|
66
66
|
|
|
@@ -70,7 +70,7 @@ declare function rem(x: number, y: number): number;
|
|
|
70
70
|
* [📘](https://github.com/nodef/extra-math/wiki/mod)
|
|
71
71
|
* @param x dividend
|
|
72
72
|
* @param y divisor
|
|
73
|
-
* @returns floor(x
|
|
73
|
+
* @returns floor(x % y)
|
|
74
74
|
* */
|
|
75
75
|
|
|
76
76
|
|
|
@@ -80,7 +80,7 @@ declare function mod(x: number, y: number): number;
|
|
|
80
80
|
* [📘](https://github.com/nodef/extra-math/wiki/modp)
|
|
81
81
|
* @param x dividend
|
|
82
82
|
* @param y divisor
|
|
83
|
-
* @returns n>0: floor(x
|
|
83
|
+
* @returns n>0: floor(x % y), n<0: ceil(x % y)
|
|
84
84
|
* */
|
|
85
85
|
|
|
86
86
|
|
|
@@ -145,21 +145,21 @@ declare function lerp(x: number, y: number, t: number): number;
|
|
|
145
145
|
|
|
146
146
|
declare function isPow(x: number, n: number): boolean;
|
|
147
147
|
/**
|
|
148
|
-
*
|
|
148
|
+
* Find largest power-of-n less than or equal to given number.
|
|
149
149
|
* [📘](https://github.com/nodef/extra-math/wiki/prevPow)
|
|
150
150
|
* @param x a number
|
|
151
151
|
* @param n base
|
|
152
|
-
* @returns
|
|
152
|
+
* @returns nⁱ | nⁱ ≤ x and nⁱ > x/n
|
|
153
153
|
* */
|
|
154
154
|
|
|
155
155
|
|
|
156
156
|
declare function prevPow(x: number, n: number): number;
|
|
157
157
|
/**
|
|
158
|
-
* Find
|
|
158
|
+
* Find smallest power-of-n greater than or equal to given number.
|
|
159
159
|
* [📘](https://github.com/nodef/extra-math/wiki/nextPow)
|
|
160
160
|
* @param x a number
|
|
161
161
|
* @param n base
|
|
162
|
-
* @returns
|
|
162
|
+
* @returns nⁱ | nⁱ ≥ x and nⁱ < n*x
|
|
163
163
|
* */
|
|
164
164
|
|
|
165
165
|
|
|
@@ -193,6 +193,7 @@ declare function log(x: number, b?: number): number;
|
|
|
193
193
|
|
|
194
194
|
|
|
195
195
|
declare function properDivisors(x: number): number[];
|
|
196
|
+
|
|
196
197
|
/**
|
|
197
198
|
* Sum all proper divisors of a number.
|
|
198
199
|
* [📘](https://github.com/nodef/extra-math/wiki/aliquotSum)
|
|
@@ -397,4 +398,4 @@ declare function magnitude(xs: number[]): number;
|
|
|
397
398
|
|
|
398
399
|
declare function distance(xs: number[], ys: number[]): number;
|
|
399
400
|
|
|
400
|
-
export { 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 };
|
|
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 };
|
package/index.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
function floor(x, pre = 1) {
|
|
6
4
|
return Math.floor(x / pre) * pre;
|
|
7
5
|
}
|
|
@@ -50,12 +48,16 @@ function isPow(x, n) {
|
|
|
50
48
|
return x < 0 ? n < 0 && (p & 1) === 1 : n > 0 || (p & 1) === 0;
|
|
51
49
|
}
|
|
52
50
|
function prevPow(x, n) {
|
|
53
|
-
|
|
54
|
-
|
|
51
|
+
if (x <= 1)
|
|
52
|
+
return 0;
|
|
53
|
+
var p = Math.floor(Math.log(x) / Math.log(n));
|
|
54
|
+
return Math.pow(n, p);
|
|
55
55
|
}
|
|
56
56
|
function nextPow(x, n) {
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
if (x <= 0)
|
|
58
|
+
return 1;
|
|
59
|
+
var p = Math.ceil(Math.log(x) / Math.log(n));
|
|
60
|
+
return Math.pow(n, p);
|
|
59
61
|
}
|
|
60
62
|
function root(x, n) {
|
|
61
63
|
if ((n & 1) === 0)
|
|
@@ -79,31 +81,41 @@ function aliquotSum(x) {
|
|
|
79
81
|
a += i;
|
|
80
82
|
return a;
|
|
81
83
|
}
|
|
82
|
-
function
|
|
84
|
+
function minPrimeFactor(x) {
|
|
83
85
|
var x = Math.abs(x);
|
|
86
|
+
if (x <= 1)
|
|
87
|
+
return 0;
|
|
84
88
|
if (x <= 3)
|
|
85
|
-
return x
|
|
86
|
-
if (x % 2 === 0
|
|
87
|
-
return
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
var t = y;
|
|
96
|
-
y = x % y;
|
|
97
|
-
x = t;
|
|
89
|
+
return x;
|
|
90
|
+
if (x % 2 === 0)
|
|
91
|
+
return 2;
|
|
92
|
+
if (x % 3 === 0)
|
|
93
|
+
return 3;
|
|
94
|
+
for (var i = 6, I = Math.sqrt(x) + 1; i <= I; i += 6) {
|
|
95
|
+
if (x % (i - 1) === 0)
|
|
96
|
+
return i - 1;
|
|
97
|
+
if (x % (i + 1) === 0)
|
|
98
|
+
return i + 1;
|
|
98
99
|
}
|
|
99
100
|
return x;
|
|
100
101
|
}
|
|
102
|
+
function isPrime(x) {
|
|
103
|
+
return x !== 0 && minPrimeFactor(x) === Math.abs(x);
|
|
104
|
+
}
|
|
101
105
|
function gcd(...xs) {
|
|
102
106
|
var a = xs[0] || 1;
|
|
103
107
|
for (var i = 1, I = xs.length; i < I; i++)
|
|
104
108
|
a = gcdPair(a, xs[i]);
|
|
105
109
|
return a;
|
|
106
110
|
}
|
|
111
|
+
function gcdPair(x, y) {
|
|
112
|
+
while (y !== 0) {
|
|
113
|
+
var t = y;
|
|
114
|
+
y = x % y;
|
|
115
|
+
x = t;
|
|
116
|
+
}
|
|
117
|
+
return x;
|
|
118
|
+
}
|
|
107
119
|
function lcm(...xs) {
|
|
108
120
|
var a = xs[0] || 1;
|
|
109
121
|
for (var i = 1, I = xs.length; i < I; i++)
|
|
@@ -164,6 +176,11 @@ function median(...xs) {
|
|
|
164
176
|
return xs[i];
|
|
165
177
|
return (xs[i - 1] + xs[i]) / 2;
|
|
166
178
|
}
|
|
179
|
+
function modes(...xs) {
|
|
180
|
+
xs.sort((a, b) => a - b);
|
|
181
|
+
var r = maxRepeat(xs);
|
|
182
|
+
return getRepeats(xs, r);
|
|
183
|
+
}
|
|
167
184
|
function maxRepeat(xs) {
|
|
168
185
|
var count = Math.min(xs.length, 1), max = count;
|
|
169
186
|
for (var i = 1, I = xs.length; i < I; i++) {
|
|
@@ -184,11 +201,6 @@ function getRepeats(xs, r) {
|
|
|
184
201
|
a.push(xs[i += r]);
|
|
185
202
|
return a;
|
|
186
203
|
}
|
|
187
|
-
function modes(...xs) {
|
|
188
|
-
xs.sort((a, b) => a - b);
|
|
189
|
-
var r = maxRepeat(xs);
|
|
190
|
-
return getRepeats(xs, r);
|
|
191
|
-
}
|
|
192
204
|
function range(...xs) {
|
|
193
205
|
return [Math.min(...xs), Math.max(...xs)];
|
|
194
206
|
}
|
|
@@ -242,6 +254,7 @@ function distance(xs, ys) {
|
|
|
242
254
|
return Math.sqrt(a);
|
|
243
255
|
}
|
|
244
256
|
|
|
257
|
+
exports.aliquotParts = properDivisors;
|
|
245
258
|
exports.aliquotSum = aliquotSum;
|
|
246
259
|
exports.arithmeticMean = arithmeticMean;
|
|
247
260
|
exports.binomial = binomial;
|
package/index.mjs
CHANGED
|
@@ -46,12 +46,16 @@ function isPow(x, n) {
|
|
|
46
46
|
return x < 0 ? n < 0 && (p & 1) === 1 : n > 0 || (p & 1) === 0;
|
|
47
47
|
}
|
|
48
48
|
function prevPow(x, n) {
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
if (x <= 1)
|
|
50
|
+
return 0;
|
|
51
|
+
var p = Math.floor(Math.log(x) / Math.log(n));
|
|
52
|
+
return Math.pow(n, p);
|
|
51
53
|
}
|
|
52
54
|
function nextPow(x, n) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
if (x <= 0)
|
|
56
|
+
return 1;
|
|
57
|
+
var p = Math.ceil(Math.log(x) / Math.log(n));
|
|
58
|
+
return Math.pow(n, p);
|
|
55
59
|
}
|
|
56
60
|
function root(x, n) {
|
|
57
61
|
if ((n & 1) === 0)
|
|
@@ -75,31 +79,41 @@ function aliquotSum(x) {
|
|
|
75
79
|
a += i;
|
|
76
80
|
return a;
|
|
77
81
|
}
|
|
78
|
-
function
|
|
82
|
+
function minPrimeFactor(x) {
|
|
79
83
|
var x = Math.abs(x);
|
|
84
|
+
if (x <= 1)
|
|
85
|
+
return 0;
|
|
80
86
|
if (x <= 3)
|
|
81
|
-
return x
|
|
82
|
-
if (x % 2 === 0
|
|
83
|
-
return
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
var t = y;
|
|
92
|
-
y = x % y;
|
|
93
|
-
x = t;
|
|
87
|
+
return x;
|
|
88
|
+
if (x % 2 === 0)
|
|
89
|
+
return 2;
|
|
90
|
+
if (x % 3 === 0)
|
|
91
|
+
return 3;
|
|
92
|
+
for (var i = 6, I = Math.sqrt(x) + 1; i <= I; i += 6) {
|
|
93
|
+
if (x % (i - 1) === 0)
|
|
94
|
+
return i - 1;
|
|
95
|
+
if (x % (i + 1) === 0)
|
|
96
|
+
return i + 1;
|
|
94
97
|
}
|
|
95
98
|
return x;
|
|
96
99
|
}
|
|
100
|
+
function isPrime(x) {
|
|
101
|
+
return x !== 0 && minPrimeFactor(x) === Math.abs(x);
|
|
102
|
+
}
|
|
97
103
|
function gcd(...xs) {
|
|
98
104
|
var a = xs[0] || 1;
|
|
99
105
|
for (var i = 1, I = xs.length; i < I; i++)
|
|
100
106
|
a = gcdPair(a, xs[i]);
|
|
101
107
|
return a;
|
|
102
108
|
}
|
|
109
|
+
function gcdPair(x, y) {
|
|
110
|
+
while (y !== 0) {
|
|
111
|
+
var t = y;
|
|
112
|
+
y = x % y;
|
|
113
|
+
x = t;
|
|
114
|
+
}
|
|
115
|
+
return x;
|
|
116
|
+
}
|
|
103
117
|
function lcm(...xs) {
|
|
104
118
|
var a = xs[0] || 1;
|
|
105
119
|
for (var i = 1, I = xs.length; i < I; i++)
|
|
@@ -160,6 +174,11 @@ function median(...xs) {
|
|
|
160
174
|
return xs[i];
|
|
161
175
|
return (xs[i - 1] + xs[i]) / 2;
|
|
162
176
|
}
|
|
177
|
+
function modes(...xs) {
|
|
178
|
+
xs.sort((a, b) => a - b);
|
|
179
|
+
var r = maxRepeat(xs);
|
|
180
|
+
return getRepeats(xs, r);
|
|
181
|
+
}
|
|
163
182
|
function maxRepeat(xs) {
|
|
164
183
|
var count = Math.min(xs.length, 1), max = count;
|
|
165
184
|
for (var i = 1, I = xs.length; i < I; i++) {
|
|
@@ -180,11 +199,6 @@ function getRepeats(xs, r) {
|
|
|
180
199
|
a.push(xs[i += r]);
|
|
181
200
|
return a;
|
|
182
201
|
}
|
|
183
|
-
function modes(...xs) {
|
|
184
|
-
xs.sort((a, b) => a - b);
|
|
185
|
-
var r = maxRepeat(xs);
|
|
186
|
-
return getRepeats(xs, r);
|
|
187
|
-
}
|
|
188
202
|
function range(...xs) {
|
|
189
203
|
return [Math.min(...xs), Math.max(...xs)];
|
|
190
204
|
}
|
|
@@ -238,4 +252,4 @@ function distance(xs, ys) {
|
|
|
238
252
|
return Math.sqrt(a);
|
|
239
253
|
}
|
|
240
254
|
|
|
241
|
-
export { 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 };
|
|
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 };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "extra-math",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.41",
|
|
4
4
|
"description": "A collection of common mathematical functions.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.mjs",
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"keywords": [
|
|
19
19
|
"extra",
|
|
20
20
|
"math",
|
|
21
|
+
"aliquotParts",
|
|
21
22
|
"clamp",
|
|
22
23
|
"hcf",
|
|
23
24
|
"map",
|
|
@@ -77,14 +78,14 @@
|
|
|
77
78
|
},
|
|
78
79
|
"homepage": "https://github.com/nodef/extra-math#readme",
|
|
79
80
|
"devDependencies": {
|
|
80
|
-
"@rollup/plugin-commonjs": "^
|
|
81
|
-
"@rollup/plugin-node-resolve": "^
|
|
82
|
-
"@types/jest": "^
|
|
83
|
-
"extra-build": "^2.2.
|
|
84
|
-
"extra-number": "^2.
|
|
85
|
-
"jest": "^
|
|
81
|
+
"@rollup/plugin-commonjs": "^23.0.2",
|
|
82
|
+
"@rollup/plugin-node-resolve": "^15.0.1",
|
|
83
|
+
"@types/jest": "^29.2.1",
|
|
84
|
+
"extra-build": "^2.2.35",
|
|
85
|
+
"extra-number": "^2.3.1",
|
|
86
|
+
"jest": "^29.2.2",
|
|
86
87
|
"rollup-plugin-cleanup": "^3.2.1",
|
|
87
|
-
"rollup-plugin-dts": "^
|
|
88
|
-
"ts-jest": "^
|
|
88
|
+
"rollup-plugin-dts": "^5.0.0",
|
|
89
|
+
"ts-jest": "^29.0.3"
|
|
89
90
|
}
|
|
90
91
|
}
|