fix(libc): format wide %a, %e, %f and %g with the narrow console rules #9927

Merged
JJenkx merged 2 commits from upstream-pr/9927 into main 2026-10-26 12:25:23 +00:00
JJenkx commented 2026-10-22 22:11:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-22T22:11:59Z.


What

The wide printf family (swprintf, vswprintf and the rest) still formats %a, %e, %f and %g through the host. The libc.prx that titles ship gives swprintf the same text as snprintf. On 199,948 random formats, the copy bundled with PPSA07923 printed identical narrow and wide output. This build's wide output differed from it on 23,893, including 1,631 with no more than 17 significant digits. Examples, console then main: %.0f of 2.5 gives 3 vs 2, and %a of 0x1p-1074 gives 0x1p-1074 vs 0x0.0000000000001p-1022.

The wide float branch now uses #9916's DecimalFloat and #9699's HexFloat for finite values. Infinities, NaN, and long double with %a still use the host, as in the narrow family.

Tested

Refreshed exact head, 2026-10-25: 2def057898f2d0d857bed1579e14b6930adf4cd2. Two linear topic commits directly on main 49d1f9b07ec7f6f989ace1c504bbe9dd6748dcbb; #9699 and #9916 are already merged. No merge commits or duplicated merged prerequisites. All added/removed line multisets for this topic's code, tests and debt match the former public patch. Conventions and whitespace pass. Both stack heads merge cleanly with newer main b76f08cf33ea280d6155f16a84c1555701c3b2af, which changes only libSceNet export/tests/debt since the tested base; that is a merge preview, not another build.

Fresh Linux GCC 16.2.1 Release: rebuilt libc and all 12 selected CPU test executables. Exact main, candidate and restored candidate each pass 12 groups × 3 repetitions (36 passes per arm), zero skips. This includes complete guest_formatting, guest_wide_formatting and guest_stdio_variadic executables, plus wide strings/conversion/stream scanning, scan counts, strings, allocating strings, allocator failures, multibyte locale and character checks.

Restoring only main's FormattingWide.cpp while keeping candidate tests fails guest_wide_formatting at the decimal rounding/cap check and guest_stdio_variadic at the formatted stream contents. Those parent-production controls fail both expected groups. Restoring this exact head passes all 36 executions again and reproduces identical hashes for libc and all 12 tested executables.

Both pinned heads, full source-preservation checks, patches, build/test logs, parent controls and restoration hashes. SHA-256: 7da9766761e33dbc0bd05a7462cda802cb6b2d9a096516324133055079f9e151; downloaded copy verified.

These are CPU regression results, not a fresh Windows run, converted title-libc differential, physical-console measurement, game/performance run or full-suite build. Earlier evidence below retains its original revisions and platforms.

Historical pinned validation

Earlier Linux refresh: 8f2f8a0e3fd494d4930198112cf558569811f534 on main 637220db112a3daf4960984290a82fcf65ba7061. The stack is rebuilt linearly in the order #9699 → #9916 → #9927 → #9958 → #10379, with no merge commits or duplicated prerequisite commits. This PR adds the wide-formatting commit plus its stream-expectation correction. Fresh Release libc/fixture build and guest_formatting, guest_wide_formatting, guest_stdio_variadic pass (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 main c8d34aa8f4d8058d57169cc1e423ba6db00faaf0; that merge preview is not an additional runtime test. The stream expectation correction is retained together with the wide finite paths. All five pinned heads, patches, checks and control logs (SHA-256 9cda806ab2a54a4a0ce012517eafb7db0441ab2665d2e49884c3d1fc5b9e0c8a). 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 6ff9b7d58ace9c651630593c511875b67224e222 is 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 UCRT r7, Ninja, Release, BUILD_TESTING=ON. Head 8359f9ef3a, on #9916's head b5e461750e.

  • Differential run: a scratch loader runs a title's decrypted libc.prx natively. It calls that copy's snprintf and swprintf (nJz16JE1txM) and this build's swprintf_nid_postfix on 199,948 random formats: random flags, width, precision 0–29, a/A/e/E/f/F/g/G, and values from random bits or binary fractions. The copies of PPSA07923, PPSA05916 and PPSA13934 all give the same results:

    • the console's wide and narrow output never differ;
    • this build's wide output now differs on 556 formats, all with more than 17 significant digits. That is the extended-precision tail #9916 records as technical debt. On main it differed on 23,893.
  • guest_wide_formatting: the new CheckFloat covers ties (2.5, 0.25, 2025 with #), a large tie that rounds down (67108865.5), zero padding (%.20f of 0.1), %a of a subnormal and a carried %.3a, and a long double tie. All of them are console results. The libc formatting, scanning, stream, wide-character and string tests (34) pass in three runs out of three. With #9916's FormattingWide.cpp and this test, guest_wide_formatting aborts.

  • python tools/check_conventions.py --base origin/main and git diff --check pass.

  • Overlap: the code merges cleanly with #9596, #9527 and #5303, which also edit FormattingWide.cpp. The last two have a neighbouring-line conflict in docs/dev/debt/libc.md. The overlap bot also flags #8855 and #9552 in the debt file. At their reviewed heads (a37f8c630a and 314c7c4b9c), #8855 changes the narrow printf locale wording and #9552 raises its argument-position limit; retain those changes alongside this PR's float-formatting entries when resolving the debt text. #8855 also changes CheckWcsftime in GuestWideFormatting.cpp, separately from this PR's CheckFloat cases. These are patch-review findings, not a combined build/test result or additional dependencies.

  • Not tested: a console. The original Windows report above used the earlier head; the exact-head Linux result is recorded below.

  • Linux (reviewer run): MarcZX10 ran a focused Linux check in an existing configured Release build with GCC 12: guest_formatting and guest_wide_formatting passed 2/2 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 72e9e54e1591ab826269db01c2f936cdaa881691: 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 120 passes 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 broader Linux run reproduced a stale guest_stdio_variadic expectation: vfwprintf of 2.25 with %5.1f now correctly writes 2.3 under this PR’s rounding rule, while the test expected 2.2. Commit f51e62745581c846487cdc00415e2bde681b1bb4 corrects only that expected string; production code is unchanged. All 19 selected libc formatting, allocation, scanning, stream, wide-character, string, conversion and locale tests then passed in each of three repetitions (19/19 ×3, no skips). This is a focused Linux result, not a Windows rerun, full CI build or title test.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none (#9699 and #9916 are merged)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a (CPU libc tests)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4974808705 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9927). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-22T22:11:59Z. --- ### What The wide printf family (`swprintf`, `vswprintf` and the rest) still formats `%a`, `%e`, `%f` and `%g` through the host. The `libc.prx` that titles ship gives `swprintf` the same text as `snprintf`. On 199,948 random formats, the copy bundled with PPSA07923 printed identical narrow and wide output. This build's wide output differed from it on 23,893, including 1,631 with no more than 17 significant digits. Examples, console then `main`: `%.0f` of 2.5 gives `3` vs `2`, and `%a` of `0x1p-1074` gives `0x1p-1074` vs `0x0.0000000000001p-1022`. The wide float branch now uses #9916's `DecimalFloat` and #9699's `HexFloat` for finite values. Infinities, NaN, and `long double` with `%a` still use the host, as in the narrow family. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> **Refreshed exact head, 2026-10-25: `2def057898f2d0d857bed1579e14b6930adf4cd2`.** Two linear topic commits directly on main `49d1f9b07ec7f6f989ace1c504bbe9dd6748dcbb`; #9699 and #9916 are already merged. No merge commits or duplicated merged prerequisites. All added/removed line multisets for this topic's code, tests and debt match the former public patch. Conventions and whitespace pass. Both stack heads merge cleanly with newer main `b76f08cf33ea280d6155f16a84c1555701c3b2af`, which changes only libSceNet export/tests/debt since the tested base; that is a merge preview, not another build. Fresh Linux GCC 16.2.1 Release: rebuilt libc and all 12 selected CPU test executables. Exact main, candidate and restored candidate each pass **12 groups × 3 repetitions (36 passes per arm), zero skips**. This includes complete `guest_formatting`, `guest_wide_formatting` and `guest_stdio_variadic` executables, plus wide strings/conversion/stream scanning, scan counts, strings, allocating strings, allocator failures, multibyte locale and character checks. Restoring only main's `FormattingWide.cpp` while keeping candidate tests fails `guest_wide_formatting` at the decimal rounding/cap check and `guest_stdio_variadic` at the formatted stream contents. Those parent-production controls fail both expected groups. Restoring this exact head passes all 36 executions again and reproduces identical hashes for libc and all 12 tested executables. [Both pinned heads, full source-preservation checks, patches, build/test logs, parent controls and restoration hashes](https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/format-stack-head2def0578-head98992248-main49d-linux-validation.tar.gz). SHA-256: `7da9766761e33dbc0bd05a7462cda802cb6b2d9a096516324133055079f9e151`; downloaded copy verified. These are CPU regression results, not a fresh Windows run, converted title-libc differential, physical-console measurement, game/performance run or full-suite build. Earlier evidence below retains its original revisions and platforms. ### Historical pinned validation Earlier Linux refresh: `8f2f8a0e3fd494d4930198112cf558569811f534` on main `637220db112a3daf4960984290a82fcf65ba7061`. The stack is rebuilt linearly in the order #9699 → #9916 → #9927 → #9958 → #10379, with no merge commits or duplicated prerequisite commits. This PR adds the wide-formatting commit plus its stream-expectation correction. Fresh Release libc/fixture build and `guest_formatting`, `guest_wide_formatting`, `guest_stdio_variadic` pass (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 main `c8d34aa8f4d8058d57169cc1e423ba6db00faaf0`; that merge preview is not an additional runtime test. The stream expectation correction is retained together with the wide finite paths. [All five pinned heads, patches, checks and control logs](https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/format-stack-main637220db-five-heads-linux-20261024.tar.gz) (SHA-256 `9cda806ab2a54a4a0ce012517eafb7db0441ab2665d2e49884c3d1fc5b9e0c8a`). 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 `6ff9b7d58ace9c651630593c511875b67224e222` is 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 UCRT r7, Ninja, Release, `BUILD_TESTING=ON`. Head 8359f9ef3a, on #9916's head b5e461750e. - **Differential run:** a scratch loader runs a title's decrypted `libc.prx` natively. It calls that copy's `snprintf` and `swprintf` (`nJz16JE1txM`) and this build's `swprintf_nid_postfix` on 199,948 random formats: random flags, width, precision 0–29, `a/A/e/E/f/F/g/G`, and values from random bits or binary fractions. The copies of PPSA07923, PPSA05916 and PPSA13934 all give the same results: - the console's wide and narrow output never differ; - this build's wide output now differs on 556 formats, all with more than 17 significant digits. That is the extended-precision tail #9916 records as technical debt. On `main` it differed on 23,893. - **`guest_wide_formatting`:** the new `CheckFloat` covers ties (`2.5`, `0.25`, `2025` with `#`), a large tie that rounds down (`67108865.5`), zero padding (`%.20f` of 0.1), `%a` of a subnormal and a carried `%.3a`, and a `long double` tie. All of them are console results. The libc formatting, scanning, stream, wide-character and string tests (34) pass in three runs out of three. With #9916's `FormattingWide.cpp` and this test, `guest_wide_formatting` aborts. - `python tools/check_conventions.py --base origin/main` and `git diff --check` pass. - **Overlap:** the code merges cleanly with #9596, #9527 and #5303, which also edit `FormattingWide.cpp`. The last two have a neighbouring-line conflict in `docs/dev/debt/libc.md`. The overlap bot also flags #8855 and #9552 in the debt file. At their reviewed heads (`a37f8c630a` and `314c7c4b9c`), #8855 changes the narrow printf locale wording and #9552 raises its argument-position limit; retain those changes alongside this PR's float-formatting entries when resolving the debt text. #8855 also changes `CheckWcsftime` in `GuestWideFormatting.cpp`, separately from this PR's `CheckFloat` cases. These are patch-review findings, not a combined build/test result or additional dependencies. - Not tested: a console. The original Windows report above used the earlier head; the exact-head Linux result is recorded below. - **Linux (reviewer run):** [MarcZX10 ran a focused Linux check](https://github.com/boykopovar/AnyPS5/pull/9958#issuecomment-6354379800) in an existing configured Release build with GCC 12: `guest_formatting` and `guest_wide_formatting` passed 2/2 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](https://github.com/boykopovar/AnyPS5/pull/9927#issuecomment-6355204843) for `72e9e54e1591ab826269db01c2f936cdaa881691`: 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 120` passes 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 broader Linux run reproduced a stale `guest_stdio_variadic` expectation: `vfwprintf` of `2.25` with `%5.1f` now correctly writes ` 2.3` under this PR’s rounding rule, while the test expected ` 2.2`. Commit `f51e62745581c846487cdc00415e2bde681b1bb4` corrects only that expected string; production code is unchanged. All 19 selected libc formatting, allocation, scanning, stream, wide-character, string, conversion and locale tests then passed in each of three repetitions (19/19 ×3, no skips). This is a focused Linux result, not a Windows rerun, full CI build or title test. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none (#9699 and #9916 are merged) - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a (CPU libc tests) - [x] AI-assisted: yes
MarcZX10 commented 2026-10-23 05:12:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T05:12:55Z.

Review: DISMISSED


Reviewed exact head f51e62745581c846487cdc00415e2bde681b1bb4. The implementation and test report describe a focused wide floating-formatting change, preserve the stated extended-precision debt, and include a correction to the dependent guest_stdio_variadic expectation. The PR reports repeated focused Linux tests and Windows differential/build results; I have not independently rerun these on this head in this session. Local diff check, conventions, and registration checks pass. I cannot approve this branch as based on current main: tools/check_main_sync.py --base upstream/main --head <head> reports 6 commits ahead / 396 behind, with a clean merge. CONTRIBUTING requires one topic branch based on current main and kept up to date. Please merge current main, preserve the agreed overlap/debt edits, and rerun the focused formatting tests plus conventions on the resulting head. This request is only for repository freshness; it is not an intake or queue-size objection.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5624168207 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9927#pullrequestreview-5624168207). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T05:12:55Z. **Review:** DISMISSED --- Reviewed exact head f51e62745581c846487cdc00415e2bde681b1bb4. The implementation and test report describe a focused wide floating-formatting change, preserve the stated extended-precision debt, and include a correction to the dependent `guest_stdio_variadic` expectation. The PR reports repeated focused Linux tests and Windows differential/build results; I have not independently rerun these on this head in this session. Local diff check, conventions, and registration checks pass. I cannot approve this branch as based on current `main`: `tools/check_main_sync.py --base upstream/main --head <head>` reports 6 commits ahead / 396 behind, with a clean merge. CONTRIBUTING requires one topic branch based on current `main` and kept up to date. Please merge current `main`, preserve the agreed overlap/debt edits, and rerun the focused formatting tests plus conventions on the resulting head. This request is only for repository freshness; it is not an intake or queue-size objection.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!9927
No description provided.