fix(est): match project costs and stored formulas

This commit is contained in:
2026-11-05 07:12:08 +09:00
parent 1856aa897d
commit d922ad13f3
19 changed files with 569 additions and 150 deletions
+9 -2
View File
@@ -26,7 +26,12 @@ const EstMath = (() => {
}
function floating(value, digits = 0, method = 2) {
const k = 10 ** digits;
return mode((value + Math.sign(value) * 2e-10) * k, method) / k;
// The original keeps x87 extended intermediates. Account for one binary64
// rounding unit before truncation so exact decimal boundaries survive JS.
const scaled = value * k;
return (
mode(scaled + Math.sign(value) * (2e-10 * k + Number.EPSILON * Math.abs(scaled)), method) / k
);
}
function precision(row, fallback = 0) {
return num(row.DigetIndex)
@@ -63,7 +68,9 @@ const EstMath = (() => {
const result = Object.fromEntries(
components.map((key) => [
key,
floating(rows.filter(predicate).reduce((n, row) => n + num(row[key]), 0)),
floating(
rows.filter(predicate).reduce((n, row) => n + even(num(row[key]) * 10000), 0) / 10000,
),
]),
);
result.TC = sum(result);