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

Aberta
#175 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
4/5
Tempo estimado
3-5 dias
Facilidade para iniciantes
56/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
rust
Domínio
cli

Direção de pesquisa

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.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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.

Linguagem predominante
Rust
Estrelas
31
Forks
13
Merge médio
23h 42min
PRs com merge (30d)
29

Preparar o ambiente

Este projeto não oferece contêiner de desenvolvimento, Dockerfile nem guia de contribuição, então a configuração fica por sua conta: comece pelo README e veja nosso guia da primeira contribuição para os passos gerais.

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de uutils/awk

Todas as issues de uutils/awk

Issues semelhantes

Mais issues de Rust

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.