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