You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Median aggregation overflows for large finite middle values #6654
@tanstack/table-core 9.3.1, main at c14e0221b1e656c7bb35e7b3d4cdf188719a3599.
Framework/Library version
Framework-independent aggregation API; reproduced with Node 24.19.0.
Describe the bug and the steps to reproduce it
The even-length median adds the two middle values before dividing by two. That intermediate addition can overflow even when the median is finite and representable.
For example, the median of [Number.MAX_VALUE, Number.MAX_VALUE] is Number.MAX_VALUE, but the current implementation returns Infinity. The negative equivalent returns -Infinity. Unequal large finite pairs have the same issue.
The fix should also preserve tiny/subnormal results: always dividing both operands first would turn the median of [Number.MIN_VALUE, Number.MIN_VALUE] into zero. The existing zero, NaN and infinity behavior should remain unchanged.
Your Minimal, Reproducible Example
Run this with Node 24 from a checkout; this source module only has type imports and needs no framework setup:
import{aggregationFn_median}from'./packages/table-core/src/features/row-aggregation/aggregationFns.ts'constcontext=values=>({rows: values.map(value=>({ value })),getValue: row=>row.value,})console.log(aggregationFn_median.aggregate(context([Number.MAX_VALUE,Number.MAX_VALUE,])))// Infinity; expected Number.MAX_VALUE
Four focused Vitest overflow regressions fail on main, while six controls pass (opposite signs, subnormal values, ordinary numbers, signed zero and non-finite inputs).
Do you intend to try to help solve this bug with your own PR?
Yes. I am preparing a small fallback for intermediate overflow and will complete the repository's required checks before opening a PR.
Hi! I'd like to work on this. Plan: in the even-length median, average the two middle values without overflowing (fall back to a / 2 + b / 2 only when a + b isn't finite, so subnormal results like [Number.MIN_VALUE, Number.MIN_VALUE] stay exact), and add tests for the large, negative, tiny, zero, NaN and infinity cases. Does that sound good?
Hi! I'd claimed this earlier, but I see @EnesKartal has already opened #6655 with a fix, so I'll step back to avoid duplicate work. Happy to help review or test if useful!
Activity
monishpatalay commentedon Nov 7, 2026
Hi! I'd like to work on this. Plan: in the even-length median, average the two middle values without overflowing (fall back to
a / 2 + b / 2only whena + bisn't finite, so subnormal results like[Number.MIN_VALUE, Number.MIN_VALUE]stay exact), and add tests for the large, negative, tiny, zero, NaN and infinity cases. Does that sound good?monishpatalay commentedon Nov 8, 2026
Hi! I'd claimed this earlier, but I see @EnesKartal has already opened #6655 with a fix, so I'll step back to avoid duplicate work. Happy to help review or test if useful!