Median aggregation overflows for large finite middle values

オープン 初心者向け
#6,654 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
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分
マージ済み PR(30日)
12

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

TanStack/table のほかの issue

TanStack/table の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。