|
| 1 | +import Decimal from "decimal.js" |
| 2 | + |
| 3 | +export function decimalchildwork(piwei, threadall, threadid) { |
| 4 | + const precision = piwei |
| 5 | + Decimal.set({ precision: precision }) |
| 6 | + var p = new Decimal(0) |
| 7 | + var a = new Decimal(1) |
| 8 | + var h = 1 |
| 9 | + var x = new Decimal(0) |
| 10 | + var fu = 1 |
| 11 | + var t = new Decimal(1) |
| 12 | + for (var i = 0, len = threadid; i < len; i++) { |
| 13 | + fu = -1 * fu |
| 14 | + a = Decimal.mul(a, 1024) |
| 15 | + x = x.plus(1) |
| 16 | + } |
| 17 | + while (Decimal.abs(t).cmp(new Decimal("1e-" + precision)) >= 0) { |
| 18 | + t = Decimal.mul(h, fu) |
| 19 | + |
| 20 | + .mul( |
| 21 | + Decimal.div(-(2 ** 5), Decimal.mul(4, x).plus(1)) |
| 22 | + .plus(Decimal.div(-1, Decimal.mul(4, x).plus(3))) |
| 23 | + .plus(Decimal.div(2 ** 8, Decimal.mul(10, x).plus(1))) |
| 24 | + .plus(Decimal.div(-(2 ** 6), Decimal.mul(10, x).plus(3))) |
| 25 | + .plus(Decimal.div(-(2 ** 2), Decimal.mul(10, x).plus(5))) |
| 26 | + .plus(Decimal.div(-(2 ** 2), Decimal.mul(10, x).plus(7))) |
| 27 | + .plus(Decimal.div(1, Decimal.mul(10, x).plus(9))) |
| 28 | + ) |
| 29 | + .div(Decimal.mul(2 ** 6, a)) |
| 30 | + |
| 31 | + p = Decimal.add(p, t) |
| 32 | + if (Decimal.abs(t).cmp(new Decimal("1e-" + precision)) <= 0) break |
| 33 | + |
| 34 | + for (var i = 0, len = threadall; i < len; i++) { |
| 35 | + fu = -1 * fu |
| 36 | + a = Decimal.mul(a, 1024) |
| 37 | + x = x.plus(1) |
| 38 | + } |
| 39 | + } |
| 40 | + x = x.plus(1) |
| 41 | + return [String(p), String(x)] |
| 42 | +} |
0 commit comments