@thi.ng/math 5.10.11 → 5.10.13
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/CHANGELOG.md +1 -1
- package/extrema.js +1 -2
- package/interval.js +3 -6
- package/libc.js +1 -2
- package/min-error.js +2 -4
- package/package.json +8 -9
- package/permutations.js +2 -4
- package/prime.js +3 -6
package/CHANGELOG.md
CHANGED
package/extrema.js
CHANGED
|
@@ -14,8 +14,7 @@ const maximaIndex = (values, from = 0, to = values.length) => index(isMaxima, va
|
|
|
14
14
|
function* indices(fn, vals, from = 0, to = vals.length) {
|
|
15
15
|
while (from < to) {
|
|
16
16
|
const i = fn(vals, from, to);
|
|
17
|
-
if (i < 0)
|
|
18
|
-
return;
|
|
17
|
+
if (i < 0) return;
|
|
19
18
|
yield i;
|
|
20
19
|
from = i + 1;
|
|
21
20
|
}
|
package/interval.js
CHANGED
|
@@ -5,18 +5,15 @@ const clamp11 = (x) => x < -1 ? -1 : x > 1 ? 1 : x;
|
|
|
5
5
|
const clamp05 = (x) => x < 0 ? 0 : x > 0.5 ? 0.5 : x;
|
|
6
6
|
const minMax = (x, y) => x < y ? [x, y] : [y, x];
|
|
7
7
|
const wrap = (x, min, max) => {
|
|
8
|
-
if (min === max)
|
|
9
|
-
return min;
|
|
8
|
+
if (min === max) return min;
|
|
10
9
|
if (x > max) {
|
|
11
10
|
const d = max - min;
|
|
12
11
|
x -= d;
|
|
13
|
-
if (x > max)
|
|
14
|
-
x -= d * ((x - min) / d | 0);
|
|
12
|
+
if (x > max) x -= d * ((x - min) / d | 0);
|
|
15
13
|
} else if (x < min) {
|
|
16
14
|
const d = max - min;
|
|
17
15
|
x += d;
|
|
18
|
-
if (x < min)
|
|
19
|
-
x += d * ((min - x) / d + 1 | 0);
|
|
16
|
+
if (x < min) x += d * ((min - x) / d + 1 | 0);
|
|
20
17
|
}
|
|
21
18
|
return x;
|
|
22
19
|
};
|
package/libc.js
CHANGED
|
@@ -4,8 +4,7 @@ const fdim = (x, y) => Math.max(x - y, 0);
|
|
|
4
4
|
const fma = (x, y, z) => x * y + z;
|
|
5
5
|
const fmod = (x, y) => x % y;
|
|
6
6
|
const frexp = (x) => {
|
|
7
|
-
if (x === 0 || !isFinite(x))
|
|
8
|
-
return [x, 0];
|
|
7
|
+
if (x === 0 || !isFinite(x)) return [x, 0];
|
|
9
8
|
const abs = Math.abs(x);
|
|
10
9
|
let exp = Math.max(-1023, Math.floor(Math.log2(abs)) + 1);
|
|
11
10
|
let y = abs * 2 ** -exp;
|
package/min-error.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { EPS } from "./api.js";
|
|
2
2
|
const minError = (fn, error, q, res = 16, iter = 8, start = 0, end = 1, eps = EPS) => {
|
|
3
|
-
if (iter <= 0)
|
|
4
|
-
return (start + end) / 2;
|
|
3
|
+
if (iter <= 0) return (start + end) / 2;
|
|
5
4
|
const delta = (end - start) / res;
|
|
6
5
|
let minT = start;
|
|
7
6
|
let minE = Infinity;
|
|
@@ -9,8 +8,7 @@ const minError = (fn, error, q, res = 16, iter = 8, start = 0, end = 1, eps = EP
|
|
|
9
8
|
const t = start + i * delta;
|
|
10
9
|
const e = error(q, fn(t));
|
|
11
10
|
if (e < minE) {
|
|
12
|
-
if (e <= eps)
|
|
13
|
-
return t;
|
|
11
|
+
if (e <= eps) return t;
|
|
14
12
|
minE = e;
|
|
15
13
|
minT = t;
|
|
16
14
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/math",
|
|
3
|
-
"version": "5.10.
|
|
3
|
+
"version": "5.10.13",
|
|
4
4
|
"description": "Assorted common math functions & utilities",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"build": "yarn build:esbuild && yarn build:decl",
|
|
31
31
|
"build:decl": "tsc --declaration --emitDeclarationOnly",
|
|
32
32
|
"build:esbuild": "esbuild --format=esm --platform=neutral --target=es2022 --tsconfig=tsconfig.json --outdir=. src/**/*.ts",
|
|
33
|
-
"clean": "
|
|
33
|
+
"clean": "bun ../../tools/src/clean-package.ts",
|
|
34
34
|
"doc": "typedoc --excludePrivate --excludeInternal --out doc src/index.ts",
|
|
35
35
|
"doc:ae": "mkdir -p .ae/doc .ae/temp && api-extractor run --local --verbose",
|
|
36
36
|
"doc:readme": "bun ../../tools/src/module-stats.ts && bun ../../tools/src/readme.ts",
|
|
@@ -39,14 +39,13 @@
|
|
|
39
39
|
"tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@thi.ng/api": "^8.11.
|
|
42
|
+
"@thi.ng/api": "^8.11.2"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@microsoft/api-extractor": "^7.43.
|
|
46
|
-
"esbuild": "^0.
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"typescript": "^5.4.3"
|
|
45
|
+
"@microsoft/api-extractor": "^7.43.2",
|
|
46
|
+
"esbuild": "^0.21.1",
|
|
47
|
+
"typedoc": "^0.25.13",
|
|
48
|
+
"typescript": "^5.4.5"
|
|
50
49
|
},
|
|
51
50
|
"keywords": [
|
|
52
51
|
"animation",
|
|
@@ -143,5 +142,5 @@
|
|
|
143
142
|
"thi.ng": {
|
|
144
143
|
"year": 2013
|
|
145
144
|
},
|
|
146
|
-
"gitHead": "
|
|
145
|
+
"gitHead": "df34b4a9e650cc7323575356de207d78933bdcf3\n"
|
|
147
146
|
}
|
package/permutations.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
const factorial = (n) => {
|
|
2
|
-
if (n < 0)
|
|
3
|
-
throw new Error(`illegal argument: ${n}`);
|
|
2
|
+
if (n < 0) throw new Error(`illegal argument: ${n}`);
|
|
4
3
|
let res = 1;
|
|
5
|
-
for (let i = 1; i <= n; i++)
|
|
6
|
-
res *= i;
|
|
4
|
+
for (let i = 1; i <= n; i++) res *= i;
|
|
7
5
|
return res;
|
|
8
6
|
};
|
|
9
7
|
const permutationsWithRep = (n, k) => n ** k;
|
package/prime.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
function* primesUntil(x) {
|
|
2
|
-
if (x < 1)
|
|
3
|
-
return;
|
|
2
|
+
if (x < 1) return;
|
|
4
3
|
yield 1;
|
|
5
4
|
const sieve = [];
|
|
6
5
|
const max = Math.sqrt(x) | 0;
|
|
@@ -12,8 +11,7 @@ function* primesUntil(x) {
|
|
|
12
11
|
}
|
|
13
12
|
}
|
|
14
13
|
const nearestPrime = (x) => {
|
|
15
|
-
if (x < 1)
|
|
16
|
-
return -1;
|
|
14
|
+
if (x < 1) return -1;
|
|
17
15
|
let prime = 1;
|
|
18
16
|
const sieve = [];
|
|
19
17
|
const max = Math.sqrt(x) | 0;
|
|
@@ -27,8 +25,7 @@ const nearestPrime = (x) => {
|
|
|
27
25
|
};
|
|
28
26
|
const __updateSieve = (sieve, i, x, max) => {
|
|
29
27
|
if (i <= max) {
|
|
30
|
-
for (let j = i * i; j <= x; j += i)
|
|
31
|
-
sieve[j] = true;
|
|
28
|
+
for (let j = i * i; j <= x; j += i) sieve[j] = true;
|
|
32
29
|
}
|
|
33
30
|
};
|
|
34
31
|
export {
|