sprintf and printfn float formats %e, %g, and %f differ from .NET

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

Línea de trabajo

Start by locating Fable's implementation of sprintf and printfn float formatting, then compare its %e, %g, and %f behavior with the .NET expectations and repro cases in the issue. Run the relevant formatting tests and add coverage for the listed edge cases, including precision zero and negative zero. Done when the outputs match the expected results and %.0g no longer throws.

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

Descripción

Description

In Fable 5.27.0 targeting JavaScript/TypeScript, sprintf/printfn float format specifiers %e/%E, %g/%G, and %f diverge from .NET (String.Format in the same runtime already follows the .NET rules), and %.0g throws a RangeError (regression from 5.26.0).

Per the F# plaintext formatting reference, %e/%E defaults to precision 6 with a 3-digit exponent and matching case, %g/%G strips trailing zeros (treating precision 0 as default), %f never switches to exponential notation, and negative zero keeps its - sign.

Repro code
for s in [
    sprintf "%e" 3.0
    sprintf "%E" 3.0
    sprintf "%.2g" 1e301
    sprintf "%.8g" 0.0
    sprintf "%.4e" -0.0
    sprintf "%f" -0.0
    sprintf "%.0f" 1e21
    sprintf "%.0g" 2.5
] do
    printfn "%s" s
Expected and actual results

Expected (.NET 10):

3.000000e+000
3.000000E+000
1e+301
0
-0.0000e+000
-0.000000
1000000000000000000000
2.5

Actual under Fable 5.27.0 (Node.js v24.14.1): the first seven lines print 3e+0, 3e+0, 1.0e+301, 0.0000000, 0.0000e+0, 0.000000, and 1e+21, and sprintf "%.0g" 2.5 throws RangeError: toPrecision() argument must be between 1 and 100.

Related information
  • Fable version: 5.27.0
  • Operating system: macOS 26.3 (Node.js v24.14.1, .NET 10)

Credit: https://ucsbplse.github.io/

Lenguaje dominante
F#
Estrellas
3.2k
Forks
335
Merge medio
19 h 39 min
PR fusionados (30 d)
158

Preparar el entorno

Abrir en Codespaces

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

  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 fable-compiler/Fable

Todos los issues de fable-compiler/Fable

Issues similares

Más issues de Backend & API Design

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.