Median aggregation overflows for large finite middle values

未关闭 适合新手
#6,654 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
68/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
typescript
领域
data

调研方向

从 packages/table-core/src/features/row-aggregation/aggregationFns.ts 中的中位数计算以及 issue 描述的针对性 Vitest 回归测试入手。检查计算如何处理较大的有限值对,以及次正规数、零、NaN 和无穷大输入。溢出情况返回有限中位数,且列出的对照情况保持现有行为,即为完成。

由索引模型根据 Issue 内容生成。

描述

TanStack Table version

@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'

const context = 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

Source of the current median calculation.

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.

主要语言
TypeScript
星标
28.5k
派生
3.6k
平均合并
18 小时 5 分钟
30 天内合并 PR
12

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

TanStack/table 的其他 Issue

查看 TanStack/table 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。