Skip to content

Commit 11c16b4

Browse files
committed
fix: WasmAggregateOperator AVG precision loss for bigint sums > 2^53
Number(bigSum) / count loses precision for sums exceeding 2^53. Use bigIntAvg() helper (BigInt division + remainder) matching the fix already applied to window aggregates and partial-agg.
1 parent 4412fa9 commit 11c16b4

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

src/operators.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2109,7 +2109,7 @@ export class WasmAggregateOperator implements Operator {
21092109
const hasBig = a.bigSum !== undefined || a.bigMin !== undefined || a.bigMax !== undefined;
21102110
switch (agg.fn) {
21112111
case "sum": row[alias] = a.count === 0 ? null : (hasBig ? a.bigSum! : a.sum); break;
2112-
case "avg": row[alias] = a.count === 0 ? null : (hasBig ? Number(a.bigSum!) / a.count : a.sum / a.count); break;
2112+
case "avg": row[alias] = a.count === 0 ? null : (hasBig ? bigIntAvg(a.bigSum!, a.count) : a.sum / a.count); break;
21132113
case "min": row[alias] = a.count === 0 ? null : (a.bigMin !== undefined ? a.bigMin : a.min); break;
21142114
case "max": row[alias] = a.count === 0 ? null : (a.bigMax !== undefined ? a.bigMax : a.max); break;
21152115
case "count": row[alias] = a.count; break;

0 commit comments

Comments
 (0)