Repository navigation
fix(printf): route float operands through 80-bit long double (#879) - #900
arookieofc wants to merge 2 commits into
Conversation
GNU spec: builtins/printf.def:208-213 floatmax_t/strtofltmax (strtold), printf.def:774-798 float conversions via getfloatmax with the 'L' modifier (glibc formats a long double), printf.def:1387-1398 chk_converror (a trailing suffix beats ERANGE). - New src/builtins/printf/longdouble.rs: pure-Rust x86-64 80-bit extended emulation (host long double is double on MSVC). Exact decimal/hex literal conversion with one round-half-even step to the 64-bit mantissa; exact decimal expansion of mant*2^exp for the formatters; overflow/underflow decided by magnitude guards plus ERANGE from the rounder (overflow, inexact underflow). - number.rs: parse_f64/convert_float_subject/hex_significand_to_f64 replaced by parse_long_double (suffix still beats ERANGE, matching chk_converror order). - float.rs: %f/%e/%g/%a engines work from exact digits and round half-even (oracle: %.0f of 0.5/1.5/2.5 -> 0/2/2). %a prints the 64-bit mantissa nibble-style with D = exp+60 (oracle: %a of 5 -> 0xap-1, %.2a of 4.2 -> 0x8.66p-1); %g re-selects style after rounding (%.2g of 99.9 -> 1e+02). - value.rs: zero padding goes after sign and 0x/0X prefix (%015a 5 -> 0x000000000ap-1, %#010x 255 -> 0x000000ff). - Fixed a carry-to-infinity guard typo in the rounder (exp+63 vs the unreached exp-63+64) and two stale f64-locked %a unit expectations; added tests/issue879_printf_longdouble_regressions.rs (9 tests). Verified: probe batteries A/B/C/D/F/G byte-identical to WSL GNU bash 5.3 (/usr/local/bin/bash) via script files; lib 706 pass (1 pre-existing windows_listing_cache env flake); printf lib 52/52; new integration 9/9.
|
欢迎!这是你的第一个 PR 🎉 请确认已跑过本地测试套件;CI 通过后维护者会 review。 |
Fold the float engines' digit/nibble -> char widenings into two reviewed helpers (decimal_digit_char/hex_digit_char in printf/longdouble.rs, operands 0-9/0-15 by construction) and allowlist them in scripts/check-utf8-boundary-hygiene.sh, replacing the stale float.rs digits[] entry from the retired f64 engine.
独立评审结论:REQUEST-CHANGES(独立评审代理,自建 worktree @ 7e89824 + a05ab23 复核;oracle = WSL GNU bash 5.3.0(1) 主体语义已达标,但新引擎的 hex 字面量路径存在两处可复现的逐字节分歧(均落在 #879 的浮点族逐字节验收面内),修完即可。 已验证逐字节一致的部分(34 形探针矩阵)
性能抽验300 次 两处 REQUEST 级分歧(
|
补充评审(
|
复审结论(a05ab236 = 当前 head):REQUEST-CHANGES 维持,不合入(复审代理独立复核:自建 worktree 检出 PR merge ref 复核矩阵(stderr 归一化后双侧逐字节一致,stdout 46+8 形中 9 处分歧,全部复现)点 1(hex 窗口截断丢指数补偿)——仍在。 点 2(hex denormal 下溢 guard 差一档)——仍在。 guard 仍为 点 3(十进制窗口 新发现(点 4):
|
|
返工 PR 已开:#935 —— 实现本轮评审全部四点分歧(hex 窗口
|
…uard, decimal window, '0' on inf/nan (#935) * fix(printf): route float operands through 80-bit long double (#879) GNU spec: builtins/printf.def:208-213 floatmax_t/strtofltmax (strtold), printf.def:774-798 float conversions via getfloatmax with the 'L' modifier (glibc formats a long double), printf.def:1387-1398 chk_converror (a trailing suffix beats ERANGE). - New src/builtins/printf/longdouble.rs: pure-Rust x86-64 80-bit extended emulation (host long double is double on MSVC). Exact decimal/hex literal conversion with one round-half-even step to the 64-bit mantissa; exact decimal expansion of mant*2^exp for the formatters; overflow/underflow decided by magnitude guards plus ERANGE from the rounder (overflow, inexact underflow). - number.rs: parse_f64/convert_float_subject/hex_significand_to_f64 replaced by parse_long_double (suffix still beats ERANGE, matching chk_converror order). - float.rs: %f/%e/%g/%a engines work from exact digits and round half-even (oracle: %.0f of 0.5/1.5/2.5 -> 0/2/2). %a prints the 64-bit mantissa nibble-style with D = exp+60 (oracle: %a of 5 -> 0xap-1, %.2a of 4.2 -> 0x8.66p-1); %g re-selects style after rounding (%.2g of 99.9 -> 1e+02). - value.rs: zero padding goes after sign and 0x/0X prefix (%015a 5 -> 0x000000000ap-1, %#010x 255 -> 0x000000ff). - Fixed a carry-to-infinity guard typo in the rounder (exp+63 vs the unreached exp-63+64) and two stale f64-locked %a unit expectations; added tests/issue879_printf_longdouble_regressions.rs (9 tests). Verified: probe batteries A/B/C/D/F/G byte-identical to WSL GNU bash 5.3 (/usr/local/bin/bash) via script files; lib 706 pass (1 pre-existing windows_listing_cache env flake); printf lib 52/52; new integration 9/9. * fix(printf): UTF-8 hygiene single-point digit widening (#879) Fold the float engines' digit/nibble -> char widenings into two reviewed helpers (decimal_digit_char/hex_digit_char in printf/longdouble.rs, operands 0-9/0-15 by construction) and allowlist them in scripts/check-utf8-boundary-hygiene.sh, replacing the stale float.rs digits[] entry from the retired f64 engine. * fix(printf): #879 PR #900 review — hex window pexp, denormal guard, decimal window, '0' on inf/nan Implements all four REQUEST-CHANGES findings from the #900 review in the 80-bit long-double emulation (GNU printf.def:208-213 strtofltmax / :774-798 getfloatmax with the 'L' modifier): 1. parse_hex_subject: the >100-significant-digit window truncated `sig` without the decimal path's exponent compensation. Dropped hex nibbles are exact 4-bit groups, so `pexp += 4 * drop`; 16^100+1 = 2^400+1 had printed as 2^396 (16x too small). 2. parse_hex_subject: the underflow guard `4*digits + pexp <= -16445` zeroed (2^-16446, 2^-16445), which glibc rounds UP to the minimum denormal (inexact -> ERANGE). Threshold is half the minimum denormal: `<= -16446`. 3. DECIMAL_KEEP_DIGITS 32 -> 2048: a dropped decimal tail is not bit-aligned (10 = 2*5), so truncation could pull the kept value below a binary tie the true value sits at/above, and `sticky` is only consulted at `low3 == 0b100`. The widened window keeps boundary literals on the exact path while still bounding the bignum. 4. format_value: the '0' flag no longer applies to nonfinite results — glibc space-pads inf/nan with any sign adjacent (`%010a` of nan is ` nan`, not `0000000nan`). Also removes the always-false `k_lo < 0 && 4*k_lo >= 16384` overflow guard disjunct flagged as a nit in the same review. All review reproducers are added to tests/issue879_printf_longdouble_regressions.rs (13/13); printf lib tests 52/52; issue326 + issue510 regression files green; cargo fmt clean; no new clippy lints in touched files. Original patch series by a-rookie-of-C-language (PR #900); this commit is the review-finding rework only. Refs #879, Refs #900 Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> --------- Co-authored-by: arookieofc <[email protected]> Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
The four review findings this PR targets have landed via #935 (squash f36a3c6 — hex window pexp compensation, denormal guard -16446, decimal window widening, '0'-flag inf/nan space-pad; 46+8 form probes byte-identical to GNU). Thank you @a-rookie-of-C-language — closing as superseded; branch remains for reference. |
The niu GAP-3 host lane (niubash#900) consumes Session::bind_view at 7 production call sites and edited its ledger copy's §2.3 row accordingly; this is the byte-identical rubash-side copy so the lockstep holds when unixwin#900 merges. Refs niubash#863
Fixes #879.
Float operands now convert through the 80-bit extended format (printf.def:208-213 strtofltmax, :774-798 getfloatmax + L modifier) instead of f64, and %a prints the glibc %La nibble style.
Verification (all oracle probes via WSL GNU bash 5.3 script files, byte-identical):