awk: numbers are printed with full precision, OFMT and CONVFMT are ignored

Aperta
#175 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à
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
56/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust
Ambito
cli

Direzione di ricerca

Start by tracing how numeric values are formatted for print and converted to strings during concatenation; the issue does not name implementation files, so locate those paths in the Rust source. Use the included print_uses_ofmt_and_concat_uses_convfmt test case as the first check, then compare behavior with the stated GNU awk reproduction. Done means print honors OFMT, other number-to-string conversions honor CONVFMT, and the shown test passes.

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

Descrizione

bug gnu-compat

Non-integer numbers are converted to strings with Rust's shortest round-trip
representation. POSIX awk uses OFMT (default %.6g) for print and
CONVFMT (default %.6g) for every other number-to-string conversion
(concatenation, array subscripts, ...). So print 1/3 gives
0.3333333333333333 instead of 0.333333, and array keys built from
non-integer numbers differ.

Reproduction

Rust (incorrect)

$ ./target/release/awk 'BEGIN { x = 1 / 3; print x; y = x ""; print y; OFMT = "%.2f"; print 3.14159 }'
0.3333333333333333
0.3333333333333333
3.14159

GNU (correct)

$ gawk 'BEGIN { x = 1 / 3; print x; y = x ""; print y; OFMT = "%.2f"; print 3.14159 }'
0.333333
0.333333
3.14

Test

#[test]
fn print_uses_ofmt_and_concat_uses_convfmt() {
    ucmd()
        .arg("BEGIN { v = 2 / 7; print v; print v \"\"; OFMT = \"%.3f\"; print v; print v \"\" }")
        .succeeds()
        .stdout_only("0.285714\n0.285714\n0.286\n0.285714\n");
}

Exposed by the GNU awk test suite: divzero2, getnr2tb, and many tests that
are now stopped earlier by printf.

Lingua principale
Rust
Stelle
31
Fork
13
Merge medio
23h 42m
PR unite (30g)
29

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

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 uutils/awk

Tutte le issue di uutils/awk

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.