Math.Round(x) rounds imprecisely under Fable 5.26.0
Los mantenedores suelen responder en 1 día
Ya se ha fusionado un pull request relacionado.
- #5254 de @MangelMaxime — fusionado
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 62/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- javascript
- Área
- compilers
Línea de trabajo
The bug is in the round helper of fable-library-js (Util.round), which uses toFixed(8) and an epsilon tie check; the reproduction is the Math.Round loop over 2.500000001 and 3.4999999999 in the issue. Start by reading that helper and checking whether the same logic is mirrored in other Fable targets. Done when both values round to 3 and Math.Round(x, digits) matches .NET behaviour, with a regression test added.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Math.Round(double) calls a value a tie when its fraction is within 1e-8 of 0.5, so values near a half round the wrong way. That way 2.500000001 rounds down to 2 and 3.4999999999 rounds up to 4 under Fable 5.26.0, instead of 3 for both cases.
To reproduce this issue
open System
for x in [ 2.500000001; 3.4999999999 ] do
printfn "%s" (string (Math.Round x))
fable-library-js’s Util.round reads the value through toFixed(8) and calls it a tie when the fraction is within 1e-8 of 0.5
const n = +(digits ? value * m : value).toFixed(8);
...
const r = (f > 0.5 - e && f < 0.5 + e) ? ((i % 2 === 0) ? i : i + 1) : Math.round(n);
Math.Round(double) works on the exact value and a tie is a fraction of exactly one half.
Suggested fix that would be exact.
const t = Math.trunc(x), f = Math.abs(x - t);
return f > 0.5 ? t + Math.sign(x) : f < 0.5 ? t : (t % 2 === 0 ? t : t + Math.sign(x));
For Math.Round(x, digits) the same applies after scaling by 10^digits, as .NET does.
- Lenguaje dominante
- F#
- Estrellas
- 3.2k
- Forks
- 335
- Merge medio
- 19 h 39 min
- PR fusionados (30 d)
- 158
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Sin guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de fable-compiler/Fable
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
fable-compiler/Fable#5280 ·
Los mantenedores suelen responder en 1 día
-
agentic-workflows automation repo-assist
Dificultad 1/5 Menos de una hora Aptitud para principiantes 78/100
fable-compiler/Fable#4531 ·
Los mantenedores suelen responder en 1 día
-
agentic-workflows automation repo-assist
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
fable-compiler/Fable#4522 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
fable-compiler/Fable#5286 ·
Los mantenedores suelen responder en 1 día
-
for loop bound still differs from .NET for reassigned mutable arraysPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 36/100
fable-compiler/Fable#5285 ·
Los mantenedores suelen responder en 1 día
Todos los issues de fable-compiler/Fable
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
rubys/roundhouse#1950 ·
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
tree-sitter/tree-sitter-cpp#381 ·
-
[P2] Interpreter: Array.prototype.findLastIndex starts at the wrong index for long array-likesAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 83/100
Los mantenedores suelen responder en 1 día
-
new issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
llvm/llvm-project#240065 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
Los mantenedores suelen responder en 2 días