@tktb-tess/util-fns 0.12.0 → 0.12.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/dist/assets/bpsw_worker-nJV3KnVo.js +1 -0
- package/dist/async_worker.d.ts +33 -0
- package/dist/baillie_psw.d.ts +2 -1
- package/dist/bundle.js +260 -283
- package/dist/bundle.min.js +2 -2
- package/dist/fraction.d.ts +11 -11
- package/dist/leb128.d.ts +1 -1
- package/dist/main.d.ts +1 -1
- package/dist/named_error.d.ts +2 -2
- package/dist/pcg_minimal.d.ts +2 -2
- package/dist/types.d.ts +0 -17
- package/dist/xoshiro_minimal.d.ts +4 -4
- package/package.json +3 -3
- package/dist/assets/bpsw_worker-D0gmU_qc.js +0 -1
- package/dist/worker_stream.d.ts +0 -7
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(){let e=(e,t)=>{t<0n&&(t*=-1n);let n=e%t;return n<0n?n+t:n},t=(t,n,r)=>{if(r<1n)throw RangeError("`mod` must be positive");if(n<0n)throw RangeError("`power` must not be negative");if(t=e(t,r),r===1n)return 0n;if(t%r===1n||t%r===0n)return t;if(t===r-1n)return n&1n?r-1n:1n;let i=1n;for(;n>0n;)n&1n&&(i=i*t%r),t=t*t%r,n>>=1n;return i},n=(e,t)=>{if(t<1n||t%2n==0n)throw RangeError("`n` is out of range");for(;e<0n;)e+=t;e%=t;let n=1n;for(;e!==0n;){for(;e%2n==0n;){e/=2n;let r=t%8n;(r===3n||r===5n)&&(n*=-1n)}[e,t]=[t,e],e%4n==3n&&t%4n==3n&&(n*=-1n),e%=t}return t===1n?n:0n},r=e=>{if(e<0n)return!1;if(e===0n)return!0;let t=1n,n=e;for(;t+1n<n;){let r=(t+n)/2n;r*r<e?t=r:n=r}return e===t**2n||e===(t+1n)**2n},i=()=>typeof window>`u`&&typeof self<`u`&&`importScripts`in self,a=(e,t)=>{if(!i())throw Error(`this function must be used in Worker`);let n={success:!0,value:e,id:t};self.postMessage(n)},o=(e,t)=>{if(!i())throw Error(`this function must be used in Worker`);let n={success:!1,error:e,id:t};self.postMessage(n)},s=e=>{if(e<=1n)return!1;if(e%2n==0n)return e===2n;let n=e-1n,r=0n;for(;n%2n==0n;)n>>=1n,r+=1n;let[i,a]=[n,r],o=t(2n,i,e);if(o===1n)return!0;for(let t=0n;t<a;t++){if(o===e-1n)return!0;o=o*o%e}return!1},c=e=>{let t=5n,i=n(t,e);for(;i>0n;){if(t=t>0n?t+2n:t-2n,t*=-1n,t===-15n&&r(e))return[0n,0n];i=n(t,e)}return[t,i]},l=(t,n)=>(t&1n)==1n?e(t+n>>1n,n):e(t>>1n,n),u=(t,n,r,i)=>{let a=1n,o=r,s=t.toString(2).slice(1);for(let t of s)[a,o]=[e(a*o,n),l(o*o+i*a*a,n)],t===`1`&&([a,o]=[l(r*a+o,n),l(i*a+r*o,n)]);return[a,o]},d=(n,r,i,a)=>{if(n%2n!=1n)throw RangeError("`n` must be odd");let o=n+1n,s=0n;for(;o%2n==0n;)o>>=1n,s+=1n;let[c,l]=u(o,n,i,r),d=l;if(c===0n)return!0;a=t(a,o,n);for(let r=0n;r<s;r++){if(d===0n)return!0;d=e(d*d-2n*a,n),a=t(a,2n,n)}return!1},f=[2n,3n,5n,7n,11n,13n,17n,19n,23n,29n,31n,37n,41n,43n,47n,53n,59n,61n,67n,71n,73n,79n,83n,89n,97n,101n,103n,107n,109n,113n,127n,131n,137n,139n,149n,151n,157n,163n,167n,173n,179n,181n,191n,193n,197n,199n,211n,223n,227n,229n,233n,239n,241n,251n,257n,263n,269n,271n,277n,281n,283n,293n,307n,311n,313n,317n,331n,337n,347n,349n,353n,359n,367n,373n,379n,383n,389n,397n,401n,409n,419n,421n,431n,433n,439n,443n,449n,457n,461n,463n,467n,479n,487n,491n,499n],p=e=>{if(e<=1n)return!1;if(e%2n==0n)return e===2n;for(let t of f)if(e%t===0n)return e===t;if(!s(e))return!1;let[t,n]=c(e);return n===0n?!1:d(e,t,1n,(1n-t)/4n)};globalThis.onmessage=e=>{let{value:t,id:n}=e.data;try{a(p(t),n)}catch(e){o(e,n)}}})();
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
declare const __ID_BRAND__: unique symbol;
|
|
2
|
+
type ID = ReturnType<typeof crypto.randomUUID> & {
|
|
3
|
+
readonly [__ID_BRAND__]: unknown;
|
|
4
|
+
};
|
|
5
|
+
export interface WorkerMessage<T> {
|
|
6
|
+
readonly value: T;
|
|
7
|
+
readonly id: ID;
|
|
8
|
+
}
|
|
9
|
+
interface WorkerResultBase {
|
|
10
|
+
readonly id: ID;
|
|
11
|
+
}
|
|
12
|
+
interface WorkerSucceededResult<T> extends WorkerResultBase {
|
|
13
|
+
readonly success: true;
|
|
14
|
+
readonly value: T;
|
|
15
|
+
}
|
|
16
|
+
interface WorkerFailedResult extends WorkerResultBase {
|
|
17
|
+
readonly success: false;
|
|
18
|
+
readonly error: unknown;
|
|
19
|
+
}
|
|
20
|
+
export type WorkerResult<T> = WorkerSucceededResult<T> | WorkerFailedResult;
|
|
21
|
+
export declare class AsyncWorker<TPost = unknown, TRecv = unknown> {
|
|
22
|
+
#private;
|
|
23
|
+
constructor(w: Worker);
|
|
24
|
+
/**
|
|
25
|
+
* sends a message to the worker, and returns promise resolved by message from worker
|
|
26
|
+
* @param message
|
|
27
|
+
* @param options
|
|
28
|
+
*/
|
|
29
|
+
readonly postMessage: (message: TPost, options?: StructuredSerializeOptions) => Promise<TRecv>;
|
|
30
|
+
}
|
|
31
|
+
export declare const postSuccess: <TRecv>(value: TRecv, id: ID) => void;
|
|
32
|
+
export declare const postFailed: (error: unknown, id: ID) => void;
|
|
33
|
+
export {};
|
package/dist/baillie_psw.d.ts
CHANGED
|
@@ -19,7 +19,8 @@ export declare const getRandPrimeByRange: (min: bigint, max: bigint) => bigint;
|
|
|
19
19
|
*/
|
|
20
20
|
export declare const getRandPrimeByBitLength: (bitLength: number, fixed?: boolean) => bigint;
|
|
21
21
|
/**
|
|
22
|
-
* worker async version of `bailliePSW()`
|
|
22
|
+
* worker async version of `bailliePSW()` \
|
|
23
|
+
* only available in esm context
|
|
23
24
|
* @param n
|
|
24
25
|
*/
|
|
25
26
|
export declare const bailliePSWAsync: (n: bigint) => Promise<boolean>;
|
package/dist/bundle.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
//#region lib/u8arr_ext.ts
|
|
2
|
+
var e = (e) => {
|
|
2
3
|
let t = Array.from(e, (e) => String.fromCharCode(e));
|
|
3
4
|
return btoa(t.join(""));
|
|
4
|
-
},
|
|
5
|
+
}, t = (e) => {
|
|
5
6
|
let t = atob(e);
|
|
6
7
|
return Uint8Array.from(t, (e) => e.charCodeAt(0));
|
|
7
|
-
},
|
|
8
|
-
let
|
|
9
|
-
return
|
|
10
|
-
},
|
|
8
|
+
}, n = (t) => e(t).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/, ""), r = (e) => {
|
|
9
|
+
let n = 4 - (e.length & 3) & 3;
|
|
10
|
+
return t(e.concat("=".repeat(n)).replaceAll("-", "+").replaceAll("_", "/"));
|
|
11
|
+
}, i = (e) => {
|
|
11
12
|
let t = Array.from(e, (e) => e.toString(16).padStart(2, "0")).join(""), n = (6 - t.length % 6) % 6, r = "0".repeat(n).concat(t).matchAll(/.{6}/g);
|
|
12
13
|
return Array.from(r, (e) => Number.parseInt(e[0], 16).toString(8).padStart(8, "0")).join("").replace(/^0+/, "");
|
|
13
|
-
},
|
|
14
|
+
}, a = (e) => {
|
|
14
15
|
let t = 8 - (e.length & 7) & 7, n = "0".repeat(t).concat(e).matchAll(/.{8}/g), r = Array.from(n, (e) => Number.parseInt(e[0], 8).toString(16).padStart(6, "0")).join("").matchAll(/.{2}/g);
|
|
15
16
|
return Uint8Array.from(r, (e) => Number.parseInt(e[0], 16));
|
|
16
|
-
},
|
|
17
|
+
}, o = (e, t) => [e].includes(t), s = (e, t) => {
|
|
17
18
|
if (typeof e != typeof t) return !1;
|
|
18
19
|
let n = Object.prototype.toString.call(e);
|
|
19
20
|
if (n !== Object.prototype.toString.call(t)) return !1;
|
|
@@ -22,23 +23,23 @@ var e = typeof document < "u" ? document.currentScript : null, t = e && e.tagNam
|
|
|
22
23
|
if (typeof e == "function") return !1;
|
|
23
24
|
if (Array.isArray(e) && Array.isArray(t)) {
|
|
24
25
|
if (e.length !== t.length) return !1;
|
|
25
|
-
for (let n = 0; n < e.length; n++) if (!
|
|
26
|
+
for (let n = 0; n < e.length; n++) if (!s(e[n], t[n])) return !1;
|
|
26
27
|
return !0;
|
|
27
28
|
}
|
|
28
|
-
if (e instanceof Set && t instanceof Set) return !!
|
|
29
|
-
if (e instanceof Map && t instanceof Map) return !(!
|
|
29
|
+
if (e instanceof Set && t instanceof Set) return !!s([...e.values()], [...t.values()]);
|
|
30
|
+
if (e instanceof Map && t instanceof Map) return !(!s([...e.keys()], [...t.keys()]) || !s([...e.values()], [...t.values()]));
|
|
30
31
|
if (n === "[object Object]") {
|
|
31
32
|
let n = e, r = t, i = Object.keys(n), a = Object.keys(r);
|
|
32
33
|
for (let e of i) {
|
|
33
34
|
let t = a.find((t) => t === e);
|
|
34
35
|
if (t === void 0) return !1;
|
|
35
36
|
let [i, o] = [n[e], r[t]];
|
|
36
|
-
if (!
|
|
37
|
+
if (!s(i, o)) return !1;
|
|
37
38
|
}
|
|
38
39
|
return !0;
|
|
39
40
|
}
|
|
40
41
|
throw TypeError(`comparing these objects is unavailable: ${e}, ${t}`, { cause: [e, t] });
|
|
41
|
-
},
|
|
42
|
+
}, c = () => {
|
|
42
43
|
let e, t;
|
|
43
44
|
return {
|
|
44
45
|
promise: new Promise((n, r) => {
|
|
@@ -47,16 +48,14 @@ var e = typeof document < "u" ? document.currentScript : null, t = e && e.tagNam
|
|
|
47
48
|
resolve: e,
|
|
48
49
|
reject: t
|
|
49
50
|
};
|
|
50
|
-
},
|
|
51
|
-
setTimeout(t, e);
|
|
52
|
-
}), f = (e) => Object.prototype.toString.call(e).slice(8, -1), p = (e) => (...t) => () => e(...t), ee = (e) => {
|
|
51
|
+
}, l = (e) => new Promise((t) => setTimeout(t, e)), ee = (e) => Object.prototype.toString.call(e).slice(8, -1), te = (e) => (...t) => () => e(...t), u = (e) => {
|
|
53
52
|
let t = [], n = [], r = "", i = !1;
|
|
54
53
|
for (let a = 0; a < e.length; a++) {
|
|
55
54
|
let o = e[a];
|
|
56
55
|
o === "\"" && (a === 0 || e[a - 1] !== "\\") ? i = !i : o === "," && !i ? (n.push(r.trim()), r = "") : o === "\n" && !i ? (n.push(r.trim()), t.push(n), n = [], r = "") : r += o;
|
|
57
56
|
}
|
|
58
57
|
return n.push(r.trim()), t.push(n), t;
|
|
59
|
-
},
|
|
58
|
+
}, d = async (e, t) => {
|
|
60
59
|
let n = new TextEncoder().encode(e), r = await crypto.subtle.digest(t, n);
|
|
61
60
|
return new Uint8Array(r);
|
|
62
61
|
}, ne = (e) => encodeURIComponent(e).replace(/[!'()*]/g, (e) => `%${e.charCodeAt(0).toString(16).toUpperCase()}`), re = (e) => {
|
|
@@ -65,16 +64,16 @@ var e = typeof document < "u" ? document.currentScript : null, t = e && e.tagNam
|
|
|
65
64
|
}, ie = (e, t) => {
|
|
66
65
|
let n = new Blob([e]).stream().pipeThrough(new CompressionStream(t));
|
|
67
66
|
return new Response(n).bytes();
|
|
68
|
-
},
|
|
67
|
+
}, f = (e, t) => {
|
|
69
68
|
let n = new Blob([e]).stream().pipeThrough(new DecompressionStream(t));
|
|
70
69
|
return new Response(n).bytes();
|
|
71
|
-
},
|
|
72
|
-
let
|
|
73
|
-
return
|
|
74
|
-
},
|
|
75
|
-
let n =
|
|
76
|
-
return new Response(
|
|
77
|
-
},
|
|
70
|
+
}, p = async (e, t) => {
|
|
71
|
+
let r = new Blob([e]).stream().pipeThrough(new CompressionStream(t));
|
|
72
|
+
return n(await new Response(r).bytes());
|
|
73
|
+
}, m = (e, t) => {
|
|
74
|
+
let n = r(e), i = new Blob([n]).stream().pipeThrough(new DecompressionStream(t));
|
|
75
|
+
return new Response(i).text();
|
|
76
|
+
}, h = (e, t) => new Promise((n, r) => {
|
|
78
77
|
setTimeout(async () => {
|
|
79
78
|
try {
|
|
80
79
|
n(await e());
|
|
@@ -82,42 +81,42 @@ var e = typeof document < "u" ? document.currentScript : null, t = e && e.tagNam
|
|
|
82
81
|
r(e);
|
|
83
82
|
}
|
|
84
83
|
}, t);
|
|
85
|
-
}),
|
|
84
|
+
}), g = (e, t) => {
|
|
86
85
|
if (t < -e.length || t >= e.length) throw RangeError("`index` is out of range");
|
|
87
86
|
return e.at(t);
|
|
88
|
-
},
|
|
89
|
-
let n =
|
|
87
|
+
}, ae = (e, t) => {
|
|
88
|
+
let n = g(e, t);
|
|
90
89
|
if (n == null) throw TypeError("value is nullable");
|
|
91
90
|
return n;
|
|
92
|
-
},
|
|
91
|
+
}, _ = (e, t) => Math.floor(Math.random() * (t - e) + e), v = (e, t) => {
|
|
93
92
|
t < 0n && (t *= -1n);
|
|
94
93
|
let n = e % t;
|
|
95
94
|
return n < 0n ? n + t : n;
|
|
96
|
-
},
|
|
95
|
+
}, y = (e, t = !1) => {
|
|
97
96
|
if (!Number.isFinite(e)) throw RangeError("`length` is not a valid number");
|
|
98
97
|
if (e <= 0) throw RangeError("`length` must be positive");
|
|
99
98
|
let n = Math.ceil(e / 8), r = crypto.getRandomValues(new Uint8Array(n)), i = Array.from(r, (e) => e.toString(2).padStart(8, "0")).join("").slice(0, e);
|
|
100
99
|
return t && (i = i.replace(/^\d/, "1")), BigInt("0b" + i);
|
|
101
|
-
},
|
|
100
|
+
}, b = (e, t) => {
|
|
102
101
|
if (e >= t) throw RangeError("`min` must be smaller than `max`");
|
|
103
102
|
let n = t - e, r = n.toString(2).length;
|
|
104
103
|
return e + (() => {
|
|
105
104
|
for (let e = 0; e < 1e5; e++) {
|
|
106
|
-
let e =
|
|
107
|
-
if (e >=
|
|
105
|
+
let e = y(r);
|
|
106
|
+
if (e >= x(2n, BigInt(r), n)) return e % n;
|
|
108
107
|
}
|
|
109
108
|
throw Error("Failed to generate a random bigint");
|
|
110
109
|
})();
|
|
111
|
-
},
|
|
110
|
+
}, x = (e, t, n) => {
|
|
112
111
|
if (n < 1n) throw RangeError("`mod` must be positive");
|
|
113
112
|
if (t < 0n) throw RangeError("`power` must not be negative");
|
|
114
|
-
if (e =
|
|
113
|
+
if (e = v(e, n), n === 1n) return 0n;
|
|
115
114
|
if (e % n === 1n || e % n === 0n) return e;
|
|
116
115
|
if (e === n - 1n) return t & 1n ? n - 1n : 1n;
|
|
117
116
|
let r = 1n;
|
|
118
117
|
for (; t > 0n;) t & 1n && (r = r * e % n), e = e * e % n, t >>= 1n;
|
|
119
118
|
return r;
|
|
120
|
-
},
|
|
119
|
+
}, S = (e, t) => {
|
|
121
120
|
if (e === 0n && t === 0n) return {
|
|
122
121
|
x: 0n,
|
|
123
122
|
y: 0n,
|
|
@@ -160,7 +159,7 @@ var e = typeof document < "u" ? document.currentScript : null, t = e && e.tagNam
|
|
|
160
159
|
y: o,
|
|
161
160
|
gcd: s
|
|
162
161
|
};
|
|
163
|
-
},
|
|
162
|
+
}, C = (e, t) => {
|
|
164
163
|
if (e >= t) return 1n;
|
|
165
164
|
let n = BigInt((t - 2n).toString(2).length), r = (t - e) / 2n;
|
|
166
165
|
if (n * r < 63n) {
|
|
@@ -169,12 +168,12 @@ var e = typeof document < "u" ? document.currentScript : null, t = e && e.tagNam
|
|
|
169
168
|
return n;
|
|
170
169
|
}
|
|
171
170
|
let i = e + r | 1n;
|
|
172
|
-
return
|
|
171
|
+
return C(e, i) * C(i, t);
|
|
173
172
|
}, oe = (e) => {
|
|
174
173
|
let t = 3n, n = 1n, r = 1n, i = BigInt(e.toString(2).length) - 1n;
|
|
175
174
|
for (let a = i - 1n; a > -1n; --a) {
|
|
176
175
|
let i = (e >> a) + 1n | 1n;
|
|
177
|
-
r *=
|
|
176
|
+
r *= C(t, i), t = i, n *= r;
|
|
178
177
|
}
|
|
179
178
|
return n;
|
|
180
179
|
}, se = (e) => {
|
|
@@ -182,7 +181,7 @@ var e = typeof document < "u" ? document.currentScript : null, t = e && e.tagNam
|
|
|
182
181
|
if (e === 0n) return 1n;
|
|
183
182
|
let t = e - BigInt(e.toString(2).match(/1/g)?.length ?? 0);
|
|
184
183
|
return oe(e) << t;
|
|
185
|
-
},
|
|
184
|
+
}, w = (e, t) => (e >>> (t & 31) | e << (-t & 31)) >>> 0, T = (e, t) => BigInt.asUintN(64, e >> (t & 63n) | e << (-t & 63n)), E = (e, t) => {
|
|
186
185
|
if (t < 1n || t % 2n == 0n) throw RangeError("`n` is out of range");
|
|
187
186
|
for (; e < 0n;) e += t;
|
|
188
187
|
e %= t;
|
|
@@ -196,7 +195,7 @@ var e = typeof document < "u" ? document.currentScript : null, t = e && e.tagNam
|
|
|
196
195
|
[e, t] = [t, e], e % 4n == 3n && t % 4n == 3n && (n *= -1n), e %= t;
|
|
197
196
|
}
|
|
198
197
|
return t === 1n ? n : 0n;
|
|
199
|
-
},
|
|
198
|
+
}, D = (e) => {
|
|
200
199
|
if (e < 0n) return !1;
|
|
201
200
|
if (e === 0n) return !0;
|
|
202
201
|
let t = 1n, n = e;
|
|
@@ -205,179 +204,201 @@ var e = typeof document < "u" ? document.currentScript : null, t = e && e.tagNam
|
|
|
205
204
|
r * r < e ? t = r : n = r;
|
|
206
205
|
}
|
|
207
206
|
return e === t ** 2n || e === (t + 1n) ** 2n;
|
|
208
|
-
},
|
|
207
|
+
}, O = class {
|
|
208
|
+
#e;
|
|
209
|
+
constructor(e) {
|
|
210
|
+
this.#e = e;
|
|
211
|
+
}
|
|
212
|
+
postMessage = (e, t) => new Promise((n, r) => {
|
|
213
|
+
let i = crypto.randomUUID(), a = (e) => {
|
|
214
|
+
let t = e.data;
|
|
215
|
+
t.id === i && (this.#e.removeEventListener("message", a), this.#e.removeEventListener("error", o), t.success ? n(t.value) : r(t.error));
|
|
216
|
+
}, o = (e) => {
|
|
217
|
+
this.#e.removeEventListener("message", a), this.#e.removeEventListener("error", o), r(e.error);
|
|
218
|
+
};
|
|
219
|
+
this.#e.addEventListener("message", a), this.#e.addEventListener("error", o);
|
|
220
|
+
let s = {
|
|
221
|
+
value: e,
|
|
222
|
+
id: i
|
|
223
|
+
};
|
|
224
|
+
this.#e.postMessage(s, t);
|
|
225
|
+
});
|
|
226
|
+
}, k = () => typeof window > "u" && typeof self < "u" && "importScripts" in self, A = (e, t) => {
|
|
227
|
+
if (!k()) throw Error("this function must be used in Worker");
|
|
228
|
+
let n = {
|
|
229
|
+
success: !0,
|
|
230
|
+
value: e,
|
|
231
|
+
id: t
|
|
232
|
+
};
|
|
233
|
+
self.postMessage(n);
|
|
234
|
+
}, j = (e, t) => {
|
|
235
|
+
if (!k()) throw Error("this function must be used in Worker");
|
|
236
|
+
let n = {
|
|
237
|
+
success: !1,
|
|
238
|
+
error: e,
|
|
239
|
+
id: t
|
|
240
|
+
};
|
|
241
|
+
self.postMessage(n);
|
|
242
|
+
}, M = (e) => {
|
|
209
243
|
if (e <= 1n) return !1;
|
|
210
244
|
if (e % 2n == 0n) return e === 2n;
|
|
211
245
|
let t = e - 1n, n = 0n;
|
|
212
246
|
for (; t % 2n == 0n;) t >>= 1n, n += 1n;
|
|
213
|
-
let [r, i] = [t, n], a =
|
|
247
|
+
let [r, i] = [t, n], a = x(2n, r, e);
|
|
214
248
|
if (a === 1n) return !0;
|
|
215
249
|
for (let t = 0n; t < i; t++) {
|
|
216
250
|
if (a === e - 1n) return !0;
|
|
217
251
|
a = a * a % e;
|
|
218
252
|
}
|
|
219
253
|
return !1;
|
|
220
|
-
},
|
|
221
|
-
let t = 5n, n =
|
|
254
|
+
}, N = (e) => {
|
|
255
|
+
let t = 5n, n = E(t, e);
|
|
222
256
|
for (; n > 0n;) {
|
|
223
|
-
if (t = t > 0n ? t + 2n : t - 2n, t *= -1n, t === -15n &&
|
|
224
|
-
n =
|
|
257
|
+
if (t = t > 0n ? t + 2n : t - 2n, t *= -1n, t === -15n && D(e)) return [0n, 0n];
|
|
258
|
+
n = E(t, e);
|
|
225
259
|
}
|
|
226
260
|
return [t, n];
|
|
227
|
-
},
|
|
261
|
+
}, P = (e, t) => (e & 1n) == 1n ? v(e + t >> 1n, t) : v(e >> 1n, t), F = (e, t, n, r) => {
|
|
228
262
|
let i = 1n, a = n, o = e.toString(2).slice(1);
|
|
229
|
-
for (let e of o) [i, a] = [
|
|
263
|
+
for (let e of o) [i, a] = [v(i * a, t), P(a * a + r * i * i, t)], e === "1" && ([i, a] = [P(n * i + a, t), P(r * i + n * a, t)]);
|
|
230
264
|
return [i, a];
|
|
231
|
-
},
|
|
265
|
+
}, I = (e, t, n, r) => {
|
|
232
266
|
if (e % 2n != 1n) throw RangeError("`n` must be odd");
|
|
233
267
|
let i = e + 1n, a = 0n;
|
|
234
268
|
for (; i % 2n == 0n;) i >>= 1n, a += 1n;
|
|
235
|
-
let [o, s] =
|
|
269
|
+
let [o, s] = F(i, e, n, t), c = s;
|
|
236
270
|
if (o === 0n) return !0;
|
|
237
|
-
r =
|
|
271
|
+
r = x(r, i, e);
|
|
238
272
|
for (let t = 0n; t < a; t++) {
|
|
239
273
|
if (c === 0n) return !0;
|
|
240
|
-
c =
|
|
274
|
+
c = v(c * c - 2n * r, e), r = x(r, 2n, e);
|
|
241
275
|
}
|
|
242
276
|
return !1;
|
|
243
|
-
},
|
|
277
|
+
}, L = [
|
|
278
|
+
2n,
|
|
279
|
+
3n,
|
|
280
|
+
5n,
|
|
281
|
+
7n,
|
|
282
|
+
11n,
|
|
283
|
+
13n,
|
|
284
|
+
17n,
|
|
285
|
+
19n,
|
|
286
|
+
23n,
|
|
287
|
+
29n,
|
|
288
|
+
31n,
|
|
289
|
+
37n,
|
|
290
|
+
41n,
|
|
291
|
+
43n,
|
|
292
|
+
47n,
|
|
293
|
+
53n,
|
|
294
|
+
59n,
|
|
295
|
+
61n,
|
|
296
|
+
67n,
|
|
297
|
+
71n,
|
|
298
|
+
73n,
|
|
299
|
+
79n,
|
|
300
|
+
83n,
|
|
301
|
+
89n,
|
|
302
|
+
97n,
|
|
303
|
+
101n,
|
|
304
|
+
103n,
|
|
305
|
+
107n,
|
|
306
|
+
109n,
|
|
307
|
+
113n,
|
|
308
|
+
127n,
|
|
309
|
+
131n,
|
|
310
|
+
137n,
|
|
311
|
+
139n,
|
|
312
|
+
149n,
|
|
313
|
+
151n,
|
|
314
|
+
157n,
|
|
315
|
+
163n,
|
|
316
|
+
167n,
|
|
317
|
+
173n,
|
|
318
|
+
179n,
|
|
319
|
+
181n,
|
|
320
|
+
191n,
|
|
321
|
+
193n,
|
|
322
|
+
197n,
|
|
323
|
+
199n,
|
|
324
|
+
211n,
|
|
325
|
+
223n,
|
|
326
|
+
227n,
|
|
327
|
+
229n,
|
|
328
|
+
233n,
|
|
329
|
+
239n,
|
|
330
|
+
241n,
|
|
331
|
+
251n,
|
|
332
|
+
257n,
|
|
333
|
+
263n,
|
|
334
|
+
269n,
|
|
335
|
+
271n,
|
|
336
|
+
277n,
|
|
337
|
+
281n,
|
|
338
|
+
283n,
|
|
339
|
+
293n,
|
|
340
|
+
307n,
|
|
341
|
+
311n,
|
|
342
|
+
313n,
|
|
343
|
+
317n,
|
|
344
|
+
331n,
|
|
345
|
+
337n,
|
|
346
|
+
347n,
|
|
347
|
+
349n,
|
|
348
|
+
353n,
|
|
349
|
+
359n,
|
|
350
|
+
367n,
|
|
351
|
+
373n,
|
|
352
|
+
379n,
|
|
353
|
+
383n,
|
|
354
|
+
389n,
|
|
355
|
+
397n,
|
|
356
|
+
401n,
|
|
357
|
+
409n,
|
|
358
|
+
419n,
|
|
359
|
+
421n,
|
|
360
|
+
431n,
|
|
361
|
+
433n,
|
|
362
|
+
439n,
|
|
363
|
+
443n,
|
|
364
|
+
449n,
|
|
365
|
+
457n,
|
|
366
|
+
461n,
|
|
367
|
+
463n,
|
|
368
|
+
467n,
|
|
369
|
+
479n,
|
|
370
|
+
487n,
|
|
371
|
+
491n,
|
|
372
|
+
499n
|
|
373
|
+
], R = (e) => {
|
|
244
374
|
if (e <= 1n) return !1;
|
|
245
375
|
if (e % 2n == 0n) return e === 2n;
|
|
246
|
-
for (let t of
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
11n,
|
|
252
|
-
13n,
|
|
253
|
-
17n,
|
|
254
|
-
19n,
|
|
255
|
-
23n,
|
|
256
|
-
29n,
|
|
257
|
-
31n,
|
|
258
|
-
37n,
|
|
259
|
-
41n,
|
|
260
|
-
43n,
|
|
261
|
-
47n,
|
|
262
|
-
53n,
|
|
263
|
-
59n,
|
|
264
|
-
61n,
|
|
265
|
-
67n,
|
|
266
|
-
71n,
|
|
267
|
-
73n,
|
|
268
|
-
79n,
|
|
269
|
-
83n,
|
|
270
|
-
89n,
|
|
271
|
-
97n,
|
|
272
|
-
101n,
|
|
273
|
-
103n,
|
|
274
|
-
107n,
|
|
275
|
-
109n,
|
|
276
|
-
113n,
|
|
277
|
-
127n,
|
|
278
|
-
131n,
|
|
279
|
-
137n,
|
|
280
|
-
139n,
|
|
281
|
-
149n,
|
|
282
|
-
151n,
|
|
283
|
-
157n,
|
|
284
|
-
163n,
|
|
285
|
-
167n,
|
|
286
|
-
173n,
|
|
287
|
-
179n,
|
|
288
|
-
181n,
|
|
289
|
-
191n,
|
|
290
|
-
193n,
|
|
291
|
-
197n,
|
|
292
|
-
199n,
|
|
293
|
-
211n,
|
|
294
|
-
223n,
|
|
295
|
-
227n,
|
|
296
|
-
229n,
|
|
297
|
-
233n,
|
|
298
|
-
239n,
|
|
299
|
-
241n,
|
|
300
|
-
251n,
|
|
301
|
-
257n,
|
|
302
|
-
263n,
|
|
303
|
-
269n,
|
|
304
|
-
271n,
|
|
305
|
-
277n,
|
|
306
|
-
281n,
|
|
307
|
-
283n,
|
|
308
|
-
293n,
|
|
309
|
-
307n,
|
|
310
|
-
311n,
|
|
311
|
-
313n,
|
|
312
|
-
317n,
|
|
313
|
-
331n,
|
|
314
|
-
337n,
|
|
315
|
-
347n,
|
|
316
|
-
349n,
|
|
317
|
-
353n,
|
|
318
|
-
359n,
|
|
319
|
-
367n,
|
|
320
|
-
373n,
|
|
321
|
-
379n,
|
|
322
|
-
383n,
|
|
323
|
-
389n,
|
|
324
|
-
397n,
|
|
325
|
-
401n,
|
|
326
|
-
409n,
|
|
327
|
-
419n,
|
|
328
|
-
421n,
|
|
329
|
-
431n,
|
|
330
|
-
433n,
|
|
331
|
-
439n,
|
|
332
|
-
443n,
|
|
333
|
-
449n,
|
|
334
|
-
457n,
|
|
335
|
-
461n,
|
|
336
|
-
463n,
|
|
337
|
-
467n,
|
|
338
|
-
479n,
|
|
339
|
-
487n,
|
|
340
|
-
491n,
|
|
341
|
-
499n
|
|
342
|
-
]) if (e % t === 0n) return e === t;
|
|
343
|
-
if (!A(e)) return !1;
|
|
344
|
-
let [t, n] = j(e);
|
|
345
|
-
return n === 0n ? !1 : P(e, t, 1n, (1n - t) / 4n);
|
|
346
|
-
}, I = (e, t) => {
|
|
376
|
+
for (let t of L) if (e % t === 0n) return e === t;
|
|
377
|
+
if (!M(e)) return !1;
|
|
378
|
+
let [t, n] = N(e);
|
|
379
|
+
return n === 0n ? !1 : I(e, t, 1n, (1n - t) / 4n);
|
|
380
|
+
}, z = (e, t) => {
|
|
347
381
|
if (t < 2n) throw RangeError("`max` must be 2 or larger");
|
|
348
382
|
for (let n = 0; n < 1e5; n++) {
|
|
349
|
-
let n =
|
|
350
|
-
if (
|
|
383
|
+
let n = b(e, t);
|
|
384
|
+
if (R(n)) return n;
|
|
351
385
|
}
|
|
352
|
-
throw Error("
|
|
353
|
-
},
|
|
386
|
+
throw Error("no primes were found");
|
|
387
|
+
}, B = (e, t = !1) => {
|
|
354
388
|
if (e < 2) throw RangeError("`bitLength` must be 2 or larger");
|
|
355
389
|
for (let n = 0; n < 1e5; n++) {
|
|
356
|
-
let n =
|
|
357
|
-
if (
|
|
390
|
+
let n = y(e, t);
|
|
391
|
+
if (R(n)) return n;
|
|
358
392
|
}
|
|
359
|
-
throw Error("
|
|
360
|
-
},
|
|
393
|
+
throw Error("no primes were found");
|
|
394
|
+
}, V, H = () => (V ||= new O(new Worker(new URL(
|
|
361
395
|
/* @vite-ignore */
|
|
362
|
-
"/assets/bpsw_worker-
|
|
363
|
-
"" +
|
|
364
|
-
), { type: "module" }),
|
|
365
|
-
let r = z(), i = crypto.randomUUID(), a = (e) => {
|
|
366
|
-
let s = e.data;
|
|
367
|
-
s.id === i && (r.removeEventListener("error", o), r.removeEventListener("message", a), s.success ? t(s.value) : n(s.error));
|
|
368
|
-
}, o = (e) => {
|
|
369
|
-
r.removeEventListener("error", o), r.removeEventListener("message", a), n(e);
|
|
370
|
-
};
|
|
371
|
-
r.addEventListener("message", a), r.addEventListener("error", o);
|
|
372
|
-
let s = {
|
|
373
|
-
id: i,
|
|
374
|
-
value: e
|
|
375
|
-
};
|
|
376
|
-
r.postMessage(s);
|
|
377
|
-
}), V = "Rational", H = class e {
|
|
396
|
+
"/assets/bpsw_worker-nJV3KnVo.js",
|
|
397
|
+
"" + import.meta.url
|
|
398
|
+
), { type: "module" })), V), U = (e) => H().postMessage(e), W = "Rational", G = class e {
|
|
378
399
|
#e;
|
|
379
400
|
#t;
|
|
380
|
-
static name =
|
|
401
|
+
static name = W;
|
|
381
402
|
constructor(e, t) {
|
|
382
403
|
t === 0n ? (this.#t = 0n, this.#e = e === 0n ? 0n : e > 0n ? 1n : -1n) : t > 0n ? (this.#e = e, this.#t = t) : (this.#e = -e, this.#t = -t), this.#n();
|
|
383
404
|
}
|
|
@@ -390,7 +411,7 @@ var e = typeof document < "u" ? document.currentScript : null, t = e && e.tagNam
|
|
|
390
411
|
if (a === 0) return new e(r ? -i : i, 1n);
|
|
391
412
|
t = 1 / a;
|
|
392
413
|
let [o, s] = [1n, i], [c, l] = [0n, 1n];
|
|
393
|
-
for (; `${l}`.length
|
|
414
|
+
for (; `${l}`.length <= n;) {
|
|
394
415
|
let n = BigInt(Math.floor(t)), i = t - Number(n);
|
|
395
416
|
if ([o, s] = [s, n * s + o], [c, l] = [l, n * l + c], i === 0) return new e(r ? -s : s, l);
|
|
396
417
|
t = 1 / i;
|
|
@@ -398,48 +419,32 @@ var e = typeof document < "u" ? document.currentScript : null, t = e && e.tagNam
|
|
|
398
419
|
return new e(r ? -o : o, c);
|
|
399
420
|
}
|
|
400
421
|
#n() {
|
|
401
|
-
let { gcd: e } =
|
|
422
|
+
let { gcd: e } = S(this.#e, this.#t);
|
|
402
423
|
e !== 0n && (this.#e /= e, this.#t /= e);
|
|
403
424
|
}
|
|
404
|
-
minus()
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
inverse() {
|
|
408
|
-
return new e(this.#t, this.#e);
|
|
409
|
-
}
|
|
410
|
-
add(t) {
|
|
425
|
+
minus = () => new e(-this.#e, this.#t);
|
|
426
|
+
inverse = () => new e(this.#t, this.#e);
|
|
427
|
+
add = (t) => {
|
|
411
428
|
let n = this.#t * t.#t;
|
|
412
429
|
return new e(this.#e * t.#t + t.#e * this.#t, n);
|
|
413
|
-
}
|
|
414
|
-
substr(e)
|
|
415
|
-
|
|
416
|
-
}
|
|
417
|
-
multiply(t) {
|
|
430
|
+
};
|
|
431
|
+
substr = (e) => this.add(e.minus());
|
|
432
|
+
multiply = (t) => {
|
|
418
433
|
let n = this.#t * t.#t;
|
|
419
434
|
return new e(this.#e * t.#e, n);
|
|
420
|
-
}
|
|
421
|
-
divide(e)
|
|
422
|
-
|
|
423
|
-
}
|
|
424
|
-
mediant(t) {
|
|
435
|
+
};
|
|
436
|
+
divide = (e) => this.multiply(e.inverse());
|
|
437
|
+
mediant = (t) => {
|
|
425
438
|
let n = this.#t + t.#t;
|
|
426
439
|
return new e(this.#e + t.#e, n);
|
|
427
|
-
}
|
|
428
|
-
toDecimal()
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
return this.toDecimal();
|
|
436
|
-
}
|
|
437
|
-
toJSON() {
|
|
438
|
-
return {
|
|
439
|
-
type: "Rational",
|
|
440
|
-
value: ["0x" + this.#e.toString(16), "0x" + this.#t.toString(16)]
|
|
441
|
-
};
|
|
442
|
-
}
|
|
440
|
+
};
|
|
441
|
+
toDecimal = () => Number(this.#e) / Number(this.#t);
|
|
442
|
+
toString = () => this.#e === 0n && this.#t === 0n ? "NaN" : this.#e === 0n ? "0" : this.#t === 0n ? this.#e < 0n ? "-Infinity" : "Infinity" : this.#t === 1n ? `${this.#e}` : `${this.#e}/${this.#t}`;
|
|
443
|
+
valueOf = () => this.toDecimal();
|
|
444
|
+
toJSON = () => ({
|
|
445
|
+
type: "Rational",
|
|
446
|
+
value: ["0x" + this.#e.toString(16), "0x" + this.#t.toString(16)]
|
|
447
|
+
});
|
|
443
448
|
static fromData(t) {
|
|
444
449
|
return new e(BigInt(t.value[0]), BigInt(t.value[1]));
|
|
445
450
|
}
|
|
@@ -451,19 +456,21 @@ var e = typeof document < "u" ? document.currentScript : null, t = e && e.tagNam
|
|
|
451
456
|
return new e(BigInt(r), BigInt(i));
|
|
452
457
|
}
|
|
453
458
|
};
|
|
454
|
-
Object.defineProperty(
|
|
459
|
+
Object.defineProperty(G.prototype, Symbol.toStringTag, { value: W });
|
|
455
460
|
//#endregion
|
|
456
461
|
//#region lib/named_error.ts
|
|
457
|
-
var
|
|
458
|
-
static name =
|
|
462
|
+
var K = "NamedError", q = class extends Error {
|
|
463
|
+
static name = K;
|
|
459
464
|
errName;
|
|
460
465
|
constructor(e, t, n) {
|
|
461
466
|
super(t, n), this.errName = e;
|
|
462
467
|
}
|
|
463
|
-
toJSON() {
|
|
468
|
+
toJSON = () => {
|
|
464
469
|
let e = (() => {
|
|
465
470
|
let e = this.cause;
|
|
466
|
-
if (e
|
|
471
|
+
if (e == null) return e;
|
|
472
|
+
let t = e.toString();
|
|
473
|
+
return t === "[object Object]" ? JSON.stringify(e) : t;
|
|
467
474
|
})(), { errName: t, message: n, stack: r } = this;
|
|
468
475
|
return {
|
|
469
476
|
name: t,
|
|
@@ -471,29 +478,29 @@ var U = "NamedError", W = class extends Error {
|
|
|
471
478
|
stack: r,
|
|
472
479
|
cause: e
|
|
473
480
|
};
|
|
474
|
-
}
|
|
481
|
+
};
|
|
475
482
|
};
|
|
476
|
-
Object.defineProperty(
|
|
483
|
+
Object.defineProperty(q.prototype, Symbol.toStringTag, { value: K });
|
|
477
484
|
//#endregion
|
|
478
485
|
//#region lib/random.ts
|
|
479
|
-
var
|
|
486
|
+
var J = (e) => {
|
|
480
487
|
if (e === 0n) return 64n;
|
|
481
488
|
let t = 0n;
|
|
482
489
|
for (; e > 0n && !(e & 1n);) ++t, e >>= 1n;
|
|
483
490
|
return BigInt.asUintN(64, t);
|
|
484
|
-
},
|
|
491
|
+
}, Y = (e, t) => {
|
|
485
492
|
let n = 0n, r = e & 2047n, i = 1023n - 1n;
|
|
486
|
-
if (r > 0n) return i -=
|
|
493
|
+
if (r > 0n) return i -= J(r), i;
|
|
487
494
|
i -= 11n;
|
|
488
495
|
for (let e = 0; e < 1e5; ++e) {
|
|
489
496
|
let e = t();
|
|
490
|
-
if (e > 0n) return i -=
|
|
497
|
+
if (e > 0n) return i -= J(e), i;
|
|
491
498
|
if (i -= 64n, i < n) return n;
|
|
492
499
|
}
|
|
493
500
|
throw Error("loop exceeded limit");
|
|
494
501
|
}, ce = (e) => {
|
|
495
502
|
let t = () => BigInt.asUintN(64, e()), n = () => {
|
|
496
|
-
let e = t(), n = BigInt.asUintN(52, e >> 11n), r = n === 0n && e >> 63n == 1n ?
|
|
503
|
+
let e = t(), n = BigInt.asUintN(52, e >> 11n), r = n === 0n && e >> 63n == 1n ? Y(e, t) + 1n : Y(e, t), { buffer: i } = BigUint64Array.from([r << 52n | n]), a = new Float64Array(i)[0];
|
|
497
504
|
if (a == null) throw Error("unexpected");
|
|
498
505
|
return a;
|
|
499
506
|
};
|
|
@@ -504,9 +511,9 @@ var G = (e) => {
|
|
|
504
511
|
}
|
|
505
512
|
throw Error("Loop limit exceeded");
|
|
506
513
|
};
|
|
507
|
-
}, le = [9600629759793949339n, 15726070495360670683n], ue = 6364136223846793005n,
|
|
514
|
+
}, le = [9600629759793949339n, 15726070495360670683n], ue = 6364136223846793005n, X = "PCGMinimal", Z = class {
|
|
508
515
|
#e;
|
|
509
|
-
static name =
|
|
516
|
+
static name = X;
|
|
510
517
|
constructor(e) {
|
|
511
518
|
if (e && e[0] != null && e[1] != null) {
|
|
512
519
|
if (this.#e = new BigUint64Array(2), this.#e[0] == null || this.#e[1] == null) throw TypeError("unexpected");
|
|
@@ -520,12 +527,10 @@ var G = (e) => {
|
|
|
520
527
|
get #n() {
|
|
521
528
|
if (this.#e[0] == null || this.#e[1] == null) throw TypeError("unexpected");
|
|
522
529
|
let e = this.#e[0], t = Number(e >> 59n);
|
|
523
|
-
return
|
|
530
|
+
return w(Number(BigInt.asUintN(32, (e ^ e >> 18n) >> 27n)), t);
|
|
524
531
|
}
|
|
525
|
-
getRandU32()
|
|
526
|
-
|
|
527
|
-
}
|
|
528
|
-
getBoundedRandU32(e) {
|
|
532
|
+
getRandU32 = () => (this.#t(), this.#n);
|
|
533
|
+
getBoundedRandU32 = (e) => {
|
|
529
534
|
let t = 4294967296;
|
|
530
535
|
if (e > t) throw RangeError("`bound` exceeded limit (2^32)");
|
|
531
536
|
if (e <= 0) throw RangeError("'bound' must be positive");
|
|
@@ -535,49 +540,49 @@ var G = (e) => {
|
|
|
535
540
|
if (t >= n) return t % e;
|
|
536
541
|
}
|
|
537
542
|
throw Error("exceeded loop limit");
|
|
538
|
-
}
|
|
543
|
+
};
|
|
539
544
|
*genRandU32s(e, t) {
|
|
540
545
|
if (e <= 0) throw RangeError("'step' must be positive");
|
|
541
546
|
for (let n = 0; n < e; n++) yield typeof t == "number" ? this.getBoundedRandU32(t) : this.getRandU32();
|
|
542
547
|
}
|
|
543
548
|
};
|
|
544
|
-
Object.defineProperty(
|
|
549
|
+
Object.defineProperty(Z.prototype, Symbol.toStringTag, { value: X });
|
|
545
550
|
//#endregion
|
|
546
551
|
//#region lib/xoshiro_minimal.ts
|
|
547
|
-
var
|
|
552
|
+
var de = [
|
|
548
553
|
13715198867125970446n,
|
|
549
554
|
3333371893450545919n,
|
|
550
555
|
5627726498316411518n,
|
|
551
556
|
8467276975966080893n
|
|
552
|
-
],
|
|
557
|
+
], Q = "XoshiroMinimal", $ = class {
|
|
553
558
|
bits = 64;
|
|
554
559
|
#e;
|
|
555
|
-
static name =
|
|
560
|
+
static name = Q;
|
|
556
561
|
constructor(e) {
|
|
557
562
|
if (e && e[0] != null && e[1] != null && e[2] != null && e[3] != null) {
|
|
558
563
|
if (this.#e = new BigUint64Array(4), this.#e[0] = e[0], this.#e[1] = e[1], this.#t(), this.#e[2] == null || this.#e[3] == null) throw TypeError("unexpected");
|
|
559
564
|
this.#e[2] += e[2], this.#e[3] += e[3];
|
|
560
|
-
} else this.#e = BigUint64Array.from(
|
|
565
|
+
} else this.#e = BigUint64Array.from(de);
|
|
561
566
|
}
|
|
562
567
|
#t() {
|
|
563
568
|
if (this.#e[0] == null || this.#e[1] == null || this.#e[2] == null || this.#e[3] == null) throw TypeError("unexpected");
|
|
564
569
|
let e = this.#e[1] << 17n;
|
|
565
|
-
this.#e[2] ^= this.#e[0], this.#e[3] ^= this.#e[1], this.#e[1] ^= this.#e[2], this.#e[0] ^= this.#e[3], this.#e[2] ^= e, this.#e[3] =
|
|
570
|
+
this.#e[2] ^= this.#e[0], this.#e[3] ^= this.#e[1], this.#e[1] ^= this.#e[2], this.#e[0] ^= this.#e[3], this.#e[2] ^= e, this.#e[3] = T(this.#e[3], 45n);
|
|
566
571
|
}
|
|
567
572
|
get value() {
|
|
568
573
|
if (this.#e[0] == null || this.#e[3] == null) throw TypeError("unexpected");
|
|
569
|
-
let e =
|
|
574
|
+
let e = T(this.#e[0] + this.#e[3], 23n) + this.#e[0];
|
|
570
575
|
return BigInt.asUintN(64, e);
|
|
571
576
|
}
|
|
572
|
-
getRandU64() {
|
|
577
|
+
getRandU64 = () => {
|
|
573
578
|
let e = this.value;
|
|
574
579
|
return this.#t(), e;
|
|
575
|
-
}
|
|
576
|
-
getRandU32() {
|
|
580
|
+
};
|
|
581
|
+
getRandU32 = () => {
|
|
577
582
|
let e = BigInt.asUintN(32, this.getRandU64());
|
|
578
583
|
return Number(e);
|
|
579
|
-
}
|
|
580
|
-
getBoundedRandU64(e) {
|
|
584
|
+
};
|
|
585
|
+
getBoundedRandU64 = (e) => {
|
|
581
586
|
let t = 1n << 64n;
|
|
582
587
|
if (e > t) throw RangeError("`bound` exceeded limit");
|
|
583
588
|
if (e <= 0n) throw RangeError("`bound` must be positive");
|
|
@@ -587,13 +592,13 @@ var Y = [
|
|
|
587
592
|
if (t >= n) return t % e;
|
|
588
593
|
}
|
|
589
594
|
throw Error("exceeded loop limit");
|
|
590
|
-
}
|
|
591
|
-
getBoundedRandU32(e) {
|
|
595
|
+
};
|
|
596
|
+
getBoundedRandU32 = (e) => {
|
|
592
597
|
if (e > 2 ** 32) throw RangeError("`bound` exceeded limit");
|
|
593
598
|
if (e <= 0n) throw RangeError("`bound` must be positive");
|
|
594
599
|
let t = this.getBoundedRandU64(BigInt(e));
|
|
595
600
|
return Number(t);
|
|
596
|
-
}
|
|
601
|
+
};
|
|
597
602
|
*genRandU64s(e, t) {
|
|
598
603
|
if (e <= 0) throw RangeError("`step` must be positive");
|
|
599
604
|
for (let n = 0; n < e; ++n) yield t === void 0 ? this.getRandU64() : this.getBoundedRandU64(t);
|
|
@@ -603,50 +608,22 @@ var Y = [
|
|
|
603
608
|
for (let n = 0; n < e; ++n) yield t === void 0 ? this.getRandU32() : this.getBoundedRandU32(t);
|
|
604
609
|
}
|
|
605
610
|
};
|
|
606
|
-
Object.defineProperty(Z.prototype, Symbol.toStringTag, { value: X });
|
|
607
|
-
//#endregion
|
|
608
|
-
//#region lib/worker_stream.ts
|
|
609
|
-
var Q = "WorkerStream", $ = class extends ReadableStream {
|
|
610
|
-
close;
|
|
611
|
-
#e;
|
|
612
|
-
static name = Q;
|
|
613
|
-
constructor(e, t) {
|
|
614
|
-
let n, r, i;
|
|
615
|
-
super({
|
|
616
|
-
start: (t) => {
|
|
617
|
-
n = (e) => {
|
|
618
|
-
t.enqueue(e.data);
|
|
619
|
-
}, r = (i) => {
|
|
620
|
-
e.removeEventListener("message", n), e.removeEventListener("error", r), t.error(Error(i.message, { cause: i.error }));
|
|
621
|
-
}, i = () => {
|
|
622
|
-
e.removeEventListener("message", n), e.removeEventListener("error", r), t.close();
|
|
623
|
-
}, e.addEventListener("message", n), e.addEventListener("error", r);
|
|
624
|
-
},
|
|
625
|
-
cancel: () => {
|
|
626
|
-
e.removeEventListener("message", n), e.removeEventListener("error", r);
|
|
627
|
-
}
|
|
628
|
-
}, t), this.close = i, this.#e = e;
|
|
629
|
-
}
|
|
630
|
-
postMessage = (e, t) => {
|
|
631
|
-
this.#e.postMessage(e, t);
|
|
632
|
-
};
|
|
633
|
-
};
|
|
634
611
|
Object.defineProperty($.prototype, Symbol.toStringTag, { value: Q });
|
|
635
612
|
//#endregion
|
|
636
613
|
//#region lib/leb128.ts
|
|
637
|
-
var
|
|
614
|
+
var fe = (e) => {
|
|
638
615
|
let t = e < 0n;
|
|
639
616
|
t && (e *= -1n);
|
|
640
617
|
let n = e.toString(2).length, r = e === 1n << BigInt(n - 1) && !(n % 7) && t, i = Math.floor(n / 7) + 1;
|
|
641
618
|
return r ? i - 1 : i;
|
|
642
|
-
},
|
|
643
|
-
let t =
|
|
619
|
+
}, pe = (e) => {
|
|
620
|
+
let t = fe(e);
|
|
644
621
|
e = BigInt.asUintN(t * 7, e);
|
|
645
622
|
let n = new Uint8Array(t);
|
|
646
623
|
for (let r = 0; r < t - 1; ++r) n[r] = Number(e & 127n) | 128, e >>= 7n;
|
|
647
624
|
let r = Number(e & 127n);
|
|
648
625
|
return n[t - 1] = r, e >>= 7n, n;
|
|
649
|
-
},
|
|
626
|
+
}, me = (e) => {
|
|
650
627
|
let t = e.length, n = 0n;
|
|
651
628
|
for (let [t, r] of e.entries()) {
|
|
652
629
|
let e = BigInt(r & 127);
|
|
@@ -655,4 +632,4 @@ var de = (e) => {
|
|
|
655
632
|
return BigInt.asIntN(7 * t, n);
|
|
656
633
|
};
|
|
657
634
|
//#endregion
|
|
658
|
-
export {
|
|
635
|
+
export { O as AsyncWorker, q as NamedError, Z as PCGMinimal, G as Rational, $ as XoshiroMinimal, R as bailliePSW, U as bailliePSWAsync, ie as compress, p as compressString, me as decodeLEB128, re as decodeRFC3986URIComponent, f as decompress, m as decompressString, pe as encodeLEB128, ne as encodeRFC3986URIComponent, S as exEuclidean, se as factorial, ce as floatRng, t as fromBase64, r as fromBase64URL, a as fromOct, d as getHash, y as getRandBIByBitLength, b as getRandBIByRange, B as getRandPrimeByBitLength, z as getRandPrimeByRange, _ as getRndInt, ee as getStringTag, s as isDeepStrictEqual, D as isSquare, E as jacobiSymbol, te as lazify, x as modPow, g as nullableStrictAt, u as parseCSV, j as postFailed, A as postSuccess, v as residue, w as rot32, T as rot64, o as sameValueZero, h as setTimeoutPromise, l as sleep, ae as strictAt, e as toBase64, n as toBase64URL, i as toOct, c as withResolvers };
|
package/dist/bundle.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var UtilFns=(function(e){
|
|
2
|
-
`&&!i?(n.push(r.trim()),t.push(n),n=[],r=``):r+=o}return n.push(r.trim()),t.push(n),t},m=async(e,t)=>{let n=new TextEncoder().encode(e),r=await crypto.subtle.digest(t,n);return new Uint8Array(r)},h=e=>encodeURIComponent(e).replace(/[!'()*]/g,e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`),g=e=>{if(e.includes(`+`))throw URIError("an input string must not include `+`");return decodeURIComponent(e)},ne=(e,t)=>{let n=new Blob([e]).stream().pipeThrough(new CompressionStream(t));return new Response(n).bytes()},re=(e,t)=>{let n=new Blob([e]).stream().pipeThrough(new DecompressionStream(t));return new Response(n).bytes()},ie=async(e,t)=>{let n=new Blob([e]).stream().pipeThrough(new CompressionStream(t));return a(await new Response(n).bytes())},ae=(e,t)=>{let n=o(e),r=new Blob([n]).stream().pipeThrough(new DecompressionStream(t));return new Response(r).text()},oe=(e,t)=>new Promise((n,r)=>{setTimeout(async()=>{try{n(await e())}catch(e){r(e)}},t)}),_=(e,t)=>{if(t<-e.length||t>=e.length)throw RangeError("`index` is out of range");return e.at(t)},v=(e,t)=>{let n=_(e,t);if(n==null)throw TypeError(`value is nullable`);return n},y=(e,t)=>Math.floor(Math.random()*(t-e)+e),b=(e,t)=>{t<0n&&(t*=-1n);let n=e%t;return n<0n?n+t:n},x=(e,t=!1)=>{if(!Number.isFinite(e))throw RangeError("`length` is not a valid number");if(e<=0)throw RangeError("`length` must be positive");let n=Math.ceil(e/8),r=crypto.getRandomValues(new Uint8Array(n)),i=Array.from(r,e=>e.toString(2).padStart(8,`0`)).join(``).slice(0,e);return t&&(i=i.replace(/^\d/,`1`)),BigInt(`0b`+i)},S=(e,t)=>{if(e>=t)throw RangeError("`min` must be smaller than `max`");let n=t-e,r=n.toString(2).length;return e+(()=>{for(let e=0;e<1e5;e++){let e=x(r);if(e>=C(2n,BigInt(r),n))return e%n}throw Error(`Failed to generate a random bigint`)})()},C=(e,t,n)=>{if(n<1n)throw RangeError("`mod` must be positive");if(t<0n)throw RangeError("`power` must not be negative");if(e=b(e,n),n===1n)return 0n;if(e%n===1n||e%n===0n)return e;if(e===n-1n)return t&1n?n-1n:1n;let r=1n;for(;t>0n;)t&1n&&(r=r*e%n),e=e*e%n,t>>=1n;return r},w=(e,t)=>{if(e===0n&&t===0n)return{x:0n,y:0n,gcd:0n};if(e===0n)return t>0n?{x:0n,y:-1n,gcd:t}:{x:0n,y:1n,gcd:-t};if(t===0n)return e>0n?{x:1n,y:0n,gcd:e}:{x:-1n,y:0n,gcd:-e};let[n,r,i]=[1n,0n,e],[a,o,s]=[0n,-1n,t];for(;;){let e=i/s,t=i-e*s;if(t===0n)break;[n,a]=[a,n-e*a],[r,o]=[o,r-e*o],[i,s]=[s,t]}return s<0n&&(a*=-1n,o*=-1n,s*=-1n),{x:a,y:o,gcd:s}},T=(e,t)=>{if(e>=t)return 1n;let n=BigInt((t-2n).toString(2).length),r=(t-e)/2n;if(n*r<63n){let n=e;for(let r=e+2n;r<t;r+=2n)n*=r;return n}let i=e+r|1n;return T(e,i)*T(i,t)},se=e=>{let t=3n,n=1n,r=1n,i=BigInt(e.toString(2).length)-1n;for(let a=i-1n;a>-1n;--a){let i=(e>>a)+1n|1n;r*=T(t,i),t=i,n*=r}return n},ce=e=>{if(e<0n)throw RangeError(`'n' must be non-negative`);if(e===0n)return 1n;let t=e-BigInt(e.toString(2).match(/1/g)?.length??0);return se(e)<<t},E=(e,t)=>(e>>>(t&31)|e<<(-t&31))>>>0,D=(e,t)=>BigInt.asUintN(64,e>>(t&63n)|e<<(-t&63n)),O=(e,t)=>{if(t<1n||t%2n==0n)throw RangeError("`n` is out of range");for(;e<0n;)e+=t;e%=t;let n=1n;for(;e!==0n;){for(;e%2n==0n;){e/=2n;let r=t%8n;(r===3n||r===5n)&&(n*=-1n)}[e,t]=[t,e],e%4n==3n&&t%4n==3n&&(n*=-1n),e%=t}return t===1n?n:0n},k=e=>{if(e<0n)return!1;if(e===0n)return!0;let t=1n,n=e;for(;t+1n<n;){let r=(t+n)/2n;r*r<e?t=r:n=r}return e===t**2n||e===(t+1n)**2n},A=e=>{if(e<=1n)return!1;if(e%2n==0n)return e===2n;let t=e-1n,n=0n;for(;t%2n==0n;)t>>=1n,n+=1n;let[r,i]=[t,n],a=C(2n,r,e);if(a===1n)return!0;for(let t=0n;t<i;t++){if(a===e-1n)return!0;a=a*a%e}return!1},j=e=>{let t=5n,n=O(t,e);for(;n>0n;){if(t=t>0n?t+2n:t-2n,t*=-1n,t===-15n&&k(e))return[0n,0n];n=O(t,e)}return[t,n]},M=(e,t)=>(e&1n)==1n?b(e+t>>1n,t):b(e>>1n,t),N=(e,t,n,r)=>{let i=1n,a=n,o=e.toString(2).slice(1);for(let e of o)[i,a]=[b(i*a,t),M(a*a+r*i*i,t)],e===`1`&&([i,a]=[M(n*i+a,t),M(r*i+n*a,t)]);return[i,a]},P=(e,t,n,r)=>{if(e%2n!=1n)throw RangeError("`n` must be odd");let i=e+1n,a=0n;for(;i%2n==0n;)i>>=1n,a+=1n;let[o,s]=N(i,e,n,t),c=s;if(o===0n)return!0;r=C(r,i,e);for(let t=0n;t<a;t++){if(c===0n)return!0;c=b(c*c-2n*r,e),r=C(r,2n,e)}return!1},F=e=>{if(e<=1n)return!1;if(e%2n==0n)return e===2n;for(let t of[2n,3n,5n,7n,11n,13n,17n,19n,23n,29n,31n,37n,41n,43n,47n,53n,59n,61n,67n,71n,73n,79n,83n,89n,97n,101n,103n,107n,109n,113n,127n,131n,137n,139n,149n,151n,157n,163n,167n,173n,179n,181n,191n,193n,197n,199n,211n,223n,227n,229n,233n,239n,241n,251n,257n,263n,269n,271n,277n,281n,283n,293n,307n,311n,313n,317n,331n,337n,347n,349n,353n,359n,367n,373n,379n,383n,389n,397n,401n,409n,419n,421n,431n,433n,439n,443n,449n,457n,461n,463n,467n,479n,487n,491n,499n])if(e%t===0n)return e===t;if(!A(e))return!1;let[t,n]=j(e);return n===0n?!1:P(e,t,1n,(1n-t)/4n)},I=(e,t)=>{if(t<2n)throw RangeError("`max` must be 2 or larger");for(let n=0;n<1e5;n++){let n=S(e,t);if(F(n))return n}throw Error(`No primes were found`)},L=(e,t=!1)=>{if(e<2)throw RangeError("`bitLength` must be 2 or larger");for(let n=0;n<1e5;n++){let n=x(e,t);if(F(n))return n}throw Error(`NoPrimesFound`)},R,z=()=>(R||=new Worker(new URL(`/assets/bpsw_worker-D0gmU_qc.js`,``+n.url),{type:`module`}),R),B=async e=>new Promise((t,n)=>{let r=z(),i=crypto.randomUUID(),a=e=>{let s=e.data;s.id===i&&(r.removeEventListener(`error`,o),r.removeEventListener(`message`,a),s.success?t(s.value):n(s.error))},o=e=>{r.removeEventListener(`error`,o),r.removeEventListener(`message`,a),n(e)};r.addEventListener(`message`,a),r.addEventListener(`error`,o);let s={id:i,value:e};r.postMessage(s)}),V=`Rational`,H=class e{#e;#t;static name=V;constructor(e,t){t===0n?(this.#t=0n,this.#e=e===0n?0n:e>0n?1n:-1n):t>0n?(this.#e=e,this.#t=t):(this.#e=-e,this.#t=-t),this.#n()}static fromDecimal(t,n=5){if(Number.isNaN(t))return new e(0n,0n);if(Math.abs(t)===1/0)return new e(t>0?1n:-1n,0n);let r=t<0;r&&(t*=-1);let i=BigInt(Math.floor(t)),a=t-Number(i);if(a===0)return new e(r?-i:i,1n);t=1/a;let[o,s]=[1n,i],[c,l]=[0n,1n];for(;`${l}`.length<n+1;){let n=BigInt(Math.floor(t)),i=t-Number(n);if([o,s]=[s,n*s+o],[c,l]=[l,n*l+c],i===0)return new e(r?-s:s,l);t=1/i}return new e(r?-o:o,c)}#n(){let{gcd:e}=w(this.#e,this.#t);e!==0n&&(this.#e/=e,this.#t/=e)}minus(){return new e(-this.#e,this.#t)}inverse(){return new e(this.#t,this.#e)}add(t){let n=this.#t*t.#t;return new e(this.#e*t.#t+t.#e*this.#t,n)}substr(e){return this.add(e.minus())}multiply(t){let n=this.#t*t.#t;return new e(this.#e*t.#e,n)}divide(e){return this.multiply(e.inverse())}mediant(t){let n=this.#t+t.#t;return new e(this.#e+t.#e,n)}toDecimal(){return Number(this.#e)/Number(this.#t)}toString(){return this.#e===0n&&this.#t===0n?`NaN`:this.#e===0n?`0`:this.#t===0n?this.#e<0n?`-Infinity`:`Infinity`:this.#t===1n?`${this.#e}`:`${this.#e}/${this.#t}`}valueOf(){return this.toDecimal()}toJSON(){return{type:`Rational`,value:[`0x`+this.#e.toString(16),`0x`+this.#t.toString(16)]}}static fromData(t){return new e(BigInt(t.value[0]),BigInt(t.value[1]))}static parse(t){let n=/^\s*(\d+)\s*\/\s*(\d+)\s*$/.exec(t);if(!n)throw Error(`cannot parse`);let r=n.at(1),i=n.at(2);if(!r||!i)throw Error(`cannot parse`);return new e(BigInt(r),BigInt(i))}};Object.defineProperty(H.prototype,Symbol.toStringTag,{value:V});var U=`NamedError`,W=class extends Error{static name=U;errName;constructor(e,t,n){super(t,n),this.errName=e}toJSON(){let e=(()=>{let e=this.cause;if(e!=null)return typeof e==`string`||typeof e==`number`||typeof e==`boolean`?e:typeof e==`bigint`?e.toString():typeof e==`object`?e instanceof Set||e instanceof Map?Object.fromEntries(e):e:void 0})(),{errName:t,message:n,stack:r}=this;return{name:t,message:n,stack:r,cause:e}}};Object.defineProperty(W.prototype,Symbol.toStringTag,{value:U});var G=e=>{if(e===0n)return 64n;let t=0n;for(;e>0n&&!(e&1n);)++t,e>>=1n;return BigInt.asUintN(64,t)},K=(e,t)=>{let n=0n,r=e&2047n,i=1023n-1n;if(r>0n)return i-=G(r),i;i-=11n;for(let e=0;e<1e5;++e){let e=t();if(e>0n)return i-=G(e),i;if(i-=64n,i<n)return n}throw Error(`loop exceeded limit`)},q=e=>{let t=()=>BigInt.asUintN(64,e()),n=()=>{let e=t(),n=BigInt.asUintN(52,e>>11n),r=n===0n&&e>>63n==1n?K(e,t)+1n:K(e,t),{buffer:i}=BigUint64Array.from([r<<52n|n]),a=new Float64Array(i)[0];if(a==null)throw Error(`unexpected`);return a};return()=>{for(let e=0;e<1e5;++e){let e=n();if(e<1)return e}throw Error(`Loop limit exceeded`)}},le=[9600629759793949339n,15726070495360670683n],ue=6364136223846793005n,J=`PCGMinimal`,Y=class{#e;static name=J;constructor(e){if(e&&e[0]!=null&&e[1]!=null){if(this.#e=new BigUint64Array(2),this.#e[0]==null||this.#e[1]==null)throw TypeError(`unexpected`);this.#e[1]=e[1]<<1n|1n,this.#t(),this.#e[0]+=e[0],this.#t()}else this.#e=BigUint64Array.from(le)}#t(){if(this.#e[0]==null||this.#e[1]==null)throw TypeError(`unexpected`);this.#e[0]=this.#e[0]*ue+this.#e[1]}get#n(){if(this.#e[0]==null||this.#e[1]==null)throw TypeError(`unexpected`);let e=this.#e[0],t=Number(e>>59n);return E(Number(BigInt.asUintN(32,(e^e>>18n)>>27n)),t)}getRandU32(){return this.#t(),this.#n}getBoundedRandU32(e){let t=4294967296;if(e>t)throw RangeError("`bound` exceeded limit (2^32)");if(e<=0)throw RangeError(`'bound' must be positive`);let n=t%e;for(let t=0;t<1e5;++t){let t=this.getRandU32();if(t>=n)return t%e}throw Error(`exceeded loop limit`)}*genRandU32s(e,t){if(e<=0)throw RangeError(`'step' must be positive`);for(let n=0;n<e;n++)yield typeof t==`number`?this.getBoundedRandU32(t):this.getRandU32()}};Object.defineProperty(Y.prototype,Symbol.toStringTag,{value:J});var de=[13715198867125970446n,3333371893450545919n,5627726498316411518n,8467276975966080893n],X=`XoshiroMinimal`,Z=class{bits=64;#e;static name=X;constructor(e){if(e&&e[0]!=null&&e[1]!=null&&e[2]!=null&&e[3]!=null){if(this.#e=new BigUint64Array(4),this.#e[0]=e[0],this.#e[1]=e[1],this.#t(),this.#e[2]==null||this.#e[3]==null)throw TypeError(`unexpected`);this.#e[2]+=e[2],this.#e[3]+=e[3]}else this.#e=BigUint64Array.from(de)}#t(){if(this.#e[0]==null||this.#e[1]==null||this.#e[2]==null||this.#e[3]==null)throw TypeError(`unexpected`);let e=this.#e[1]<<17n;this.#e[2]^=this.#e[0],this.#e[3]^=this.#e[1],this.#e[1]^=this.#e[2],this.#e[0]^=this.#e[3],this.#e[2]^=e,this.#e[3]=D(this.#e[3],45n)}get value(){if(this.#e[0]==null||this.#e[3]==null)throw TypeError(`unexpected`);let e=D(this.#e[0]+this.#e[3],23n)+this.#e[0];return BigInt.asUintN(64,e)}getRandU64(){let e=this.value;return this.#t(),e}getRandU32(){let e=BigInt.asUintN(32,this.getRandU64());return Number(e)}getBoundedRandU64(e){let t=1n<<64n;if(e>t)throw RangeError("`bound` exceeded limit");if(e<=0n)throw RangeError("`bound` must be positive");let n=t%e;for(let t=0;t<1e5;++t){let t=this.getRandU64();if(t>=n)return t%e}throw Error(`exceeded loop limit`)}getBoundedRandU32(e){if(e>2**32)throw RangeError("`bound` exceeded limit");if(e<=0n)throw RangeError("`bound` must be positive");let t=this.getBoundedRandU64(BigInt(e));return Number(t)}*genRandU64s(e,t){if(e<=0)throw RangeError("`step` must be positive");for(let n=0;n<e;++n)yield t===void 0?this.getRandU64():this.getBoundedRandU64(t)}*genRandU32s(e,t){if(e<=0)throw RangeError("`step` must be positive");for(let n=0;n<e;++n)yield t===void 0?this.getRandU32():this.getBoundedRandU32(t)}};Object.defineProperty(Z.prototype,Symbol.toStringTag,{value:X});var Q=`WorkerStream`,$=class extends ReadableStream{close;#e;static name=Q;constructor(e,t){let n,r,i;super({start:t=>{n=e=>{t.enqueue(e.data)},r=i=>{e.removeEventListener(`message`,n),e.removeEventListener(`error`,r),t.error(Error(i.message,{cause:i.error}))},i=()=>{e.removeEventListener(`message`,n),e.removeEventListener(`error`,r),t.close()},e.addEventListener(`message`,n),e.addEventListener(`error`,r)},cancel:()=>{e.removeEventListener(`message`,n),e.removeEventListener(`error`,r)}},t),this.close=i,this.#e=e}postMessage=(e,t)=>{this.#e.postMessage(e,t)}};Object.defineProperty($.prototype,Symbol.toStringTag,{value:Q});var fe=e=>{let t=e<0n;t&&(e*=-1n);let n=e.toString(2).length,r=e===1n<<BigInt(n-1)&&!(n%7)&&t,i=Math.floor(n/7)+1;return r?i-1:i};return e.NamedError=W,e.PCGMinimal=Y,e.Rational=H,e.WorkerStream=$,e.XoshiroMinimal=Z,e.bailliePSW=F,e.bailliePSWAsync=B,e.compress=ne,e.compressString=ie,e.decodeLEB128=e=>{let t=e.length,n=0n;for(let[t,r]of e.entries()){let e=BigInt(r&127);n+=e<<BigInt(7*t)}return BigInt.asIntN(7*t,n)},e.decodeRFC3986URIComponent=g,e.decompress=re,e.decompressString=ae,e.encodeLEB128=e=>{let t=fe(e);e=BigInt.asUintN(t*7,e);let n=new Uint8Array(t);for(let r=0;r<t-1;++r)n[r]=Number(e&127n)|128,e>>=7n;let r=Number(e&127n);return n[t-1]=r,e>>=7n,n},e.encodeRFC3986URIComponent=h,e.exEuclidean=w,e.factorial=ce,e.floatRng=q,e.fromBase64=i,e.fromBase64URL=o,e.fromOct=c,e.getHash=m,e.getRandBIByBitLength=x,e.getRandBIByRange=S,e.getRandPrimeByBitLength=L,e.getRandPrimeByRange=I,e.getRndInt=y,e.getStringTag=ee,e.isDeepStrictEqual=u,e.isSquare=k,e.jacobiSymbol=O,e.lazify=te,e.modPow=C,e.nullableStrictAt=_,e.parseCSV=p,e.residue=b,e.rot32=E,e.rot64=D,e.sameValueZero=l,e.setTimeoutPromise=oe,e.sleep=f,e.strictAt=v,e.toBase64=r,e.toBase64URL=a,e.toOct=s,e.withResolvers=d,e})({});
|
|
1
|
+
var UtilFns=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=e=>{let t=Array.from(e,e=>String.fromCharCode(e));return btoa(t.join(``))},n=e=>{let t=atob(e);return Uint8Array.from(t,e=>e.charCodeAt(0))},r=e=>t(e).replaceAll(`+`,`-`).replaceAll(`/`,`_`).replace(/=+$/,``),i=e=>{let t=4-(e.length&3)&3;return n(e.concat(`=`.repeat(t)).replaceAll(`-`,`+`).replaceAll(`_`,`/`))},a=e=>{let t=Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``),n=(6-t.length%6)%6,r=`0`.repeat(n).concat(t).matchAll(/.{6}/g);return Array.from(r,e=>Number.parseInt(e[0],16).toString(8).padStart(8,`0`)).join(``).replace(/^0+/,``)},o=e=>{let t=8-(e.length&7)&7,n=`0`.repeat(t).concat(e).matchAll(/.{8}/g),r=Array.from(n,e=>Number.parseInt(e[0],8).toString(16).padStart(6,`0`)).join(``).matchAll(/.{2}/g);return Uint8Array.from(r,e=>Number.parseInt(e[0],16))},s=(e,t)=>[e].includes(t),c=(e,t)=>{if(typeof e!=typeof t)return!1;let n=Object.prototype.toString.call(e);if(n!==Object.prototype.toString.call(t))return!1;if(typeof e==`string`||typeof e==`bigint`||typeof e==`boolean`||typeof e==`symbol`||e==null)return e===t;if(typeof e==`number`)return e!==e&&t!==t||e===t;if(typeof e==`function`)return!1;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!c(e[n],t[n]))return!1;return!0}if(e instanceof Set&&t instanceof Set)return!!c([...e.values()],[...t.values()]);if(e instanceof Map&&t instanceof Map)return!(!c([...e.keys()],[...t.keys()])||!c([...e.values()],[...t.values()]));if(n===`[object Object]`){let n=e,r=t,i=Object.keys(n),a=Object.keys(r);for(let e of i){let t=a.find(t=>t===e);if(t===void 0)return!1;let[i,o]=[n[e],r[t]];if(!c(i,o))return!1}return!0}throw TypeError(`comparing these objects is unavailable: ${e}, ${t}`,{cause:[e,t]})},l=()=>{let e,t;return{promise:new Promise((n,r)=>{e=n,t=r}),resolve:e,reject:t}},ee=e=>new Promise(t=>setTimeout(t,e)),te=e=>Object.prototype.toString.call(e).slice(8,-1),u=e=>(...t)=>()=>e(...t),ne=e=>{let t=[],n=[],r=``,i=!1;for(let a=0;a<e.length;a++){let o=e[a];o===`"`&&(a===0||e[a-1]!==`\\`)?i=!i:o===`,`&&!i?(n.push(r.trim()),r=``):o===`
|
|
2
|
+
`&&!i?(n.push(r.trim()),t.push(n),n=[],r=``):r+=o}return n.push(r.trim()),t.push(n),t},re=async(e,t)=>{let n=new TextEncoder().encode(e),r=await crypto.subtle.digest(t,n);return new Uint8Array(r)},ie=e=>encodeURIComponent(e).replace(/[!'()*]/g,e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`),d=e=>{if(e.includes(`+`))throw URIError("an input string must not include `+`");return decodeURIComponent(e)},f=(e,t)=>{let n=new Blob([e]).stream().pipeThrough(new CompressionStream(t));return new Response(n).bytes()},ae=(e,t)=>{let n=new Blob([e]).stream().pipeThrough(new DecompressionStream(t));return new Response(n).bytes()},p=async(e,t)=>{let n=new Blob([e]).stream().pipeThrough(new CompressionStream(t));return r(await new Response(n).bytes())},m=(e,t)=>{let n=i(e),r=new Blob([n]).stream().pipeThrough(new DecompressionStream(t));return new Response(r).text()},h=(e,t)=>new Promise((n,r)=>{setTimeout(async()=>{try{n(await e())}catch(e){r(e)}},t)}),g=(e,t)=>{if(t<-e.length||t>=e.length)throw RangeError("`index` is out of range");return e.at(t)},_=(e,t)=>{let n=g(e,t);if(n==null)throw TypeError(`value is nullable`);return n},oe=(e,t)=>Math.floor(Math.random()*(t-e)+e),v=(e,t)=>{t<0n&&(t*=-1n);let n=e%t;return n<0n?n+t:n},y=(e,t=!1)=>{if(!Number.isFinite(e))throw RangeError("`length` is not a valid number");if(e<=0)throw RangeError("`length` must be positive");let n=Math.ceil(e/8),r=crypto.getRandomValues(new Uint8Array(n)),i=Array.from(r,e=>e.toString(2).padStart(8,`0`)).join(``).slice(0,e);return t&&(i=i.replace(/^\d/,`1`)),BigInt(`0b`+i)},b=(e,t)=>{if(e>=t)throw RangeError("`min` must be smaller than `max`");let n=t-e,r=n.toString(2).length;return e+(()=>{for(let e=0;e<1e5;e++){let e=y(r);if(e>=x(2n,BigInt(r),n))return e%n}throw Error(`Failed to generate a random bigint`)})()},x=(e,t,n)=>{if(n<1n)throw RangeError("`mod` must be positive");if(t<0n)throw RangeError("`power` must not be negative");if(e=v(e,n),n===1n)return 0n;if(e%n===1n||e%n===0n)return e;if(e===n-1n)return t&1n?n-1n:1n;let r=1n;for(;t>0n;)t&1n&&(r=r*e%n),e=e*e%n,t>>=1n;return r},S=(e,t)=>{if(e===0n&&t===0n)return{x:0n,y:0n,gcd:0n};if(e===0n)return t>0n?{x:0n,y:-1n,gcd:t}:{x:0n,y:1n,gcd:-t};if(t===0n)return e>0n?{x:1n,y:0n,gcd:e}:{x:-1n,y:0n,gcd:-e};let[n,r,i]=[1n,0n,e],[a,o,s]=[0n,-1n,t];for(;;){let e=i/s,t=i-e*s;if(t===0n)break;[n,a]=[a,n-e*a],[r,o]=[o,r-e*o],[i,s]=[s,t]}return s<0n&&(a*=-1n,o*=-1n,s*=-1n),{x:a,y:o,gcd:s}},C=(e,t)=>{if(e>=t)return 1n;let n=BigInt((t-2n).toString(2).length),r=(t-e)/2n;if(n*r<63n){let n=e;for(let r=e+2n;r<t;r+=2n)n*=r;return n}let i=e+r|1n;return C(e,i)*C(i,t)},se=e=>{let t=3n,n=1n,r=1n,i=BigInt(e.toString(2).length)-1n;for(let a=i-1n;a>-1n;--a){let i=(e>>a)+1n|1n;r*=C(t,i),t=i,n*=r}return n},ce=e=>{if(e<0n)throw RangeError(`'n' must be non-negative`);if(e===0n)return 1n;let t=e-BigInt(e.toString(2).match(/1/g)?.length??0);return se(e)<<t},w=(e,t)=>(e>>>(t&31)|e<<(-t&31))>>>0,T=(e,t)=>BigInt.asUintN(64,e>>(t&63n)|e<<(-t&63n)),E=(e,t)=>{if(t<1n||t%2n==0n)throw RangeError("`n` is out of range");for(;e<0n;)e+=t;e%=t;let n=1n;for(;e!==0n;){for(;e%2n==0n;){e/=2n;let r=t%8n;(r===3n||r===5n)&&(n*=-1n)}[e,t]=[t,e],e%4n==3n&&t%4n==3n&&(n*=-1n),e%=t}return t===1n?n:0n},D=e=>{if(e<0n)return!1;if(e===0n)return!0;let t=1n,n=e;for(;t+1n<n;){let r=(t+n)/2n;r*r<e?t=r:n=r}return e===t**2n||e===(t+1n)**2n},O=class{#e;constructor(e){this.#e=e}postMessage=(e,t)=>new Promise((n,r)=>{let i=crypto.randomUUID(),a=e=>{let t=e.data;t.id===i&&(this.#e.removeEventListener(`message`,a),this.#e.removeEventListener(`error`,o),t.success?n(t.value):r(t.error))},o=e=>{this.#e.removeEventListener(`message`,a),this.#e.removeEventListener(`error`,o),r(e.error)};this.#e.addEventListener(`message`,a),this.#e.addEventListener(`error`,o);let s={value:e,id:i};this.#e.postMessage(s,t)})},k=()=>typeof window>`u`&&typeof self<`u`&&`importScripts`in self,A=(e,t)=>{if(!k())throw Error(`this function must be used in Worker`);let n={success:!0,value:e,id:t};self.postMessage(n)},j=(e,t)=>{if(!k())throw Error(`this function must be used in Worker`);let n={success:!1,error:e,id:t};self.postMessage(n)},M=e=>{if(e<=1n)return!1;if(e%2n==0n)return e===2n;let t=e-1n,n=0n;for(;t%2n==0n;)t>>=1n,n+=1n;let[r,i]=[t,n],a=x(2n,r,e);if(a===1n)return!0;for(let t=0n;t<i;t++){if(a===e-1n)return!0;a=a*a%e}return!1},N=e=>{let t=5n,n=E(t,e);for(;n>0n;){if(t=t>0n?t+2n:t-2n,t*=-1n,t===-15n&&D(e))return[0n,0n];n=E(t,e)}return[t,n]},P=(e,t)=>(e&1n)==1n?v(e+t>>1n,t):v(e>>1n,t),F=(e,t,n,r)=>{let i=1n,a=n,o=e.toString(2).slice(1);for(let e of o)[i,a]=[v(i*a,t),P(a*a+r*i*i,t)],e===`1`&&([i,a]=[P(n*i+a,t),P(r*i+n*a,t)]);return[i,a]},I=(e,t,n,r)=>{if(e%2n!=1n)throw RangeError("`n` must be odd");let i=e+1n,a=0n;for(;i%2n==0n;)i>>=1n,a+=1n;let[o,s]=F(i,e,n,t),c=s;if(o===0n)return!0;r=x(r,i,e);for(let t=0n;t<a;t++){if(c===0n)return!0;c=v(c*c-2n*r,e),r=x(r,2n,e)}return!1},L=[2n,3n,5n,7n,11n,13n,17n,19n,23n,29n,31n,37n,41n,43n,47n,53n,59n,61n,67n,71n,73n,79n,83n,89n,97n,101n,103n,107n,109n,113n,127n,131n,137n,139n,149n,151n,157n,163n,167n,173n,179n,181n,191n,193n,197n,199n,211n,223n,227n,229n,233n,239n,241n,251n,257n,263n,269n,271n,277n,281n,283n,293n,307n,311n,313n,317n,331n,337n,347n,349n,353n,359n,367n,373n,379n,383n,389n,397n,401n,409n,419n,421n,431n,433n,439n,443n,449n,457n,461n,463n,467n,479n,487n,491n,499n],R=e=>{if(e<=1n)return!1;if(e%2n==0n)return e===2n;for(let t of L)if(e%t===0n)return e===t;if(!M(e))return!1;let[t,n]=N(e);return n===0n?!1:I(e,t,1n,(1n-t)/4n)},z=(e,t)=>{if(t<2n)throw RangeError("`max` must be 2 or larger");for(let n=0;n<1e5;n++){let n=b(e,t);if(R(n))return n}throw Error(`no primes were found`)},B=(e,t=!1)=>{if(e<2)throw RangeError("`bitLength` must be 2 or larger");for(let n=0;n<1e5;n++){let n=y(e,t);if(R(n))return n}throw Error(`no primes were found`)},V,H=()=>(V||=new O(new Worker(new URL(`/assets/bpsw_worker-nJV3KnVo.js`,``+{}.url),{type:`module`})),V),U=e=>H().postMessage(e),W=`Rational`,G=class e{#e;#t;static name=W;constructor(e,t){t===0n?(this.#t=0n,this.#e=e===0n?0n:e>0n?1n:-1n):t>0n?(this.#e=e,this.#t=t):(this.#e=-e,this.#t=-t),this.#n()}static fromDecimal(t,n=5){if(Number.isNaN(t))return new e(0n,0n);if(Math.abs(t)===1/0)return new e(t>0?1n:-1n,0n);let r=t<0;r&&(t*=-1);let i=BigInt(Math.floor(t)),a=t-Number(i);if(a===0)return new e(r?-i:i,1n);t=1/a;let[o,s]=[1n,i],[c,l]=[0n,1n];for(;`${l}`.length<=n;){let n=BigInt(Math.floor(t)),i=t-Number(n);if([o,s]=[s,n*s+o],[c,l]=[l,n*l+c],i===0)return new e(r?-s:s,l);t=1/i}return new e(r?-o:o,c)}#n(){let{gcd:e}=S(this.#e,this.#t);e!==0n&&(this.#e/=e,this.#t/=e)}minus=()=>new e(-this.#e,this.#t);inverse=()=>new e(this.#t,this.#e);add=t=>{let n=this.#t*t.#t;return new e(this.#e*t.#t+t.#e*this.#t,n)};substr=e=>this.add(e.minus());multiply=t=>{let n=this.#t*t.#t;return new e(this.#e*t.#e,n)};divide=e=>this.multiply(e.inverse());mediant=t=>{let n=this.#t+t.#t;return new e(this.#e+t.#e,n)};toDecimal=()=>Number(this.#e)/Number(this.#t);toString=()=>this.#e===0n&&this.#t===0n?`NaN`:this.#e===0n?`0`:this.#t===0n?this.#e<0n?`-Infinity`:`Infinity`:this.#t===1n?`${this.#e}`:`${this.#e}/${this.#t}`;valueOf=()=>this.toDecimal();toJSON=()=>({type:`Rational`,value:[`0x`+this.#e.toString(16),`0x`+this.#t.toString(16)]});static fromData(t){return new e(BigInt(t.value[0]),BigInt(t.value[1]))}static parse(t){let n=/^\s*(\d+)\s*\/\s*(\d+)\s*$/.exec(t);if(!n)throw Error(`cannot parse`);let r=n.at(1),i=n.at(2);if(!r||!i)throw Error(`cannot parse`);return new e(BigInt(r),BigInt(i))}};Object.defineProperty(G.prototype,Symbol.toStringTag,{value:W});var K=`NamedError`,q=class extends Error{static name=K;errName;constructor(e,t,n){super(t,n),this.errName=e}toJSON=()=>{let e=(()=>{let e=this.cause;if(e==null)return e;let t=e.toString();return t===`[object Object]`?JSON.stringify(e):t})(),{errName:t,message:n,stack:r}=this;return{name:t,message:n,stack:r,cause:e}}};Object.defineProperty(q.prototype,Symbol.toStringTag,{value:K});var J=e=>{if(e===0n)return 64n;let t=0n;for(;e>0n&&!(e&1n);)++t,e>>=1n;return BigInt.asUintN(64,t)},Y=(e,t)=>{let n=0n,r=e&2047n,i=1023n-1n;if(r>0n)return i-=J(r),i;i-=11n;for(let e=0;e<1e5;++e){let e=t();if(e>0n)return i-=J(e),i;if(i-=64n,i<n)return n}throw Error(`loop exceeded limit`)},le=e=>{let t=()=>BigInt.asUintN(64,e()),n=()=>{let e=t(),n=BigInt.asUintN(52,e>>11n),r=n===0n&&e>>63n==1n?Y(e,t)+1n:Y(e,t),{buffer:i}=BigUint64Array.from([r<<52n|n]),a=new Float64Array(i)[0];if(a==null)throw Error(`unexpected`);return a};return()=>{for(let e=0;e<1e5;++e){let e=n();if(e<1)return e}throw Error(`Loop limit exceeded`)}},ue=[9600629759793949339n,15726070495360670683n],de=6364136223846793005n,X=`PCGMinimal`,Z=class{#e;static name=X;constructor(e){if(e&&e[0]!=null&&e[1]!=null){if(this.#e=new BigUint64Array(2),this.#e[0]==null||this.#e[1]==null)throw TypeError(`unexpected`);this.#e[1]=e[1]<<1n|1n,this.#t(),this.#e[0]+=e[0],this.#t()}else this.#e=BigUint64Array.from(ue)}#t(){if(this.#e[0]==null||this.#e[1]==null)throw TypeError(`unexpected`);this.#e[0]=this.#e[0]*de+this.#e[1]}get#n(){if(this.#e[0]==null||this.#e[1]==null)throw TypeError(`unexpected`);let e=this.#e[0],t=Number(e>>59n);return w(Number(BigInt.asUintN(32,(e^e>>18n)>>27n)),t)}getRandU32=()=>(this.#t(),this.#n);getBoundedRandU32=e=>{let t=4294967296;if(e>t)throw RangeError("`bound` exceeded limit (2^32)");if(e<=0)throw RangeError(`'bound' must be positive`);let n=t%e;for(let t=0;t<1e5;++t){let t=this.getRandU32();if(t>=n)return t%e}throw Error(`exceeded loop limit`)};*genRandU32s(e,t){if(e<=0)throw RangeError(`'step' must be positive`);for(let n=0;n<e;n++)yield typeof t==`number`?this.getBoundedRandU32(t):this.getRandU32()}};Object.defineProperty(Z.prototype,Symbol.toStringTag,{value:X});var fe=[13715198867125970446n,3333371893450545919n,5627726498316411518n,8467276975966080893n],Q=`XoshiroMinimal`,$=class{bits=64;#e;static name=Q;constructor(e){if(e&&e[0]!=null&&e[1]!=null&&e[2]!=null&&e[3]!=null){if(this.#e=new BigUint64Array(4),this.#e[0]=e[0],this.#e[1]=e[1],this.#t(),this.#e[2]==null||this.#e[3]==null)throw TypeError(`unexpected`);this.#e[2]+=e[2],this.#e[3]+=e[3]}else this.#e=BigUint64Array.from(fe)}#t(){if(this.#e[0]==null||this.#e[1]==null||this.#e[2]==null||this.#e[3]==null)throw TypeError(`unexpected`);let e=this.#e[1]<<17n;this.#e[2]^=this.#e[0],this.#e[3]^=this.#e[1],this.#e[1]^=this.#e[2],this.#e[0]^=this.#e[3],this.#e[2]^=e,this.#e[3]=T(this.#e[3],45n)}get value(){if(this.#e[0]==null||this.#e[3]==null)throw TypeError(`unexpected`);let e=T(this.#e[0]+this.#e[3],23n)+this.#e[0];return BigInt.asUintN(64,e)}getRandU64=()=>{let e=this.value;return this.#t(),e};getRandU32=()=>{let e=BigInt.asUintN(32,this.getRandU64());return Number(e)};getBoundedRandU64=e=>{let t=1n<<64n;if(e>t)throw RangeError("`bound` exceeded limit");if(e<=0n)throw RangeError("`bound` must be positive");let n=t%e;for(let t=0;t<1e5;++t){let t=this.getRandU64();if(t>=n)return t%e}throw Error(`exceeded loop limit`)};getBoundedRandU32=e=>{if(e>2**32)throw RangeError("`bound` exceeded limit");if(e<=0n)throw RangeError("`bound` must be positive");let t=this.getBoundedRandU64(BigInt(e));return Number(t)};*genRandU64s(e,t){if(e<=0)throw RangeError("`step` must be positive");for(let n=0;n<e;++n)yield t===void 0?this.getRandU64():this.getBoundedRandU64(t)}*genRandU32s(e,t){if(e<=0)throw RangeError("`step` must be positive");for(let n=0;n<e;++n)yield t===void 0?this.getRandU32():this.getBoundedRandU32(t)}};Object.defineProperty($.prototype,Symbol.toStringTag,{value:Q});var pe=e=>{let t=e<0n;t&&(e*=-1n);let n=e.toString(2).length,r=e===1n<<BigInt(n-1)&&!(n%7)&&t,i=Math.floor(n/7)+1;return r?i-1:i};return e.AsyncWorker=O,e.NamedError=q,e.PCGMinimal=Z,e.Rational=G,e.XoshiroMinimal=$,e.bailliePSW=R,e.bailliePSWAsync=U,e.compress=f,e.compressString=p,e.decodeLEB128=e=>{let t=e.length,n=0n;for(let[t,r]of e.entries()){let e=BigInt(r&127);n+=e<<BigInt(7*t)}return BigInt.asIntN(7*t,n)},e.decodeRFC3986URIComponent=d,e.decompress=ae,e.decompressString=m,e.encodeLEB128=e=>{let t=pe(e);e=BigInt.asUintN(t*7,e);let n=new Uint8Array(t);for(let r=0;r<t-1;++r)n[r]=Number(e&127n)|128,e>>=7n;let r=Number(e&127n);return n[t-1]=r,e>>=7n,n},e.encodeRFC3986URIComponent=ie,e.exEuclidean=S,e.factorial=ce,e.floatRng=le,e.fromBase64=n,e.fromBase64URL=i,e.fromOct=o,e.getHash=re,e.getRandBIByBitLength=y,e.getRandBIByRange=b,e.getRandPrimeByBitLength=B,e.getRandPrimeByRange=z,e.getRndInt=oe,e.getStringTag=te,e.isDeepStrictEqual=c,e.isSquare=D,e.jacobiSymbol=E,e.lazify=u,e.modPow=x,e.nullableStrictAt=g,e.parseCSV=ne,e.postFailed=j,e.postSuccess=A,e.residue=v,e.rot32=w,e.rot64=T,e.sameValueZero=s,e.setTimeoutPromise=h,e.sleep=ee,e.strictAt=_,e.toBase64=t,e.toBase64URL=r,e.toOct=a,e.withResolvers=l,e})({});
|
package/dist/fraction.d.ts
CHANGED
|
@@ -22,55 +22,55 @@ export declare class Rational {
|
|
|
22
22
|
* returns a fraction multiplied by -1
|
|
23
23
|
* @returns
|
|
24
24
|
*/
|
|
25
|
-
minus()
|
|
25
|
+
readonly minus: () => Rational;
|
|
26
26
|
/**
|
|
27
27
|
* returns inverse of this fraction
|
|
28
28
|
* @returns
|
|
29
29
|
*/
|
|
30
|
-
inverse()
|
|
30
|
+
readonly inverse: () => Rational;
|
|
31
31
|
/**
|
|
32
32
|
* returns `this + right`
|
|
33
33
|
* @param right
|
|
34
34
|
* @returns
|
|
35
35
|
*/
|
|
36
|
-
add(right: Rational)
|
|
36
|
+
readonly add: (right: Rational) => Rational;
|
|
37
37
|
/**
|
|
38
38
|
* returns `this - right`
|
|
39
39
|
* @param right
|
|
40
40
|
* @returns
|
|
41
41
|
*/
|
|
42
|
-
substr(right: Rational)
|
|
42
|
+
readonly substr: (right: Rational) => Rational;
|
|
43
43
|
/**
|
|
44
44
|
* returns `this * right`
|
|
45
45
|
* @param right
|
|
46
46
|
* @returns
|
|
47
47
|
*/
|
|
48
|
-
multiply(right: Rational)
|
|
48
|
+
readonly multiply: (right: Rational) => Rational;
|
|
49
49
|
/**
|
|
50
50
|
* returns `this / right`
|
|
51
51
|
* @param right
|
|
52
52
|
* @returns
|
|
53
53
|
*/
|
|
54
|
-
divide(right: Rational)
|
|
54
|
+
readonly divide: (right: Rational) => Rational;
|
|
55
55
|
/**
|
|
56
56
|
* returns mediant
|
|
57
57
|
* @param this `a / b`
|
|
58
58
|
* @param right `c / d`
|
|
59
59
|
* @returns `(a + c) / (b + d)`
|
|
60
60
|
*/
|
|
61
|
-
mediant(right: Rational)
|
|
61
|
+
readonly mediant: (right: Rational) => Rational;
|
|
62
62
|
/**
|
|
63
63
|
* returns `number` type decimal
|
|
64
64
|
* @returns decimal
|
|
65
65
|
*/
|
|
66
|
-
toDecimal()
|
|
66
|
+
readonly toDecimal: () => number;
|
|
67
67
|
/**
|
|
68
68
|
* returns `'numerator/denominator'`
|
|
69
69
|
* @returns string form
|
|
70
70
|
*/
|
|
71
|
-
toString()
|
|
72
|
-
valueOf()
|
|
73
|
-
toJSON()
|
|
71
|
+
readonly toString: () => string;
|
|
72
|
+
readonly valueOf: () => number;
|
|
73
|
+
readonly toJSON: () => RationalData;
|
|
74
74
|
/**
|
|
75
75
|
* makes instance from RationalData
|
|
76
76
|
* @param data
|
package/dist/leb128.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const encodeLEB128: (bigint: bigint) => Uint8Array<ArrayBuffer>;
|
|
2
|
-
export declare const decodeLEB128: (
|
|
2
|
+
export declare const decodeLEB128: (LEB128: Uint8Array<ArrayBuffer>) => bigint;
|
package/dist/main.d.ts
CHANGED
package/dist/named_error.d.ts
CHANGED
|
@@ -7,11 +7,11 @@ declare class NamedError<EName extends string> extends Error {
|
|
|
7
7
|
static readonly name = "NamedError";
|
|
8
8
|
readonly errName: EName;
|
|
9
9
|
constructor(errName: EName, message: string, options?: ErrorOptions);
|
|
10
|
-
toJSON()
|
|
10
|
+
readonly toJSON: () => {
|
|
11
11
|
name: EName;
|
|
12
12
|
message: string;
|
|
13
13
|
stack: string | undefined;
|
|
14
|
-
cause: string |
|
|
14
|
+
cause: string | null | undefined;
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
17
|
export { NamedError };
|
package/dist/pcg_minimal.d.ts
CHANGED
|
@@ -24,11 +24,11 @@ export declare class PCGMinimal {
|
|
|
24
24
|
*
|
|
25
25
|
* @returns a random 32-bit unsigned integer
|
|
26
26
|
*/
|
|
27
|
-
getRandU32()
|
|
27
|
+
readonly getRandU32: () => number;
|
|
28
28
|
/**
|
|
29
29
|
* @returns a random 32-bit unsigned integer less than `bound`
|
|
30
30
|
*/
|
|
31
|
-
getBoundedRandU32(bound: number)
|
|
31
|
+
readonly getBoundedRandU32: (bound: number) => number;
|
|
32
32
|
/**
|
|
33
33
|
*
|
|
34
34
|
* @param step the number of needed random integers
|
package/dist/types.d.ts
CHANGED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export type UUID = ReturnType<typeof crypto.randomUUID>;
|
|
2
|
-
interface WorkerSuccessedResult<T> {
|
|
3
|
-
readonly id: UUID;
|
|
4
|
-
success: true;
|
|
5
|
-
value: T;
|
|
6
|
-
}
|
|
7
|
-
interface WorkerFailedResult<E = unknown> {
|
|
8
|
-
readonly id: UUID;
|
|
9
|
-
success: false;
|
|
10
|
-
error: E;
|
|
11
|
-
}
|
|
12
|
-
export type WorkerResult<T, E = unknown> = WorkerSuccessedResult<T> | WorkerFailedResult<E>;
|
|
13
|
-
export interface WorkerMessage<T> {
|
|
14
|
-
readonly id: UUID;
|
|
15
|
-
value: T;
|
|
16
|
-
}
|
|
17
|
-
export {};
|
|
@@ -22,10 +22,10 @@ export declare class XoshiroMinimal {
|
|
|
22
22
|
*/
|
|
23
23
|
constructor(seed?: BigUint64Array<ArrayBuffer>);
|
|
24
24
|
get value(): bigint;
|
|
25
|
-
getRandU64()
|
|
26
|
-
getRandU32()
|
|
27
|
-
getBoundedRandU64(bound: bigint)
|
|
28
|
-
getBoundedRandU32(bound: number)
|
|
25
|
+
readonly getRandU64: () => bigint;
|
|
26
|
+
readonly getRandU32: () => number;
|
|
27
|
+
readonly getBoundedRandU64: (bound: bigint) => bigint;
|
|
28
|
+
readonly getBoundedRandU32: (bound: number) => number;
|
|
29
29
|
genRandU64s(step: number, bound?: bigint): Generator<bigint, void, unknown>;
|
|
30
30
|
genRandU32s(step: number, bound?: number): Generator<number, void, unknown>;
|
|
31
31
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tktb-tess/util-fns",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.2",
|
|
4
4
|
"description": "Utility functions for personal use",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"@types/node": "^25.5.2",
|
|
30
30
|
"typescript": "^6.0.2",
|
|
31
31
|
"unplugin-dts": "1.0.0-beta.6",
|
|
32
|
-
"vite": "^8.0.
|
|
33
|
-
"vitest": "^4.1.
|
|
32
|
+
"vite": "^8.0.8",
|
|
33
|
+
"vitest": "^4.1.4"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
36
|
"dev": "vite",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
(function(){let e=(e,t)=>{t<0n&&(t*=-1n);let n=e%t;return n<0n?n+t:n},t=(t,n,r)=>{if(r<1n)throw RangeError("`mod` must be positive");if(n<0n)throw RangeError("`power` must not be negative");if(t=e(t,r),r===1n)return 0n;if(t%r===1n||t%r===0n)return t;if(t===r-1n)return n&1n?r-1n:1n;let i=1n;for(;n>0n;)n&1n&&(i=i*t%r),t=t*t%r,n>>=1n;return i},n=(e,t)=>{if(t<1n||t%2n==0n)throw RangeError("`n` is out of range");for(;e<0n;)e+=t;e%=t;let n=1n;for(;e!==0n;){for(;e%2n==0n;){e/=2n;let r=t%8n;(r===3n||r===5n)&&(n*=-1n)}[e,t]=[t,e],e%4n==3n&&t%4n==3n&&(n*=-1n),e%=t}return t===1n?n:0n},r=e=>{if(e<0n)return!1;if(e===0n)return!0;let t=1n,n=e;for(;t+1n<n;){let r=(t+n)/2n;r*r<e?t=r:n=r}return e===t**2n||e===(t+1n)**2n},i=e=>{if(e<=1n)return!1;if(e%2n==0n)return e===2n;let n=e-1n,r=0n;for(;n%2n==0n;)n>>=1n,r+=1n;let[i,a]=[n,r],o=t(2n,i,e);if(o===1n)return!0;for(let t=0n;t<a;t++){if(o===e-1n)return!0;o=o*o%e}return!1},a=e=>{let t=5n,i=n(t,e);for(;i>0n;){if(t=t>0n?t+2n:t-2n,t*=-1n,t===-15n&&r(e))return[0n,0n];i=n(t,e)}return[t,i]},o=(t,n)=>(t&1n)==1n?e(t+n>>1n,n):e(t>>1n,n),s=(t,n,r,i)=>{let a=1n,s=r,c=t.toString(2).slice(1);for(let t of c)[a,s]=[e(a*s,n),o(s*s+i*a*a,n)],t===`1`&&([a,s]=[o(r*a+s,n),o(i*a+r*s,n)]);return[a,s]},c=(n,r,i,a)=>{if(n%2n!=1n)throw RangeError("`n` must be odd");let o=n+1n,c=0n;for(;o%2n==0n;)o>>=1n,c+=1n;let[l,u]=s(o,n,i,r),d=u;if(l===0n)return!0;a=t(a,o,n);for(let r=0n;r<c;r++){if(d===0n)return!0;d=e(d*d-2n*a,n),a=t(a,2n,n)}return!1},l=e=>{if(e<=1n)return!1;if(e%2n==0n)return e===2n;for(let t of[2n,3n,5n,7n,11n,13n,17n,19n,23n,29n,31n,37n,41n,43n,47n,53n,59n,61n,67n,71n,73n,79n,83n,89n,97n,101n,103n,107n,109n,113n,127n,131n,137n,139n,149n,151n,157n,163n,167n,173n,179n,181n,191n,193n,197n,199n,211n,223n,227n,229n,233n,239n,241n,251n,257n,263n,269n,271n,277n,281n,283n,293n,307n,311n,313n,317n,331n,337n,347n,349n,353n,359n,367n,373n,379n,383n,389n,397n,401n,409n,419n,421n,431n,433n,439n,443n,449n,457n,461n,463n,467n,479n,487n,491n,499n])if(e%t===0n)return e===t;if(!i(e))return!1;let[t,n]=a(e);return n===0n?!1:c(e,t,1n,(1n-t)/4n)};globalThis.onmessage=e=>{let t=e.data;try{let e={success:!0,value:l(t.value),id:t.id};postMessage(e)}catch(e){let n={success:!1,error:e,id:t.id};postMessage(n)}}})();
|
package/dist/worker_stream.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export declare class WorkerStream<TPost = unknown, TRecv = unknown> extends ReadableStream<TRecv> {
|
|
2
|
-
#private;
|
|
3
|
-
readonly close: () => void;
|
|
4
|
-
static readonly name = "WorkerStream";
|
|
5
|
-
constructor(worker: Worker, strategy?: CountQueuingStrategy);
|
|
6
|
-
postMessage: (message: TPost, options?: StructuredSerializeOptions) => void;
|
|
7
|
-
}
|