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

Aperta
#5,281 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
68/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
javascript, typescript
Ambito
backend

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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/

Lingua principale
F#
Stelle
3.2k
Fork
335
Merge medio
18h 57m
PR unite (30g)
154

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

  • Nessun Dockerfile né file Docker Compose
  • Nessun modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di fable-compiler/Fable

Tutte le issue di fable-compiler/Fable

Issue simili

Altre issue su Backend & API Design

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.