Skip to content

#1488 borrow uutils algorithms - #1575

Merged
caomengxuan666 merged 3 commits into
mainfrom
rust2/borrow-algo
Nov 12, 2026
Merged

caomengxuan666 merged 3 commits into
mainfrom
rust2/borrow-algo

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Borrow-algo action items from the uutils audit (DOCS/2.0-uutils-audit.md §4.1/§4.2, PR #1562): seq exact fixed-point decimal stepping and numfmt --field line reassembly.

seq — exact fixed-point stepping

  • Root cause: the float path stepped in f64 where GNU uses 80-bit long double (seq.c print_numbers, lines 300-364) — >17-significant-digit decimal operands rounded at parse, and sub-f64-ulp steps looped forever. Audit case seq 0.9999999999999999999 1.0000000000000000002 printed 1.0000000000000000000 instead of GNU's 0.9999999999999999999.
  • Fix (std-only, no bigdecimal): operands parse as (i128 mantissa, decimal scale) pairs, the loop steps on the common 10^-scale grid, and output formats from the scaled integers only. seq.c's rounding fixup (lines 340-356) is dead in the exact domain: the value just past LAST sits on the 10^-prec grid, so its rendering never reparses to LAST. A parity guard admits only magnitudes below the long-double 64-bit mantissa grid (< 2^64 units of 10^-prec over first/last/|last-first|) — probed boundary: 0.9999999999999999999 is admitted, 0.99999999999999999999 (GNU long double parses to 1.0) stays on the float path. The scientific-integer fast attempt renders endpoints from the exact mantissa (GNU prints "%0.Lf" of the long double, lines 686-695): seq 1e23 1e23 was 99999999999999991611392, now 100000000000000000000000.
  • Also fixes a pre-existing hang: seq 0.9999999999999999999 0.0000000000000000001 1.0000000000000000002 looped forever printing 1.0000000000000000000.

numfmt — --field reassembly keeps the original field width

  • Root cause: the auto-padding width ignored GNU's 1 < field rule (numfmt.c process_suffixed_number line 1360: padding_width = text < p || 1 < field ? mbswidth (text) : 0), so a converted field past the first collapsed the line: echo 'plain 1048576 line' | numfmt --field 2 --to=iec gave plain 1.0M line instead of GNU's plain 1.0M line.
  • Fix: one invariant correction — auto-padding uses the full field-text width when the field has leading blanks or is past the first; the converted number is padded back to the original field width and trailing fields keep their columns. Byte length stands in for mbswidth (ASCII = gate domain; wide multibyte is a documented divergence, and GNU's own strlen fallback applies to unprintable bytes). Explicit --padding and --delimiter still disable auto-padding (numfmt.c line 1687).

Gate (same tables, same harness)

  • before: 134/146 — 12 fail: sq51 sq52 sq53 sq54 (audit case x2, sub-ulp hang, 1e23) + nf75 nf76 nf77 nf78 nf79 nf80 nf85 nf86 (field-width collapse family)
  • after: 146/146 GREEN
  • cargo test winux-cmds: 358 passed / 0 failed (3 new tests); rustfmt clean on both files
  • New cases: sq51-sq60 (audit case + -w, sub-ulp, 1e23, 1000-step no-drift, 18/19-digit grids, negative zero, both long-double boundary shapes), nf75-nf86 (--field 1/2/3/-/2-3/1,3/4 × aligned multi-space lines, tabs, invalid=warn, wider output, delimiter/padding opt-outs, suffix/format-suffix width)
  • Oracle evidence: rust2/target/borrow-algo/{seq,numfmt}-probe{,.before,.after}.txt — 33 seq + 21 numfmt cases paired against WSL GNU coreutils 9.4 (33/33 and 20/21 parity; the 1 is stderr smart-quote wording, never gated)

Notes / residual

  • Past the long-double mantissa GNU itself prints float artifacts (probed: seq 2 1e-19 2.0000000000000000005 duplicates lines; -1.5 0.9999999999999999999 1.5 drifts a final ulp). We now print exact decimals there (uutils-equivalent behavior); documented in the module comment, outside the gate.
  • Harness finding flagged in GATE-REPORT.md (not fixed here): run_case feeds the stdin column with printf %s, so the \n escape stays literal and single-value numfmt rows (the nf01-nf28 class) pass vacuously through the invalid-suffix error path on both sides. Suggested follow-up recorded in the report.

Closes the borrow items of #1488. Not merging — captain to review.

…borrow-algo)

Root cause: the float generation path stepped in f64 where GNU uses
80-bit long double (seq.c print_numbers, lines 300-364), so >17-digit
decimal operands rounded at parse and sub-f64-ulp steps looped forever
(seq 0.9999999999999999999 1e-19 1.0000000000000000002 printed
1.0000000000000000000 forever; the audit case
seq 0.9999999999999999999 1.0000000000000000002 printed
1.0000000000000000000 instead of 0.9999999999999999999).

Fix: std-only exact-decimal path. Operands parse as (i128 mantissa,
decimal scale) pairs, the loop steps on the common 10^-scale grid,
output formats from the scaled integers only. The seq.c rounding fixup
(lines 340-356) is dead here: the value just past LAST sits on the
10^-prec grid so its rendering never reparses to LAST. A parity guard
admits only magnitudes under the long-double 64-bit mantissa grid
(< 2^64 units of 10^-prec over first/last/|last-first|); the probed
boundary keeps 0.99999999999999999999 (GNU parses to 1.0) on the float
path. The scientific-integer fast attempt renders endpoints from the
exact mantissa (GNU %0.Lf of the long double, seq.c lines 686-695):
seq 1e23 1e23 was 99999999999999991611392, now
100000000000000000000000.

Gate: sq51-sq60 (audit case, -w, sub-ulp, 1e23, 1000-step no-drift,
18/19-digit grids, negative zero, both ld boundary shapes). Evidence:
rust2/target/borrow-algo/seq-probe*.txt, 33/33 GNU 9.4 parity.
…borrow-algo)

Root cause: under auto-padding the per-field pad width ignored GNU's
1 < field rule (numfmt.c process_suffixed_number line 1360:
padding_width = text < p || 1 < field ? mbswidth (text) : 0), so a
converted field past the first collapsed the line to single spaces:
echo 'plain 1048576 line' | numfmt --field 2 --to=iec gave
'plain 1.0M line' instead of GNU's 'plain    1.0M line'.

Fix: one invariant correction — auto-padding uses the full field-text
width whenever the field carries leading blanks or is past the first,
so the converted number is padded back to its original field width and
trailing fields keep their columns. Byte length stands in for mbswidth
(ASCII = gate domain; wide multibyte is a documented divergence, and
GNU's own strlen fallback applies to unprintable bytes). Explicit
--padding and --delimiter still disable auto-padding (numfmt.c line
1687).

Gate: nf75-nf86 (--field 1/2/3/-/2-3/1,3/4 over aligned multi-space
lines, tab separators, invalid=warn, wider output, delimiter/padding
opt-outs, suffix/format-suffix width). Evidence:
rust2/target/borrow-algo/numfmt-probe*.txt, 20/21 GNU 9.4 parity
(the 1 is stderr smart-quote wording, never gated).
@caomengxuan666
caomengxuan666 merged commit 6f3146e into main Nov 12, 2026
7 of 9 checks passed
aphrody-labs Bot pushed a commit to aphrody-labs/WinuxCmd that referenced this pull request Nov 15, 2026
…nixwin#1488)

Owner-directed follow-up to unixwin#1562 (which covered only the coreutils
monorepo): audit the four uutils SIBLING repos that own our 2.0 big
unimplemented commands.

Method: shallow clones (target/uutils-siblings/, HEADs 2026-11-10..12),
three-party semantic sampling (WSL GNU 5.3.20 / our C++ build-1496 /
uutils debug builds), 8 cases per command, raw output in
target/uutils-siblings/sampling/threeway_all.txt.

Key findings:
- All four repos outsource regex: grep+findutils delegate to Oniguruma
  C (onig/onig_sys); sed = bre_to_ere translation -> regex crate with
  fancy-regex fallback for backrefs; diffutils ships a 360-line BRE
  translator over the regex crate. NO repo has a portable std-only
  Rust POSIX engine -> regex decision A (port portable_regex) stands;
  sed's bre_to_ere + diffutils bre.rs become cross-check corpora.
- IO: all four are process-level stdio; unixwin#1488 explicit-IO contract
  would require rewriting each repo's output layer (grep worst,
  diffutils lib layer best).
- Deps: 119-167 transitive packages per repo incl. a C library
  (onig_sys) -> route C (adopt crates) conflicts with std-only policy.
- Sampling: grep 8/8, sed 8/8, find 6/8 (uu walks print backslash
  paths while -printf prints forward slashes; localized -newer error),
  diff 7/8 for uu (missing -i) — and two OUR-side 1.x divergences
  found: cmp says "char 7" vs GNU/uu "byte 7"; diff -r recursion
  header prints redundant "diff diff -r ..." full args.
Recommendation: route B (borrow algorithms, unixwin#1575 precedent) as the
mainline with A carrying the engine; per-command table in the doc.
@caomengxuan666
caomengxuan666 deleted the rust2/borrow-algo branch November 18, 2026 05:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant