script = {
const blob = new Blob([`
importScripts("${await require.resolve("decimal.js-light@2/decimal.min.js")}");
const precision = 1000;
const D = Decimal.clone({precision: precision + 4});
const one = D(1), four = D(4);
function* arctan(x) {
const x2 = x.times(x);
let k = 1, y = x;
while (true) {
yield y = y.minus((x = x.times(x2)).div(k += 2));
yield y = y.plus((x = x.times(x2)).div(k += 2));
}
}
function* pi() {
const a = arctan(one.div(5));
const b = arctan(one.div(239));
let y0, y1 = one;
do yield y0 = y1, y1 = four.times(four.times(a.next().value).minus(b.next().value));
while (!y1.equals(y0));
}
for (const p of pi()) {
postMessage(p.toFixed(precision));
}
close();
`], {type: "text/javascript"});
const script = URL.createObjectURL(blob);
invalidation.then(() => URL.revokeObjectURL(script));
return script;
}