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