@tktb-tess/util-fns 0.10.1 → 0.11.1
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 +0 -46
- package/dist/bundle.js +467 -419
- package/dist/bundle.min.js +2 -2
- package/dist/icon.svg +23 -0
- package/dist/main.d.ts +6 -5
- package/dist/math.d.ts +1 -1
- package/dist/{named-error.d.ts → named_error.d.ts} +1 -1
- package/dist/util.d.ts +9 -2
- package/dist/worker_stream.d.ts +7 -0
- package/package.json +4 -4
- /package/dist/{baillie-psw.d.ts → baillie_psw.d.ts} +0 -0
- /package/dist/{pcg-minimal.d.ts → pcg_minimal.d.ts} +0 -0
- /package/dist/{u8arr-ext.d.ts → u8arr_ext.d.ts} +0 -0
- /package/dist/{xoshiro-minimal.d.ts → xoshiro_minimal.d.ts} +0 -0
package/dist/bundle.js
CHANGED
|
@@ -1,216 +1,252 @@
|
|
|
1
|
-
const
|
|
2
|
-
if (typeof
|
|
3
|
-
const
|
|
4
|
-
if (
|
|
5
|
-
if (typeof
|
|
6
|
-
return
|
|
7
|
-
if (typeof
|
|
8
|
-
return
|
|
9
|
-
if (typeof
|
|
1
|
+
const T = new TextEncoder(), Y = (e, t) => [e].includes(t), d = (e, t) => {
|
|
2
|
+
if (typeof e != typeof t) return !1;
|
|
3
|
+
const n = Object.prototype.toString.call(e), r = Object.prototype.toString.call(t);
|
|
4
|
+
if (n !== r) return !1;
|
|
5
|
+
if (typeof e == "string" || typeof e == "bigint" || typeof e == "boolean" || typeof e == "symbol" || e == null)
|
|
6
|
+
return e === t;
|
|
7
|
+
if (typeof e == "number")
|
|
8
|
+
return e !== e && t !== t || e === t;
|
|
9
|
+
if (typeof e == "function")
|
|
10
10
|
return !1;
|
|
11
|
-
if (Array.isArray(
|
|
12
|
-
if (
|
|
13
|
-
for (let
|
|
14
|
-
if (!
|
|
11
|
+
if (Array.isArray(e) && Array.isArray(t)) {
|
|
12
|
+
if (e.length !== t.length) return !1;
|
|
13
|
+
for (let s = 0; s < e.length; s++)
|
|
14
|
+
if (!d(e[s], t[s])) return !1;
|
|
15
15
|
return !0;
|
|
16
16
|
}
|
|
17
|
-
if (
|
|
18
|
-
const
|
|
19
|
-
return !!
|
|
17
|
+
if (e instanceof Set && t instanceof Set) {
|
|
18
|
+
const s = [...e.values()], o = [...t.values()];
|
|
19
|
+
return !!d(s, o);
|
|
20
20
|
}
|
|
21
|
-
if (
|
|
22
|
-
const
|
|
23
|
-
if (!
|
|
24
|
-
const i = [...
|
|
25
|
-
return !!
|
|
21
|
+
if (e instanceof Map && t instanceof Map) {
|
|
22
|
+
const s = [...e.keys()], o = [...t.keys()];
|
|
23
|
+
if (!d(s, o)) return !1;
|
|
24
|
+
const i = [...e.values()], c = [...t.values()];
|
|
25
|
+
return !!d(i, c);
|
|
26
26
|
}
|
|
27
|
-
if (
|
|
28
|
-
const
|
|
29
|
-
for (const
|
|
30
|
-
const l = c.find((
|
|
27
|
+
if (n === "[object Object]") {
|
|
28
|
+
const s = e, o = t, i = Object.keys(s), c = Object.keys(o);
|
|
29
|
+
for (const a of i) {
|
|
30
|
+
const l = c.find((p) => p === a);
|
|
31
31
|
if (l === void 0) return !1;
|
|
32
|
-
const [
|
|
33
|
-
if (!
|
|
32
|
+
const [f, h] = [s[a], o[l]];
|
|
33
|
+
if (!d(f, h)) return !1;
|
|
34
34
|
}
|
|
35
35
|
return !0;
|
|
36
36
|
}
|
|
37
|
-
throw Error(`comparing these objects is unavailable: ${
|
|
38
|
-
cause: [
|
|
37
|
+
throw Error(`comparing these objects is unavailable: ${e}, ${t}`, {
|
|
38
|
+
cause: [e, t]
|
|
39
39
|
});
|
|
40
|
-
},
|
|
41
|
-
let
|
|
40
|
+
}, Z = () => {
|
|
41
|
+
let e, t;
|
|
42
42
|
return {
|
|
43
|
-
promise: new Promise((r,
|
|
44
|
-
|
|
43
|
+
promise: new Promise((r, s) => {
|
|
44
|
+
e = r, t = s;
|
|
45
45
|
}),
|
|
46
|
-
resolve:
|
|
46
|
+
resolve: e,
|
|
47
47
|
reject: t
|
|
48
48
|
};
|
|
49
|
-
},
|
|
50
|
-
setTimeout(() => t(),
|
|
51
|
-
}),
|
|
49
|
+
}, Q = (e) => new Promise((t) => {
|
|
50
|
+
setTimeout(() => t(), e);
|
|
51
|
+
}), tt = (e) => {
|
|
52
|
+
const t = Object.prototype.toString.call(e);
|
|
53
|
+
return t.slice(8, t.length - 1);
|
|
54
|
+
}, et = (e) => (...t) => () => e(...t), nt = (e) => {
|
|
52
55
|
const t = [];
|
|
53
|
-
let
|
|
54
|
-
for (let
|
|
55
|
-
const i =
|
|
56
|
-
i === '"' && (
|
|
57
|
-
` && !
|
|
58
|
-
}
|
|
59
|
-
return
|
|
60
|
-
},
|
|
61
|
-
const
|
|
56
|
+
let n = [], r = "", s = !1;
|
|
57
|
+
for (let o = 0; o < e.length; o++) {
|
|
58
|
+
const i = e[o];
|
|
59
|
+
i === '"' && (o === 0 || e[o - 1] !== "\\") ? s = !s : i === "," && !s ? (n.push(r.trim()), r = "") : i === `
|
|
60
|
+
` && !s ? (n.push(r.trim()), t.push(n), n = [], r = "") : r += i;
|
|
61
|
+
}
|
|
62
|
+
return n.push(r.trim()), t.push(n), t;
|
|
63
|
+
}, rt = async (e, t) => {
|
|
64
|
+
const n = T.encode(e), r = await crypto.subtle.digest(t, n);
|
|
62
65
|
return new Uint8Array(r);
|
|
63
|
-
},
|
|
66
|
+
}, st = () => !!globalThis.process && typeof process.version < "u" && typeof process.versions.node < "u", ot = (e) => encodeURIComponent(e).replace(
|
|
64
67
|
/[!'()*]/g,
|
|
65
|
-
(
|
|
66
|
-
),
|
|
67
|
-
if (
|
|
68
|
+
(n) => `%${n.charCodeAt(0).toString(16).toUpperCase()}`
|
|
69
|
+
), it = (e) => {
|
|
70
|
+
if (e.includes("+"))
|
|
68
71
|
throw Error("An input string has '+'");
|
|
69
|
-
return decodeURIComponent(
|
|
70
|
-
},
|
|
71
|
-
const r = new Blob([
|
|
72
|
+
return decodeURIComponent(e);
|
|
73
|
+
}, ct = async (e, t) => {
|
|
74
|
+
const r = new Blob([e]).stream().pipeThrough(new CompressionStream(t));
|
|
72
75
|
return new Response(r).bytes();
|
|
73
|
-
},
|
|
74
|
-
const r = new Blob([
|
|
76
|
+
}, at = async (e, t) => {
|
|
77
|
+
const r = new Blob([e]).stream().pipeThrough(new DecompressionStream(t));
|
|
75
78
|
return new Response(r).bytes();
|
|
76
|
-
},
|
|
79
|
+
}, lt = (e, t) => new Promise((n, r) => {
|
|
80
|
+
setTimeout(async () => {
|
|
81
|
+
try {
|
|
82
|
+
const s = await e();
|
|
83
|
+
n(s);
|
|
84
|
+
} catch (s) {
|
|
85
|
+
r(s);
|
|
86
|
+
}
|
|
87
|
+
}, t);
|
|
88
|
+
}), N = "NamedError";
|
|
89
|
+
class w extends Error {
|
|
90
|
+
constructor(t, n, r) {
|
|
91
|
+
super(n, r), this.errName = t;
|
|
92
|
+
}
|
|
93
|
+
static name = N;
|
|
94
|
+
toJSON() {
|
|
95
|
+
const t = (() => {
|
|
96
|
+
const o = this.cause;
|
|
97
|
+
return typeof o == "string" || typeof o == "number" || typeof o == "boolean" ? o : typeof o == "bigint" ? o.toString() : typeof o == "object" && o !== null ? o instanceof Set || o instanceof Map ? Object.fromEntries(o) : o : void 0;
|
|
98
|
+
})(), { errName: n, message: r, stack: s } = this;
|
|
99
|
+
return {
|
|
100
|
+
errName: n,
|
|
101
|
+
message: r,
|
|
102
|
+
stack: s,
|
|
103
|
+
cause: t
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
Object.defineProperty(w.prototype, Symbol.toStringTag, {
|
|
108
|
+
value: N
|
|
109
|
+
});
|
|
110
|
+
const ut = (e, t) => Math.floor(Math.random() * (t - e) + e), g = (e, t) => {
|
|
77
111
|
t < 0n && (t *= -1n);
|
|
78
|
-
const
|
|
79
|
-
return
|
|
80
|
-
},
|
|
81
|
-
if (!Number.isFinite(
|
|
82
|
-
if (
|
|
83
|
-
const
|
|
84
|
-
let
|
|
85
|
-
return t && (
|
|
86
|
-
},
|
|
87
|
-
if (
|
|
88
|
-
|
|
112
|
+
const n = e % t;
|
|
113
|
+
return n < 0n ? n + t : n;
|
|
114
|
+
}, v = (e, t = !1) => {
|
|
115
|
+
if (!Number.isFinite(e)) throw Error("`length` is not a valid number");
|
|
116
|
+
if (e <= 0) throw Error("`length` must be positive");
|
|
117
|
+
const n = Math.ceil(e / 8), r = crypto.getRandomValues(new Uint8Array(n));
|
|
118
|
+
let s = Array.from(r, (o) => o.toString(2).padStart(8, "0")).join("").slice(0, e);
|
|
119
|
+
return t && (s = s.replace(/^\d/, "1")), BigInt("0b" + s);
|
|
120
|
+
}, P = (e, t) => {
|
|
121
|
+
if (e >= t)
|
|
122
|
+
throw new w("RangeError", "min is larger than max");
|
|
123
|
+
const n = t - e, r = n.toString(2).length, s = (() => {
|
|
89
124
|
for (let i = 0; i < 1e5; i++) {
|
|
90
|
-
const c =
|
|
91
|
-
if (c >=
|
|
92
|
-
return c %
|
|
125
|
+
const c = v(r);
|
|
126
|
+
if (c >= m(2n, BigInt(r), n))
|
|
127
|
+
return c % n;
|
|
93
128
|
}
|
|
94
129
|
throw Error("Failed to generate a random bigint");
|
|
95
130
|
})();
|
|
96
|
-
return
|
|
97
|
-
},
|
|
98
|
-
if (
|
|
131
|
+
return e + s;
|
|
132
|
+
}, m = (e, t, n) => {
|
|
133
|
+
if (n < 1n) throw Error("`mod` must be positive");
|
|
99
134
|
if (t < 0n) throw Error("`power` must not be negative");
|
|
100
|
-
if (
|
|
101
|
-
if (
|
|
102
|
-
if (
|
|
135
|
+
if (e = g(e, n), n === 1n) return 0n;
|
|
136
|
+
if (e % n === 1n || e % n === 0n) return e;
|
|
137
|
+
if (e === n - 1n) return t & 1n ? n - 1n : 1n;
|
|
103
138
|
let r = 1n;
|
|
104
139
|
for (; t > 0n; )
|
|
105
|
-
t & 1n && (r = r *
|
|
140
|
+
t & 1n && (r = r * e % n), e = e * e % n, t >>= 1n;
|
|
106
141
|
return r;
|
|
107
|
-
}, _ = (
|
|
108
|
-
if (
|
|
109
|
-
if (
|
|
142
|
+
}, _ = (e, t) => {
|
|
143
|
+
if (e === 0n && t === 0n) return { x: 0n, y: 0n, gcd: 0n };
|
|
144
|
+
if (e === 0n)
|
|
110
145
|
return t > 0n ? { x: 0n, y: -1n, gcd: t } : { x: 0n, y: 1n, gcd: -t };
|
|
111
146
|
if (t === 0n)
|
|
112
|
-
return
|
|
113
|
-
let [
|
|
147
|
+
return e > 0n ? { x: 1n, y: 0n, gcd: e } : { x: -1n, y: 0n, gcd: -e };
|
|
148
|
+
let [n, r, s] = [1n, 0n, e], [o, i, c] = [0n, -1n, t];
|
|
114
149
|
for (; ; ) {
|
|
115
|
-
const
|
|
150
|
+
const a = s / c, l = s - a * c;
|
|
116
151
|
if (l === 0n) break;
|
|
117
|
-
[
|
|
118
|
-
}
|
|
119
|
-
return c < 0n && (
|
|
120
|
-
},
|
|
121
|
-
if (
|
|
122
|
-
const
|
|
123
|
-
if (
|
|
124
|
-
let c =
|
|
125
|
-
for (let
|
|
126
|
-
c *=
|
|
152
|
+
[n, o] = [o, n - a * o], [r, i] = [i, r - a * i], [s, c] = [c, l];
|
|
153
|
+
}
|
|
154
|
+
return c < 0n && (o *= -1n, i *= -1n, c *= -1n), { x: o, y: i, gcd: c };
|
|
155
|
+
}, I = (e, t) => {
|
|
156
|
+
if (e >= t) return 1n;
|
|
157
|
+
const n = BigInt((t - 2n).toString(2).length), r = (t - e) / 2n;
|
|
158
|
+
if (n * r < 63n) {
|
|
159
|
+
let c = e;
|
|
160
|
+
for (let a = e + 2n; a < t; a += 2n)
|
|
161
|
+
c *= a;
|
|
127
162
|
return c;
|
|
128
163
|
}
|
|
129
|
-
const
|
|
130
|
-
return
|
|
131
|
-
}, j = (
|
|
132
|
-
let t = 3n,
|
|
133
|
-
const
|
|
134
|
-
for (let
|
|
135
|
-
const i = (
|
|
136
|
-
r *=
|
|
137
|
-
}
|
|
138
|
-
return
|
|
139
|
-
},
|
|
140
|
-
if (
|
|
141
|
-
if (
|
|
142
|
-
const t =
|
|
143
|
-
return j(
|
|
144
|
-
},
|
|
164
|
+
const s = e + r | 1n, o = I(e, s), i = I(s, t);
|
|
165
|
+
return o * i;
|
|
166
|
+
}, j = (e) => {
|
|
167
|
+
let t = 3n, n = 1n, r = 1n;
|
|
168
|
+
const s = BigInt(e.toString(2).length) - 1n;
|
|
169
|
+
for (let o = s - 1n; o > -1n; --o) {
|
|
170
|
+
const i = (e >> o) + 1n | 1n;
|
|
171
|
+
r *= I(t, i), t = i, n *= r;
|
|
172
|
+
}
|
|
173
|
+
return n;
|
|
174
|
+
}, ft = (e) => {
|
|
175
|
+
if (e < 0n) throw Error("'n' must be non-negative");
|
|
176
|
+
if (e === 0n) return 1n;
|
|
177
|
+
const t = e - BigInt(e.toString(2).match(/1/g)?.length ?? 0);
|
|
178
|
+
return j(e) << t;
|
|
179
|
+
}, C = (e, t) => (e >>> (t & 31) | e << (-t & 31)) >>> 0, b = (e, t) => BigInt.asUintN(64, e >> (t & 63n) | e << (-t & 63n)), E = (e, t) => {
|
|
145
180
|
if (t < 1n || t % 2n === 0n)
|
|
146
181
|
throw Error("`n` is invalid");
|
|
147
|
-
for (;
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
let
|
|
151
|
-
for (;
|
|
152
|
-
for (;
|
|
153
|
-
|
|
182
|
+
for (; e < 0n; )
|
|
183
|
+
e += t;
|
|
184
|
+
e %= t;
|
|
185
|
+
let n = 1n;
|
|
186
|
+
for (; e !== 0n; ) {
|
|
187
|
+
for (; e % 2n === 0n; ) {
|
|
188
|
+
e /= 2n;
|
|
154
189
|
const r = t % 8n;
|
|
155
|
-
(r === 3n || r === 5n) && (
|
|
190
|
+
(r === 3n || r === 5n) && (n *= -1n);
|
|
156
191
|
}
|
|
157
|
-
[
|
|
158
|
-
}
|
|
159
|
-
return t === 1n ?
|
|
160
|
-
}, O = (
|
|
161
|
-
if (
|
|
162
|
-
if (
|
|
163
|
-
let t = 1n,
|
|
164
|
-
for (; t + 1n <
|
|
165
|
-
const r = (t +
|
|
166
|
-
r
|
|
167
|
-
}
|
|
168
|
-
return
|
|
169
|
-
},
|
|
170
|
-
if (
|
|
171
|
-
if (
|
|
172
|
-
let t =
|
|
192
|
+
[e, t] = [t, e], e % 4n === 3n && t % 4n === 3n && (n *= -1n), e %= t;
|
|
193
|
+
}
|
|
194
|
+
return t === 1n ? n : 0n;
|
|
195
|
+
}, O = (e) => {
|
|
196
|
+
if (e < 0n) return !1;
|
|
197
|
+
if (e === 0n) return !0;
|
|
198
|
+
let t = 1n, n = e;
|
|
199
|
+
for (; t + 1n < n; ) {
|
|
200
|
+
const r = (t + n) / 2n;
|
|
201
|
+
r * r < e ? t = r : n = r;
|
|
202
|
+
}
|
|
203
|
+
return e === t ** 2n || e === (t + 1n) ** 2n;
|
|
204
|
+
}, F = (e) => {
|
|
205
|
+
if (e <= 1n) return !1;
|
|
206
|
+
if (e % 2n === 0n) return e === 2n;
|
|
207
|
+
let t = e - 1n, n = 0n;
|
|
173
208
|
for (; t % 2n === 0n; )
|
|
174
|
-
t >>= 1n,
|
|
175
|
-
const [r,
|
|
176
|
-
let i =
|
|
209
|
+
t >>= 1n, n += 1n;
|
|
210
|
+
const [r, s] = [t, n];
|
|
211
|
+
let i = m(2n, r, e);
|
|
177
212
|
if (i === 1n) return !0;
|
|
178
|
-
for (let c = 0n; c <
|
|
179
|
-
if (i ===
|
|
180
|
-
i = i * i %
|
|
213
|
+
for (let c = 0n; c < s; c++) {
|
|
214
|
+
if (i === e - 1n) return !0;
|
|
215
|
+
i = i * i % e;
|
|
181
216
|
}
|
|
182
217
|
return !1;
|
|
183
|
-
},
|
|
184
|
-
let t = 5n,
|
|
185
|
-
for (;
|
|
186
|
-
if (t = t > 0n ? t + 2n : t - 2n, t *= -1n, t === -15n && O(
|
|
218
|
+
}, V = (e) => {
|
|
219
|
+
let t = 5n, n = E(t, e);
|
|
220
|
+
for (; n > 0n; ) {
|
|
221
|
+
if (t = t > 0n ? t + 2n : t - 2n, t *= -1n, t === -15n && O(e))
|
|
187
222
|
return [0n, 0n];
|
|
188
|
-
|
|
223
|
+
n = E(t, e);
|
|
189
224
|
}
|
|
190
|
-
return [t,
|
|
191
|
-
},
|
|
192
|
-
let
|
|
193
|
-
const i =
|
|
225
|
+
return [t, n];
|
|
226
|
+
}, y = (e, t) => (e & 1n) === 1n ? g(e + t >> 1n, t) : g(e >> 1n, t), $ = (e, t, n, r) => {
|
|
227
|
+
let s = 1n, o = n;
|
|
228
|
+
const i = e.toString(2).slice(1);
|
|
194
229
|
for (const c of i)
|
|
195
|
-
[
|
|
196
|
-
return [
|
|
197
|
-
},
|
|
198
|
-
if (
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
230
|
+
[s, o] = [g(s * o, t), y(o * o + r * s * s, t)], c === "1" && ([s, o] = [y(n * s + o, t), y(r * s + n * o, t)]);
|
|
231
|
+
return [s, o];
|
|
232
|
+
}, D = (e, t, n, r) => {
|
|
233
|
+
if (e % 2n !== 1n)
|
|
234
|
+
throw Error("`n` must be odd");
|
|
235
|
+
let s = e + 1n, o = 0n;
|
|
236
|
+
for (; s % 2n === 0n; )
|
|
237
|
+
s >>= 1n, o += 1n;
|
|
238
|
+
const [i, c] = $(s, e, n, t);
|
|
239
|
+
let a = c;
|
|
204
240
|
if (i === 0n) return !0;
|
|
205
|
-
r =
|
|
206
|
-
for (let l = 0n; l <
|
|
207
|
-
if (
|
|
208
|
-
|
|
241
|
+
r = m(r, s, e);
|
|
242
|
+
for (let l = 0n; l < o; l++) {
|
|
243
|
+
if (a === 0n) return !0;
|
|
244
|
+
a = g(a * a - 2n * r, e), r = m(r, 2n, e);
|
|
209
245
|
}
|
|
210
246
|
return !1;
|
|
211
|
-
},
|
|
212
|
-
if (
|
|
213
|
-
if (
|
|
247
|
+
}, R = (e) => {
|
|
248
|
+
if (e <= 1n) return !1;
|
|
249
|
+
if (e % 2n === 0n) return e === 2n;
|
|
214
250
|
const t = [
|
|
215
251
|
2n,
|
|
216
252
|
3n,
|
|
@@ -239,89 +275,89 @@ const L = new TextEncoder(), X = (n, t) => [n].includes(t), g = (n, t) => {
|
|
|
239
275
|
97n,
|
|
240
276
|
101n
|
|
241
277
|
];
|
|
242
|
-
for (const
|
|
243
|
-
if (
|
|
244
|
-
return
|
|
245
|
-
if (!
|
|
278
|
+
for (const o of t)
|
|
279
|
+
if (e % o === 0n)
|
|
280
|
+
return e === o;
|
|
281
|
+
if (!F(e))
|
|
246
282
|
return !1;
|
|
247
|
-
const [
|
|
283
|
+
const [n, r] = V(e);
|
|
248
284
|
if (r === 0n) return !1;
|
|
249
|
-
const
|
|
250
|
-
return
|
|
251
|
-
},
|
|
285
|
+
const s = (1n - n) / 4n;
|
|
286
|
+
return D(e, n, 1n, s);
|
|
287
|
+
}, ht = (e, t) => {
|
|
252
288
|
if (t < 2n)
|
|
253
|
-
throw Error("
|
|
289
|
+
throw Error("NoPrimesFound");
|
|
254
290
|
for (let r = 0; r < 1e5; r++) {
|
|
255
|
-
const
|
|
256
|
-
if (
|
|
291
|
+
const s = P(e, t);
|
|
292
|
+
if (R(s)) return s;
|
|
257
293
|
}
|
|
258
|
-
throw Error("
|
|
259
|
-
},
|
|
260
|
-
if (
|
|
261
|
-
throw Error("
|
|
294
|
+
throw Error("NoPrimesFound");
|
|
295
|
+
}, dt = (e, t = !1) => {
|
|
296
|
+
if (e < 2)
|
|
297
|
+
throw Error("NoPrimesFound");
|
|
262
298
|
for (let r = 0; r < 1e5; r++) {
|
|
263
|
-
const
|
|
264
|
-
if (
|
|
299
|
+
const s = v(e, t);
|
|
300
|
+
if (R(s)) return s;
|
|
265
301
|
}
|
|
266
|
-
throw Error("
|
|
267
|
-
};
|
|
268
|
-
class
|
|
302
|
+
throw Error("NoPrimesFound");
|
|
303
|
+
}, x = "Rational";
|
|
304
|
+
class u {
|
|
269
305
|
#t;
|
|
270
|
-
#
|
|
271
|
-
static name =
|
|
306
|
+
#e;
|
|
307
|
+
static name = x;
|
|
272
308
|
/**
|
|
273
309
|
* fraction (rational) class
|
|
274
310
|
* @param numerator
|
|
275
311
|
* @param denominator
|
|
276
312
|
*/
|
|
277
|
-
constructor(t,
|
|
278
|
-
|
|
313
|
+
constructor(t, n) {
|
|
314
|
+
n === 0n ? (this.#e = 0n, this.#t = t === 0n ? 0n : t > 0n ? 1n : -1n) : n > 0n ? (this.#t = t, this.#e = n) : (this.#t = -t, this.#e = -n), this.#n();
|
|
279
315
|
}
|
|
280
316
|
/**
|
|
281
317
|
* generates fraction from `number` decimal using continued fraction
|
|
282
318
|
* @param value decimal
|
|
283
319
|
* @param denominatorDigits limit of digits of denominator
|
|
284
320
|
*/
|
|
285
|
-
static fromDecimal(t,
|
|
321
|
+
static fromDecimal(t, n = 5) {
|
|
286
322
|
if (Number.isNaN(t))
|
|
287
|
-
return new
|
|
323
|
+
return new u(0n, 0n);
|
|
288
324
|
if (Math.abs(t) === 1 / 0)
|
|
289
|
-
return new
|
|
325
|
+
return new u(t > 0 ? 1n : -1n, 0n);
|
|
290
326
|
const r = t < 0;
|
|
291
327
|
r && (t *= -1);
|
|
292
|
-
const
|
|
293
|
-
if (
|
|
294
|
-
return new
|
|
295
|
-
t = 1 /
|
|
296
|
-
let [i, c] = [1n,
|
|
297
|
-
for (; `${l}`.length <
|
|
298
|
-
const
|
|
299
|
-
if ([i, c] = [c,
|
|
300
|
-
return new
|
|
328
|
+
const s = BigInt(Math.floor(t)), o = t - Number(s);
|
|
329
|
+
if (o === 0)
|
|
330
|
+
return new u(r ? -s : s, 1n);
|
|
331
|
+
t = 1 / o;
|
|
332
|
+
let [i, c] = [1n, s], [a, l] = [0n, 1n];
|
|
333
|
+
for (; `${l}`.length < n + 1; ) {
|
|
334
|
+
const f = BigInt(Math.floor(t)), h = t - Number(f);
|
|
335
|
+
if ([i, c] = [c, f * c + i], [a, l] = [l, f * l + a], h === 0)
|
|
336
|
+
return new u(r ? -c : c, l);
|
|
301
337
|
t = 1 / h;
|
|
302
338
|
}
|
|
303
|
-
return new
|
|
339
|
+
return new u(r ? -i : i, a);
|
|
304
340
|
}
|
|
305
341
|
/**
|
|
306
342
|
* reduction
|
|
307
343
|
*/
|
|
308
|
-
#
|
|
309
|
-
const { gcd: t } = _(this.#t, this.#
|
|
310
|
-
t !== 0n && (this.#t /= t, this.#
|
|
344
|
+
#n() {
|
|
345
|
+
const { gcd: t } = _(this.#t, this.#e);
|
|
346
|
+
t !== 0n && (this.#t /= t, this.#e /= t);
|
|
311
347
|
}
|
|
312
348
|
/**
|
|
313
349
|
* returns a fraction multiplied by -1
|
|
314
350
|
* @returns
|
|
315
351
|
*/
|
|
316
352
|
minus() {
|
|
317
|
-
return new
|
|
353
|
+
return new u(-this.#t, this.#e);
|
|
318
354
|
}
|
|
319
355
|
/**
|
|
320
356
|
* returns inverse of this fraction
|
|
321
357
|
* @returns
|
|
322
358
|
*/
|
|
323
359
|
inverse() {
|
|
324
|
-
return new
|
|
360
|
+
return new u(this.#e, this.#t);
|
|
325
361
|
}
|
|
326
362
|
/**
|
|
327
363
|
* returns `this + right`
|
|
@@ -329,8 +365,8 @@ class a {
|
|
|
329
365
|
* @returns
|
|
330
366
|
*/
|
|
331
367
|
add(t) {
|
|
332
|
-
const
|
|
333
|
-
return new
|
|
368
|
+
const n = this.#e * t.#e, r = this.#t * t.#e + t.#t * this.#e;
|
|
369
|
+
return new u(r, n);
|
|
334
370
|
}
|
|
335
371
|
/**
|
|
336
372
|
* returns `this - right`
|
|
@@ -346,8 +382,8 @@ class a {
|
|
|
346
382
|
* @returns
|
|
347
383
|
*/
|
|
348
384
|
multiply(t) {
|
|
349
|
-
const
|
|
350
|
-
return new
|
|
385
|
+
const n = this.#e * t.#e, r = this.#t * t.#t;
|
|
386
|
+
return new u(r, n);
|
|
351
387
|
}
|
|
352
388
|
/**
|
|
353
389
|
* returns `this / right`
|
|
@@ -364,22 +400,22 @@ class a {
|
|
|
364
400
|
* @returns `(a+c)/(b+d)`
|
|
365
401
|
*/
|
|
366
402
|
mediant(t) {
|
|
367
|
-
const
|
|
368
|
-
return new
|
|
403
|
+
const n = this.#e + t.#e, r = this.#t + t.#t;
|
|
404
|
+
return new u(r, n);
|
|
369
405
|
}
|
|
370
406
|
/**
|
|
371
407
|
* returns `number` type decimal
|
|
372
408
|
* @returns decimal
|
|
373
409
|
*/
|
|
374
410
|
toDecimal() {
|
|
375
|
-
return Number(this.#t) / Number(this.#
|
|
411
|
+
return Number(this.#t) / Number(this.#e);
|
|
376
412
|
}
|
|
377
413
|
/**
|
|
378
414
|
* returns `'numerator/denominator'`
|
|
379
415
|
* @returns string form
|
|
380
416
|
*/
|
|
381
417
|
toString() {
|
|
382
|
-
return this.#t === 0n && this.#
|
|
418
|
+
return this.#t === 0n && this.#e === 0n ? "NaN" : this.#t === 0n ? "0" : this.#e === 0n ? this.#t < 0n ? "-Infinity" : "Infinity" : this.#e === 1n ? `${this.#t}` : `${this.#t}/${this.#e}`;
|
|
383
419
|
}
|
|
384
420
|
valueOf() {
|
|
385
421
|
return this.toDecimal();
|
|
@@ -387,7 +423,7 @@ class a {
|
|
|
387
423
|
toJSON() {
|
|
388
424
|
return {
|
|
389
425
|
type: "Rational",
|
|
390
|
-
value: ["0x" + this.#t.toString(16), "0x" + this.#
|
|
426
|
+
value: ["0x" + this.#t.toString(16), "0x" + this.#e.toString(16)]
|
|
391
427
|
};
|
|
392
428
|
}
|
|
393
429
|
/**
|
|
@@ -396,8 +432,8 @@ class a {
|
|
|
396
432
|
* @returns
|
|
397
433
|
*/
|
|
398
434
|
static fromData(t) {
|
|
399
|
-
const
|
|
400
|
-
return new
|
|
435
|
+
const n = BigInt(t.value[0]), r = BigInt(t.value[1]);
|
|
436
|
+
return new u(n, r);
|
|
401
437
|
}
|
|
402
438
|
/**
|
|
403
439
|
* pases string whose form is `'numerator/denominator'`
|
|
@@ -408,240 +444,214 @@ class a {
|
|
|
408
444
|
const r = /^\s*(\d+)\s*\/\s*(\d+)\s*$/.exec(t);
|
|
409
445
|
if (!r)
|
|
410
446
|
throw Error("cannot parse");
|
|
411
|
-
const
|
|
412
|
-
if (!
|
|
447
|
+
const s = r.at(1), o = r.at(2);
|
|
448
|
+
if (!s || !o)
|
|
413
449
|
throw Error("cannot parse");
|
|
414
|
-
return new
|
|
450
|
+
return new u(BigInt(s), BigInt(o));
|
|
415
451
|
}
|
|
416
452
|
}
|
|
417
|
-
Object.defineProperty(
|
|
418
|
-
value:
|
|
453
|
+
Object.defineProperty(u.prototype, Symbol.toStringTag, {
|
|
454
|
+
value: x
|
|
419
455
|
});
|
|
420
|
-
const
|
|
421
|
-
const t = Array.from(
|
|
456
|
+
const k = (e) => {
|
|
457
|
+
const t = Array.from(e, (n) => String.fromCharCode(n));
|
|
422
458
|
return btoa(t.join(""));
|
|
423
|
-
},
|
|
424
|
-
const t = atob(
|
|
425
|
-
return Uint8Array.from(t, (
|
|
426
|
-
},
|
|
427
|
-
const t =
|
|
428
|
-
t > 0 && (
|
|
429
|
-
const
|
|
430
|
-
return
|
|
431
|
-
},
|
|
432
|
-
let t = Array.from(
|
|
433
|
-
const
|
|
434
|
-
|
|
459
|
+
}, q = (e) => {
|
|
460
|
+
const t = atob(e);
|
|
461
|
+
return Uint8Array.from(t, (n) => n.charCodeAt(0));
|
|
462
|
+
}, gt = (e) => k(e).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/, ""), mt = (e) => {
|
|
463
|
+
const t = e.length & 3;
|
|
464
|
+
t > 0 && (e = e + "=".repeat(4 - t));
|
|
465
|
+
const n = e.replaceAll("-", "+").replaceAll("_", "/");
|
|
466
|
+
return q(n);
|
|
467
|
+
}, pt = (e) => {
|
|
468
|
+
let t = Array.from(e, (o) => o.toString(16).padStart(2, "0")).join("");
|
|
469
|
+
const n = t.length % 6;
|
|
470
|
+
n && (t = "0".repeat(6 - n) + t);
|
|
435
471
|
const r = t.matchAll(/.{6}/g);
|
|
436
472
|
return Array.from(
|
|
437
473
|
r,
|
|
438
|
-
(
|
|
474
|
+
(o) => Number.parseInt(o[0], 16).toString(8).padStart(8, "0")
|
|
439
475
|
).join("").replace(/^0+/, "");
|
|
440
|
-
},
|
|
441
|
-
const t =
|
|
442
|
-
t && (
|
|
443
|
-
const
|
|
444
|
-
const i =
|
|
476
|
+
}, yt = (e) => {
|
|
477
|
+
const t = e.length & 7;
|
|
478
|
+
t && (e = "0".repeat(8 - t) + e);
|
|
479
|
+
const n = e.matchAll(/.{8}/g), s = Array.from(n, (o) => {
|
|
480
|
+
const i = o[0];
|
|
445
481
|
return Number.parseInt(i, 8).toString(16).padStart(6, "0");
|
|
446
482
|
}).join("").matchAll(/.{2}/g);
|
|
447
|
-
return Uint8Array.from(
|
|
448
|
-
}, K = (
|
|
449
|
-
const t =
|
|
450
|
-
t && (
|
|
451
|
-
const
|
|
452
|
-
return r ?
|
|
453
|
-
},
|
|
454
|
-
const t = K(
|
|
455
|
-
|
|
456
|
-
const
|
|
457
|
-
for (let
|
|
458
|
-
const
|
|
459
|
-
|
|
460
|
-
}
|
|
461
|
-
const r = Number(
|
|
462
|
-
return
|
|
463
|
-
},
|
|
464
|
-
const t =
|
|
465
|
-
let
|
|
483
|
+
return Uint8Array.from(s, (o) => Number.parseInt(o[0], 16));
|
|
484
|
+
}, K = (e) => {
|
|
485
|
+
const t = e < 0n;
|
|
486
|
+
t && (e *= -1n);
|
|
487
|
+
const n = e.toString(2).length, r = e === 1n << BigInt(n - 1) && !(n % 7) && t, s = Math.floor(n / 7) + 1;
|
|
488
|
+
return r ? s - 1 : s;
|
|
489
|
+
}, It = (e) => {
|
|
490
|
+
const t = K(e);
|
|
491
|
+
e = BigInt.asUintN(t * 7, e);
|
|
492
|
+
const n = new Uint8Array(t);
|
|
493
|
+
for (let s = 0; s < t - 1; ++s) {
|
|
494
|
+
const o = Number(e & 127n) | 128;
|
|
495
|
+
n[s] = o, e >>= 7n;
|
|
496
|
+
}
|
|
497
|
+
const r = Number(e & 127n);
|
|
498
|
+
return n[t - 1] = r, e >>= 7n, n;
|
|
499
|
+
}, wt = (e) => {
|
|
500
|
+
const t = e.length;
|
|
501
|
+
let n = 0n;
|
|
466
502
|
for (let r = 0; r < t; ++r) {
|
|
467
|
-
const
|
|
468
|
-
|
|
469
|
-
}
|
|
470
|
-
return BigInt.asIntN(7 * t, e);
|
|
471
|
-
};
|
|
472
|
-
class U extends Error {
|
|
473
|
-
constructor(t, e, r) {
|
|
474
|
-
super(e, { cause: r }), this.errName = t;
|
|
475
|
-
}
|
|
476
|
-
static name = "NamedError";
|
|
477
|
-
toJSON() {
|
|
478
|
-
const t = (() => {
|
|
479
|
-
const s = this.cause;
|
|
480
|
-
return typeof s == "string" || typeof s == "number" || typeof s == "boolean" ? s : typeof s == "bigint" ? s.toString() : typeof s == "object" && s !== null ? s instanceof Set || s instanceof Map ? Object.fromEntries(s) : s : void 0;
|
|
481
|
-
})(), { errName: e, message: r, stack: o } = this;
|
|
482
|
-
return {
|
|
483
|
-
errName: e,
|
|
484
|
-
message: r,
|
|
485
|
-
stack: o,
|
|
486
|
-
cause: t
|
|
487
|
-
};
|
|
503
|
+
const s = BigInt(e[r] & 127);
|
|
504
|
+
n += s << BigInt(7 * r);
|
|
488
505
|
}
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
});
|
|
493
|
-
const E = (n) => {
|
|
494
|
-
if (n === 0) return 32;
|
|
506
|
+
return BigInt.asIntN(7 * t, n);
|
|
507
|
+
}, B = (e) => {
|
|
508
|
+
if (e === 0) return 32;
|
|
495
509
|
let t = 0;
|
|
496
|
-
for (;
|
|
497
|
-
++t,
|
|
510
|
+
for (; e > 0 && !(e & 1); )
|
|
511
|
+
++t, e >>>= 1;
|
|
498
512
|
return t;
|
|
499
|
-
}, S = (
|
|
500
|
-
if (
|
|
513
|
+
}, M = "FloatRng", S = (e) => {
|
|
514
|
+
if (e === 0n) return 64n;
|
|
501
515
|
let t = 0n;
|
|
502
|
-
for (;
|
|
503
|
-
++t,
|
|
516
|
+
for (; e > 0n && !(e & 1n); )
|
|
517
|
+
++t, e >>= 1n;
|
|
504
518
|
return BigInt.asUintN(64, t);
|
|
505
519
|
};
|
|
506
|
-
class
|
|
520
|
+
class G {
|
|
507
521
|
#t;
|
|
508
|
-
static name =
|
|
522
|
+
static name = M;
|
|
509
523
|
constructor(t) {
|
|
510
524
|
this.#t = t;
|
|
511
525
|
}
|
|
512
|
-
#
|
|
526
|
+
#e() {
|
|
513
527
|
const r = (() => {
|
|
514
528
|
switch (this.#t.bits) {
|
|
515
529
|
case 32:
|
|
516
530
|
return this.#t.getU32Rand() >>> 0;
|
|
517
531
|
case 64: {
|
|
518
|
-
const
|
|
519
|
-
return Number(
|
|
532
|
+
const a = this.#t.getU64Rand() & 0xffffffffn;
|
|
533
|
+
return Number(a);
|
|
520
534
|
}
|
|
521
535
|
}
|
|
522
|
-
})(),
|
|
523
|
-
let
|
|
524
|
-
if (
|
|
525
|
-
|
|
526
|
-
const
|
|
527
|
-
let
|
|
536
|
+
})(), s = r & 255;
|
|
537
|
+
let o = 126;
|
|
538
|
+
if (s === 0) {
|
|
539
|
+
o -= 8;
|
|
540
|
+
const a = 1e5;
|
|
541
|
+
let l = 0;
|
|
528
542
|
t: for (; ; ) {
|
|
529
|
-
if (
|
|
543
|
+
if (l > a)
|
|
530
544
|
throw Error("loop exceeded limit");
|
|
531
|
-
const
|
|
545
|
+
const f = (() => {
|
|
532
546
|
switch (this.#t.bits) {
|
|
533
547
|
case 32:
|
|
534
548
|
return this.#t.getU32Rand() >>> 0;
|
|
535
549
|
case 64: {
|
|
536
|
-
const
|
|
537
|
-
return Number(
|
|
550
|
+
const h = BigInt.asUintN(32, this.#t.getU64Rand());
|
|
551
|
+
return Number(h);
|
|
538
552
|
}
|
|
539
553
|
}
|
|
540
554
|
})();
|
|
541
|
-
if (
|
|
542
|
-
if (
|
|
543
|
-
|
|
555
|
+
if (f === 0) {
|
|
556
|
+
if (o -= 32, o < 0) {
|
|
557
|
+
o = 0;
|
|
544
558
|
break t;
|
|
545
559
|
}
|
|
546
560
|
} else {
|
|
547
|
-
|
|
561
|
+
o -= B(f);
|
|
548
562
|
break t;
|
|
549
563
|
}
|
|
550
|
-
++
|
|
564
|
+
++l;
|
|
551
565
|
}
|
|
552
566
|
} else
|
|
553
|
-
|
|
567
|
+
o -= B(s);
|
|
554
568
|
const i = r >>> 8 & 8388607;
|
|
555
|
-
i === 0 && r >>> 31 && ++
|
|
556
|
-
const
|
|
557
|
-
|
|
558
|
-
]);
|
|
559
|
-
return new Float32Array(c, f, l)[0];
|
|
569
|
+
i === 0 && r >>> 31 && ++o;
|
|
570
|
+
const c = Uint32Array.from([o << 23 | i]);
|
|
571
|
+
return new Float32Array(c.buffer)[0];
|
|
560
572
|
}
|
|
561
573
|
/**
|
|
562
574
|
* returns a random single-precision floating-point number (float32) in the range of [0.0, 1.0)
|
|
563
575
|
* @returns
|
|
564
576
|
*/
|
|
565
577
|
getF32Rand() {
|
|
566
|
-
for (let
|
|
567
|
-
const r = this.#
|
|
578
|
+
for (let n = 0; n < 1e5; ++n) {
|
|
579
|
+
const r = this.#e();
|
|
568
580
|
if (r < 1)
|
|
569
581
|
return r;
|
|
570
582
|
}
|
|
571
583
|
throw Error("exceeded loop limit");
|
|
572
584
|
}
|
|
573
|
-
#
|
|
574
|
-
const t = 0n,
|
|
585
|
+
#n() {
|
|
586
|
+
const t = 0n, n = 1023n, r = (() => {
|
|
575
587
|
switch (this.#t.bits) {
|
|
576
588
|
case 32: {
|
|
577
|
-
const
|
|
578
|
-
return
|
|
589
|
+
const a = BigInt(this.#t.getU32Rand() >>> 0), l = BigInt(this.#t.getU32Rand() >>> 0);
|
|
590
|
+
return a << 32n | l;
|
|
579
591
|
}
|
|
580
592
|
case 64:
|
|
581
593
|
return BigInt.asUintN(64, this.#t.getU64Rand());
|
|
582
594
|
}
|
|
583
|
-
})(),
|
|
584
|
-
let
|
|
585
|
-
if (
|
|
586
|
-
|
|
587
|
-
const
|
|
588
|
-
let
|
|
595
|
+
})(), s = r & 0x7ffn;
|
|
596
|
+
let o = n - 1n;
|
|
597
|
+
if (s === 0n) {
|
|
598
|
+
o -= 11n;
|
|
599
|
+
const a = 1e5;
|
|
600
|
+
let l = 0;
|
|
589
601
|
t: for (; ; ) {
|
|
590
|
-
if (
|
|
602
|
+
if (l > a)
|
|
591
603
|
throw Error("loop exceeded limit");
|
|
592
|
-
const
|
|
604
|
+
const f = (() => {
|
|
593
605
|
switch (this.#t.bits) {
|
|
594
606
|
case 32: {
|
|
595
|
-
const
|
|
596
|
-
return
|
|
607
|
+
const h = BigInt(this.#t.getU32Rand() >>> 0), p = BigInt(this.#t.getU32Rand() >>> 0);
|
|
608
|
+
return h << 32n | p;
|
|
597
609
|
}
|
|
598
610
|
case 64:
|
|
599
611
|
return BigInt.asUintN(64, this.#t.getU64Rand());
|
|
600
612
|
}
|
|
601
613
|
})();
|
|
602
|
-
if (
|
|
603
|
-
if (
|
|
604
|
-
|
|
614
|
+
if (f === 0n) {
|
|
615
|
+
if (o -= 64n, o < t) {
|
|
616
|
+
o = t;
|
|
605
617
|
break t;
|
|
606
618
|
}
|
|
607
619
|
} else {
|
|
608
|
-
|
|
620
|
+
o -= S(f);
|
|
609
621
|
break t;
|
|
610
622
|
}
|
|
611
|
-
++
|
|
623
|
+
++l;
|
|
612
624
|
}
|
|
613
625
|
} else
|
|
614
|
-
|
|
626
|
+
o -= S(s);
|
|
615
627
|
const i = BigInt.asUintN(52, r >> 11n);
|
|
616
|
-
i === 0n && r >> 63n && ++
|
|
617
|
-
const
|
|
618
|
-
|
|
619
|
-
]);
|
|
620
|
-
return new Float64Array(c, f, l)[0];
|
|
628
|
+
i === 0n && r >> 63n && ++o;
|
|
629
|
+
const c = BigUint64Array.from([o << 52n | i]);
|
|
630
|
+
return new Float64Array(c.buffer)[0];
|
|
621
631
|
}
|
|
622
632
|
/**
|
|
623
633
|
* returns a random double-precision floating-point number (float64) in the range of [0.0, 1.0)
|
|
624
634
|
* @returns
|
|
625
635
|
*/
|
|
626
636
|
getF64Rand() {
|
|
627
|
-
for (let
|
|
628
|
-
const r = this.#
|
|
637
|
+
for (let n = 0; n < 1e5; ++n) {
|
|
638
|
+
const r = this.#n();
|
|
629
639
|
if (r < 1)
|
|
630
640
|
return r;
|
|
631
641
|
}
|
|
632
642
|
throw Error("exceeded loop limit");
|
|
633
643
|
}
|
|
634
644
|
}
|
|
635
|
-
Object.defineProperty(
|
|
636
|
-
value:
|
|
645
|
+
Object.defineProperty(G.prototype, Symbol.toStringTag, {
|
|
646
|
+
value: M
|
|
637
647
|
});
|
|
638
|
-
const
|
|
639
|
-
class
|
|
648
|
+
const W = [0x853c49e6748fea9bn, 0xda3e39cb94b95bdbn], z = 0x5851f42d4c957f2dn, A = "PCGMinimal";
|
|
649
|
+
class X {
|
|
640
650
|
/**
|
|
641
651
|
* length = 2, `[state, increment]`
|
|
642
652
|
*/
|
|
643
653
|
#t;
|
|
644
|
-
static name =
|
|
654
|
+
static name = A;
|
|
645
655
|
bits = 32;
|
|
646
656
|
/**
|
|
647
657
|
* @param seeds
|
|
@@ -657,23 +667,23 @@ class R {
|
|
|
657
667
|
* const betterRng = new PCGMinimal(seed);
|
|
658
668
|
*/
|
|
659
669
|
constructor(t) {
|
|
660
|
-
t && t.length >= 2 ? (this.#t = new BigUint64Array(2), this.#t[1] = t[1] << 1n | 1n, this.#
|
|
670
|
+
t && t.length >= 2 ? (this.#t = new BigUint64Array(2), this.#t[1] = t[1] << 1n | 1n, this.#e(), this.#t[0] += t[0], this.#e()) : this.#t = BigUint64Array.from(W);
|
|
661
671
|
}
|
|
662
672
|
/** step inner state */
|
|
663
|
-
#
|
|
664
|
-
this.#t[0] = this.#t[0] *
|
|
673
|
+
#e() {
|
|
674
|
+
this.#t[0] = this.#t[0] * z + this.#t[1];
|
|
665
675
|
}
|
|
666
676
|
/** 32bit 乱数を返す (内部状態は変わらない) */
|
|
667
|
-
get #
|
|
668
|
-
const t = this.#t[0],
|
|
669
|
-
return
|
|
677
|
+
get #n() {
|
|
678
|
+
const t = this.#t[0], n = Number(t >> 59n), r = Number(BigInt.asUintN(32, (t ^ t >> 18n) >> 27n));
|
|
679
|
+
return C(r, n);
|
|
670
680
|
}
|
|
671
681
|
/**
|
|
672
682
|
*
|
|
673
683
|
* @returns a random 32-bit unsigned integer
|
|
674
684
|
*/
|
|
675
685
|
getU32Rand() {
|
|
676
|
-
return this.#
|
|
686
|
+
return this.#e(), this.#n;
|
|
677
687
|
}
|
|
678
688
|
/**
|
|
679
689
|
* @returns a random 32-bit unsigned integer less than `bound`
|
|
@@ -682,8 +692,8 @@ class R {
|
|
|
682
692
|
if (t > 4294967296) throw Error("`bound` exceeded limit (2^32)");
|
|
683
693
|
if (t <= 0)
|
|
684
694
|
throw Error("'bound' must be positive");
|
|
685
|
-
const r = 4294967296 % t,
|
|
686
|
-
for (let
|
|
695
|
+
const r = 4294967296 % t, s = 1e5;
|
|
696
|
+
for (let o = 0; o < s; ++o) {
|
|
687
697
|
const i = this.getU32Rand();
|
|
688
698
|
if (i >= r)
|
|
689
699
|
return i % t;
|
|
@@ -698,23 +708,23 @@ class R {
|
|
|
698
708
|
* the iterator that generates random 32-bit unsigned integers `step` times \
|
|
699
709
|
* if `bound` is given, random integers are less than `bound`
|
|
700
710
|
*/
|
|
701
|
-
*genU32Rands(t,
|
|
711
|
+
*genU32Rands(t, n) {
|
|
702
712
|
if (t <= 0)
|
|
703
713
|
throw Error("'step' must be positive");
|
|
704
714
|
for (let r = 0; r < t; r++)
|
|
705
|
-
yield typeof
|
|
715
|
+
yield typeof n == "number" ? this.getBoundedU32Rand(n) : this.getU32Rand();
|
|
706
716
|
}
|
|
707
717
|
}
|
|
708
|
-
Object.defineProperty(
|
|
709
|
-
value:
|
|
718
|
+
Object.defineProperty(X.prototype, Symbol.toStringTag, {
|
|
719
|
+
value: A
|
|
710
720
|
});
|
|
711
|
-
const
|
|
721
|
+
const H = [
|
|
712
722
|
0xbe562cb412e2260en,
|
|
713
723
|
0x2e4284137d641affn,
|
|
714
724
|
0x4e19b36ee933e27en,
|
|
715
725
|
0x7581cf8c4f4d4f7dn
|
|
716
726
|
];
|
|
717
|
-
class
|
|
727
|
+
class U {
|
|
718
728
|
bits = 64;
|
|
719
729
|
#t;
|
|
720
730
|
static name = "XoshiroMinimal";
|
|
@@ -732,9 +742,9 @@ class x {
|
|
|
732
742
|
* const betterRng = new XoshiroMinimal(seed);
|
|
733
743
|
*/
|
|
734
744
|
constructor(t) {
|
|
735
|
-
t && t.length >= 4 ? (this.#t = new BigUint64Array(4), this.#t[0] = t[0], this.#t[1] = t[1], this.#
|
|
745
|
+
t && t.length >= 4 ? (this.#t = new BigUint64Array(4), this.#t[0] = t[0], this.#t[1] = t[1], this.#e(), this.#t[2] += t[2], this.#t[3] += t[3]) : this.#t = BigUint64Array.from(H);
|
|
736
746
|
}
|
|
737
|
-
#
|
|
747
|
+
#e() {
|
|
738
748
|
const t = this.#t[1] << 17n;
|
|
739
749
|
this.#t[2] ^= this.#t[0], this.#t[3] ^= this.#t[1], this.#t[1] ^= this.#t[2], this.#t[0] ^= this.#t[3], this.#t[2] ^= t, this.#t[3] = b(this.#t[3], 45n);
|
|
740
750
|
}
|
|
@@ -744,20 +754,20 @@ class x {
|
|
|
744
754
|
}
|
|
745
755
|
getU64Rand() {
|
|
746
756
|
const t = this.value;
|
|
747
|
-
return this.#
|
|
757
|
+
return this.#e(), t;
|
|
748
758
|
}
|
|
749
759
|
getU32Rand() {
|
|
750
760
|
const t = BigInt.asUintN(32, this.getU64Rand());
|
|
751
761
|
return Number(t);
|
|
752
762
|
}
|
|
753
763
|
getBoundedU64Rand(t) {
|
|
754
|
-
const
|
|
755
|
-
if (t >
|
|
764
|
+
const n = 1n << 64n;
|
|
765
|
+
if (t > n)
|
|
756
766
|
throw Error("'bound' exceeded limit");
|
|
757
767
|
if (t <= 0n)
|
|
758
768
|
throw Error("'bound' must be positive");
|
|
759
|
-
const r =
|
|
760
|
-
for (let
|
|
769
|
+
const r = n % t, s = 1e5;
|
|
770
|
+
for (let o = 0; o < s; ++o) {
|
|
761
771
|
const i = this.getU64Rand();
|
|
762
772
|
if (i >= r)
|
|
763
773
|
return i % t;
|
|
@@ -772,61 +782,99 @@ class x {
|
|
|
772
782
|
const r = this.getBoundedU64Rand(BigInt(t));
|
|
773
783
|
return Number(r);
|
|
774
784
|
}
|
|
775
|
-
*genU64Rands(t,
|
|
785
|
+
*genU64Rands(t, n) {
|
|
776
786
|
if (t <= 0)
|
|
777
787
|
throw Error("'step' must be positive");
|
|
778
788
|
for (let r = 0; r < t; ++r)
|
|
779
|
-
yield
|
|
789
|
+
yield n === void 0 ? this.getU64Rand() : this.getBoundedU64Rand(n);
|
|
780
790
|
}
|
|
781
|
-
*genU32Rands(t,
|
|
791
|
+
*genU32Rands(t, n) {
|
|
782
792
|
if (t <= 0)
|
|
783
793
|
throw Error("'step' must be positive");
|
|
784
794
|
for (let r = 0; r < t; ++r)
|
|
785
|
-
yield
|
|
795
|
+
yield n === void 0 ? this.getU32Rand() : this.getBoundedU32Rand(n);
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
Object.defineProperty(U.prototype, Symbol.toStringTag, {
|
|
799
|
+
value: U.name
|
|
800
|
+
});
|
|
801
|
+
const L = "WorkerStream";
|
|
802
|
+
class J extends ReadableStream {
|
|
803
|
+
close;
|
|
804
|
+
#t;
|
|
805
|
+
static name = L;
|
|
806
|
+
constructor(t, n) {
|
|
807
|
+
let r, s, o;
|
|
808
|
+
super(
|
|
809
|
+
{
|
|
810
|
+
start: (i) => {
|
|
811
|
+
r = (c) => {
|
|
812
|
+
i.enqueue(c.data);
|
|
813
|
+
}, s = (c) => {
|
|
814
|
+
t.removeEventListener("message", r), t.removeEventListener("error", s);
|
|
815
|
+
const a = new w("WorkerStreamError", c.message, {
|
|
816
|
+
cause: c.error
|
|
817
|
+
});
|
|
818
|
+
i.error(a);
|
|
819
|
+
}, o = () => {
|
|
820
|
+
t.removeEventListener("message", r), t.removeEventListener("error", s), i.close();
|
|
821
|
+
}, t.addEventListener("message", r), t.addEventListener("error", s);
|
|
822
|
+
},
|
|
823
|
+
cancel: (i) => {
|
|
824
|
+
console.log("Canceled reason:", i), t.removeEventListener("message", r), t.removeEventListener("error", s);
|
|
825
|
+
}
|
|
826
|
+
},
|
|
827
|
+
n
|
|
828
|
+
), this.close = o, this.#t = t;
|
|
829
|
+
}
|
|
830
|
+
postMessage(t, n) {
|
|
831
|
+
this.#t.postMessage(t, n);
|
|
786
832
|
}
|
|
787
833
|
}
|
|
788
|
-
Object.defineProperty(
|
|
789
|
-
value:
|
|
834
|
+
Object.defineProperty(J.prototype, Symbol.toStringTag, {
|
|
835
|
+
value: L
|
|
790
836
|
});
|
|
791
837
|
export {
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
838
|
+
G as FloatRng,
|
|
839
|
+
w as NamedError,
|
|
840
|
+
X as PCGMinimal,
|
|
841
|
+
u as Rational,
|
|
842
|
+
J as WorkerStream,
|
|
843
|
+
U as XoshiroMinimal,
|
|
844
|
+
R as bailliePSW,
|
|
845
|
+
ct as compress,
|
|
846
|
+
wt as decodeLEB128,
|
|
847
|
+
it as decodeRFC3986URIComponent,
|
|
848
|
+
at as decompress,
|
|
849
|
+
It as encodeLEB128,
|
|
850
|
+
ot as encodeRFC3986URIComponent,
|
|
804
851
|
_ as exEuclidean,
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
852
|
+
ft as factorial,
|
|
853
|
+
q as fromBase64,
|
|
854
|
+
mt as fromBase64Url,
|
|
855
|
+
yt as fromOct,
|
|
856
|
+
rt as getHash,
|
|
857
|
+
v as getRandBIByBitLength,
|
|
858
|
+
P as getRandBIByRange,
|
|
859
|
+
dt as getRandPrimeByBitLength,
|
|
860
|
+
ht as getRandPrimeByRange,
|
|
861
|
+
ut as getRndInt,
|
|
862
|
+
tt as getStringTag,
|
|
863
|
+
d as isDeepStrictEqual,
|
|
864
|
+
st as isNode,
|
|
818
865
|
O as isSquare,
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
P as rot32,
|
|
866
|
+
E as jacobiSymbol,
|
|
867
|
+
et as lazify,
|
|
868
|
+
m as modPow,
|
|
869
|
+
nt as parseCSV,
|
|
870
|
+
g as residue,
|
|
871
|
+
C as rot32,
|
|
826
872
|
b as rot64,
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
873
|
+
Y as sameValueZero,
|
|
874
|
+
lt as setTimeoutPromise,
|
|
875
|
+
Q as sleep,
|
|
876
|
+
k as toBase64,
|
|
877
|
+
gt as toBase64Url,
|
|
878
|
+
pt as toOct,
|
|
879
|
+
Z as withResolvers
|
|
832
880
|
};
|