fix(libc): format %a like the console on Windows #9699
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9699"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-22T08:56:26Z.
What
On Windows the guest
printffamily (FormatWindows) passed%aand%Ato the host. UCRT gets two things wrong there compared with thelibc.prxthat titles ship, and the first is also a C conformance bug:main(Windows, UCRT)libc.prx/ this PR%-010aof 1.50x001.8p+00x1.8p+0(-overrides0)%-0#12Aof 0.750X00001.8P-10X1.8P-1%aof0x1p-10740x0.0000000000001p-10220x1p-1074%Aof 1e-3100X0.012688B70E62BP-10220X1.2688B70E62BP-1030%.3aof0x0.fffffffffffffp-10220x1.000p-10220x2.000p-1023%.0aof 1e-3100x0p-10220x1p-1030Finite doubles under
%a/%Aare now formatted byHexFloatinWindowsFormatting.hpp:%.0aof 1.5 →0x2p+0;-overrides0.Infinities, NaN (still unsigned, as in FreeBSD; those copies print
-nan) and%Lakeep their current paths. Since 4d3c9a73fa, Linux also formats%aand%Athrough the guest formatter:RequiresGuestFormattingreturns true for them, as #9916 does for%e/%f/%g. The new cross-platform checks expose an unresolved Linux regression; see the independent Linux result below.How it was checked
I ran the decrypted
libc.prxof PPSA13934, PPSA07923 and PPSA05916 natively: a scratch loader maps the ELF, applies its relocations and supplies__error. Itssnprintf(eLdDw6l0-bU) was called through a SysV variadic pointer on random%a/%Aformats, with every flag combination, widths 0-31 and precisions none, empty and 0-19. Values covered random bit patterns, subnormals, rounding halves and small fractions. The output was compared with:HexFloatextracted from this PR'sWindowsFormatting.hpp: another 3 million, all identical.An end-to-end run of 100,000 random
snprintfcalls against the builtlibc.prxstill differs in%a/%Aonly for negative NaN. The other floating conversions keep their known differences (the console's%e/%f/%gproduce about 20 significant digits and then zeros), which are out of scope here.Tested
Current Linux refresh:
377e8fccec35aefea73c6eaee48b16f4c8b44eceon main637220db112a3daf4960984290a82fcf65ba7061. The stack is rebuilt linearly in the order #9699 → #9916 → #9927 → #9958 → #10379, with no merge commits or duplicated prerequisite commits. This PR adds six original topic commits. Fresh Release libc/fixture build andguest_formatting,guest_wide_formatting,guest_stdio_variadicpass (3/3) on this exact head; conventions against the tested main and whitespace checks pass. Final-stack conventions against origin/main have zero errors (six inherited debt-length warnings). All five heads also merge cleanly with newer mainc8d34aa8f4d8058d57169cc1e423ba6db00faaf0; that merge preview is not an additional runtime test. The resolution keeps main’s measured narrow NaN signs/flags, positional/unknown-conversion handling, and bothCheckSizeLimits()andCheckHexFloat()test registrations. All five pinned heads, patches, checks and control logs (SHA-2569cda806ab2a54a4a0ce012517eafb7db0441ab2665d2e49884c3d1fc5b9e0c8a). No fresh Windows, title-library comparison, physical-console, game or performance result is claimed; Windows testing remains paused. The requested fresh Windows validation on #9699 is still outstanding.Historical validation on previous public head
ac59a7401116ac8f25ba338ace126b3f50f325d2is retained below with its original scope; references there to ‘exact head’ refer to that historical run.Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 r7 (UCRT), Ninja, Release,
-DBUILD_TESTING=ON,main7e2ba73e4c; rebased ontomain8b3a6ba88dand retested (below).guest_formatting: the newCheckHexFloathas 16 cases with the console's outputs:-/0combinations, normalised subnormals, the carry case and half-up rounding;#with precision 0, negative zero, a negative*width, and a buffer that truncates.mainit fails at the first one:[%-010a] of 0x1.8p+0 gave "[0x001.8p+0]", expected "[0x1.8p+0 ]". With this change,guest_formattingand the other formatting, scanf and stream tests (6) pass in three runs out of three.8b3a6ba88d: the 28 libc formatting, scanf, stream and wide-character tests pass in three runs out of three. They pass the same way on a local merge with #9296 that keeps both new test calls:int main() { CheckSizeLimits(); RunChecks(); CheckHexFloat(); CheckAllocatingFormat(); return CheckWidePrecision() ? 0 : 1; }.ctest -j16 --timeout 120: 1890 of 1890 pass.python tools/check_conventions.py --base origin/main: passes.tools/pr_overlap.py --branch: text-only conflicts. #9296 changes the samemain()line ofFormatting.cpp; #8855 and #9552 change neighbouringlibc.mdlines.Independent Linux result — routing fixed and focused rerun passed
Dom-The-Dom’s Linux review tested head
184733f90dmerged onto main24c6cc33f: Ubuntu 26.04 in Docker on Windows, GCC 15, glibc 2.43, WSL2 kernel 6.6, Release,BUILD_TESTING=ON.guest_formattingpasses on that main and fails with this PR:%aof the smallest positive subnormal goes through glibc and prints0x0.0000000000001p-1022, whereas the new test expects the console form0x1p-1074. Removing the subnormal rows exposes the rounding difference:%.1aof0x1.08p+0produces0x1.0p+0instead of the expected0x1.1p+0. These are reviewer results, not a fresh local Linux build.The routing correction is the commit "send %a to the guest formatter on Linux too" (4d3c9a73fa):
CheckHexFloatstays active on every host, double%a/%Ago through the guest formatter on Linux, and%Lakeeps its separate host path. The branch is rebased ontomain895f47f4ee; on Windows the 34 formatting, scanning, stream, wide-character and string tests pass in three runs out of three. The exact-head Linux rerun below passes both complete formatting executables; the broader 19-case Linux libc selection also passes three repetitions at this exact head (see below).Linux (reviewer run): MarcZX10 ran a focused Linux check in an existing configured Release build with GCC 12:
guest_formatting, includingCheckHexFloat, passed with the formatting and test sources of #9958, which contains this PR. That reused an older configured tree with the PR's sources overlaid, so it is a focused Linux run, not a clean CI build.Linux (Codex, fresh exact-head build): Recorded result for
4d3c9a73fa7e667bbe9ba5766069c3663fbf6bf6: Linux 7.2.9-arch1-1, GCC 16.2.1 20260810, glibc 2.44, Ninja Release,BUILD_TESTING=ON.ctest -R '^guest_(wide_)?formatting$' -V --no-tests=error --timeout 120passes both complete executables in all three repetitions, with no skipped cases. This is two CTest cases, not the Windows 34-test selection or a full CI/title/performance result. The subsequent broader 19-case focused libc selection passes all three repetitions at this exact head; see the recorded result below. A negative control retaining the new tests and restoring only the parent productionFormatting.cppfails on the smallest positive subnormal; the candidate keepsCheckHexFloatactive.Broader Linux validation (exact head
4d3c9a73fa7e667bbe9ba5766069c3663fbf6bf6): Complete result. All 19 selected libc formatting, scanning, stream, string, character and locale CTest cases passed in each of three repetitions, with no skips. Linux 7.2.9-arch1-1, GCC 16.2.1, glibc 2.44, Ninja Release,BUILD_TESTING=ON. This is the exact submitted head, not a build against newer main, a full CI run, or a title/performance result. Dependent #9927 has a separate stream-test expectation failure under investigation; these passes do not establish that dependent branch passes.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); no silent stubs added.mdfiles or images added to the repositoryAI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-22T08:59:12Z.
Holding this as a draft under the intake direction on #5239: six converted titles import
snprintf(eLdDw6l0-bU), but I have no title run showing one of them depends on%aoutput. I'll mark it ready when a title run shows it, or when the queue is under the threshold.Imported from boykopovar/AnyPS5. Originally posted by clairtonmichel on 2026-10-22T09:22:13Z.
Tested on AMD Ryzen 7 9800X3D and AMD Radeon RX 7900 XTX (Fedora Linux, Mesa 26.2.5):
%aformatting fix is stable. Ready to merge!Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T12:20:35Z.
Review: CHANGES_REQUESTED
The new
HexFloatpath is clearly scoped to finite%a/%Adoubles; NaNs and long doubles retain their old paths. The reported 7 million comparisons against three shippedlibc.prxcopies are strong evidence, and hosted relinker checks pass. I did not independently execute the Windows formatter tests on this Linux checkout.Please update this branch to current
main(8b3a6ba88d8fc74e768f1a7e8e9e36fb69842768); this head is based on7e2ba73e4c, 13 commits behind. Re-run the focused Windows formatting tests after the update. GitHub’s automatic full Windows/Linux jobs are skipped here, so the reported Windows 11guest_formattingresults remain author-reported.Please coordinate the overlapping
core/libs/tests/Formatting.cpptest-entry change with #9296. ItsCheckSizeLimits()addition and this PR’sCheckHexFloat()addition both update the samemain()line. The currentDepends on: noneis appropriate if you agree to combine the test changes during integration; if one branch is stacked on the other, declare that dependency and preserve both test calls. Thelibc.mdoverlap with #8855/#9552 appears to be separate debt entries, but please retain the overlap notes as those branches are rebased.Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-22T12:24:52Z.
@MarcZX10 thanks. Rebased onto
main8b3a6ba88d(head 2d9a42e3cb, no other changes). On Windows (UCRT GCC 15.2, Release),guest_formatting,guest_wide_formatting,guest_wide_strings,guest_wide_stream_scanand the rest of the libc stream/scan set (28 tests) pass in three runs out of three.tools/check_conventions.pypasses.On #9296: I agree to combine the test entries during integration, so
Depends on: nonestays. I checked the combination by merging #9296's head595dcacdf2into this branch locally. The only conflict is themain()line, and it resolves to:With that line, the same 28 tests pass in three runs out of three. The
libc.mdentries for #8855 and #9552 merged without conflict, and the overlap notes in the description stay. @superhe11 FYI, whichever of us merges second only needs that one line.Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-22T13:28:52Z.
Marked ready for review. This was a draft only because of the #5239 intake hold, which @MarcZX10 has withdrawn (https://github.com/boykopovar/AnyPS5/pull/9613#issuecomment-6337453028 and on #9596).