Median aggregation overflows for large finite middle values

Aberta Para iniciantes
#6,654 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
2/5
Tempo estimado
1-3 horas
Facilidade para iniciantes
68/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
typescript
Domínio
data

Direção de pesquisa

Comece pelo cálculo da mediana em packages/table-core/src/features/row-aggregation/aggregationFns.ts e pelos testes de regressão focados do Vitest descritos na issue. Verifique como o cálculo lida com pares de valores finitos grandes junto com entradas subnormais, zero, NaN e infinito. O trabalho estará concluído quando os casos de overflow retornarem medianas finitas e os controles listados mantiverem o comportamento atual.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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.

Linguagem predominante
TypeScript
Estrelas
28.5k
Forks
3.6k
Merge médio
18h 5min
PRs com merge (30d)
12

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de TanStack/table

Todas as issues de TanStack/table

Issues semelhantes

Mais issues de TypeScript

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.