Median aggregation overflows for large finite middle values

Abierto Apto para principiantes
#6,654 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
68/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
typescript
Área
data

Línea de trabajo

Empieza por el cálculo de la mediana en packages/table-core/src/features/row-aggregation/aggregationFns.ts y las pruebas de regresión específicas de Vitest descritas en la issue. Comprueba cómo maneja el cálculo los pares de valores finitos grandes junto con entradas subnormales, cero, NaN e infinito. Se considerará terminado cuando los casos de desbordamiento devuelvan medianas finitas y los controles enumerados conserven su comportamiento actual.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
TypeScript
Estrellas
28.5k
Forks
3.6k
Merge medio
18 h 5 min
PR fusionados (30 d)
12

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de TanStack/table

Todos los issues de TanStack/table

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.