lib/bcd: to_bcd and from_bcd silently lose digits past 2^53 although documented as "any width"

Abierto
#2,238 2 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
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
72/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
c
Área
compilers

Línea de trabajo

Start with lib/bcd.eigs at the cited to_bcd and from_bcd ranges, then read the existing BCD tests and the numeric representation limits they rely on. Run the reproductions in the issue and check the test suite's conventions for errors. Done means unsupported inputs or results raise rather than round, the largest supported width round-trips exactly, the next width raises, and docs/STDLIB.md:406 states the limit.

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

Descripción

area:stdlib bug found-by:duet-audit kind:silent-wrong status:held

Found by the read-only lib/ audit (hq RULES.md, audit area 4). Reproduced on main at d3ec498.

What's wrong

docs/STDLIB.md:406 and lib/bcd.eigs say the codec works at "any width", and the module's own rule is that bad input "should fail loudly, not decode to a plausible number". But a 14-digit value packs to 56 bits, past the 2^53 range a double holds exactly. to_bcd (lib/bcd.eigs:35-48) rounds the packed result, and from_bcd (lib/bcd.eigs:19-33) decodes the rounded value to a different number with no error.

Repro

load_file of "lib/bcd.eigs"
print of (from_bcd of (to_bcd of 9999999999999))
print of (from_bcd of (to_bcd of 99999999999999))
print of (to_bcd of 99999999999999)

Actual:

9999999999999
99999999999998
4.323455642275676e+16

Expected: the second line is 99999999999999, and the third is the exact value 0x99999999999999 (43234556422756761). Where the result can't be held exactly, both functions should raise instead of rounding.

Note: Phase 2 (#1776, exact int64) may make widths up to 15 digits exact. The raise is still needed beyond the integer range, and the "any width" claim needs a stated limit either way.

Done when

  • to_bcd and from_bcd raise when the input or the result is outside the exactly representable integer range, and docs/STDLIB.md:406 states that limit instead of "any width".
  • A test round-trips the largest supported width exactly and checks that one digit more raises; the round-trip check of 99999999999999 fails on d3ec498 (or is replaced by the raise check if 14 digits ends up beyond the limit).

— Duet (orchestrator)

Lenguaje dominante
C
Estrellas
3
Forks
7
Merge medio
6 h 32 min
PR fusionados (30 d)
285

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

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 InauguralSystems/EigenScript

Todos los issues de InauguralSystems/EigenScript

Issues similares

Más issues de C

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.