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

未關閉
#175 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
4/5
預估耗時
3-5 天
新手友好度
56/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
rust
領域
cli

研究方向

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.

由索引模型根據 Issue 內容生成。

描述

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.

主要語言
Rust
星號
31
分支
13
平均合併
23 小時 42 分鐘
30 天內合併 PR
29

環境準備

這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

uutils/awk 的其他 Issue

查看 uutils/awk 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。