Repository navigation
fix(libc): round and cap %e, %f and %g as titles' libc.prx does - #9916
Conversation
| output.Value(spec + "L" + conversion, value); | ||
| } | ||
| } else { | ||
| if (!length.empty() && length != "l") throw std::invalid_argument("Invalid floating length"); |
There was a problem hiding this comment.
ParseFloatSpec accepts precision == INT_MAX, but this sum adds the sign, decimal point and (for %e) exponent after that precision. For example %.2147483647e has an output length greater than INT_MAX; the check happens only after the signed sum. Please compute this with checked additions or reject when each component exceeds maximumLength - accumulatedLength before adding, so the intended output bound cannot be bypassed by an oversized format. I have not run this on the full Windows target locally; this is a source-level boundary finding. AI-assisted review.
There was a problem hiding this comment.
Thanks. The sum can't wrap: each term is a long long, precision is at most INT_MAX (ParseFloatSpec rejects anything larger), and the other terms add at most a few thousand. That's the sign, whole (at most 4,933 integer digits for a long double), the point and an exponent of at most 7 characters. So length is exact and the length > maximumLength check runs on the full value before anything is allocated. %.2147483647e is 2,147,483,653 characters, which the check rejects.
This wasn't covered by a test, so b5e4617 adds one in CheckDecimalFloat. These formats must throw std::overflow_error: %.2147483647e, %+.2147483647E, %.2147483647f, % .2147483646F, %#.2147483647g and %.2147483647Le. So must the smallest cases one character past the bound: %.2147483643e (2,147,483,649 characters), x%.2147483645f (output already holds 1 character) and x%-2147483647e.
Writing the test caught two cases I had first picked that are not oversized. %.2147483640e and x%.2147483642f produce 2,147,483,646 and 2,147,483,645 characters, within the bound, so they're legitimately formatted, as %a does. Windows build of b5e4617: the 34 formatting, scanning, stream, wide-character and string tests pass in three runs out of three, and conventions pass.
b1dd830 to
b5e4617
Compare
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
|
Linux run. Docker on Windows: Ubuntu 26.04, GCC 15, glibc 2.43, WSL2 kernel 6.6, Release,
AI-assisted: yes |
|
I reviewed the finite decimal formatter changes and their integration path. The exact-digit generator, precision/rounding path and shared width/flag handling are clearly scoped; the tests and differential survey describe the remaining extended-precision tail explicitly. I ran This head is 5 commits ahead/120 behind current main. Main has not changed the formatter implementation or test files since the merge base, but it has changed |
b5e4617 to
d9653a1
Compare
|
Rebased onto
|
|
The new exact-head conventions check is still failing: it reports the unchecked template item “Refresh the #9699 → #9916 stack onto current |
|
You're right that the Linux report doesn't cover this head. I can't run a Linux build on this machine, so I haven't ticked anything for Linux. Instead, the checklist's first item is back to the template's "Based on current |
|
Linux rerun completed on exact submitted head Built Both complete executables pass 2/2 in each of three runs, with Scope: these two formatting executables only, not the Windows 34-test selection, a full suite, a console run, a game test or a performance comparison. Raw configure/build/test logs and their SHA-256 hashes are retained locally under |
|
Linux follow-up at exact head This checks the libc suite listed above, not the full Windows 34-test regex or all CI. No game, GPU or performance claim. Local logs and the exact-head manifest are retained for follow-up. AI-assisted: yes (Codex). |
d9653a1 to
5291860
Compare
|
Refreshed with the rest of the formatting stack: |
|
Merged the updated #9699 head (
Windows run on |
|
Linux run of the current head Setup: CachyOS, kernel 7.3.0-4, GCC 16.2.1, glibc 2.44, CMake 4.4.3, Ninja,
No title, console or performance run. AI-assisted: yes (Claude Code). |
The Windows printf family handed %a and %A to the host, whose UCRT prints a subnormal unnormalised (0x0.0000000000001p-1022) and pads with zeros even when the - flag is given (%-010a of 1.5 gave 0x001.8p+0). The libc.prx that titles ship normalises subnormals (0x1p-1074), rounds a shorter precision half up without renormalising a carry, and lets - override 0, as C requires. Finite doubles are now formatted here, checked against three titles' copies of libc.prx run side by side. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Linux handed a format without wide arguments, %m or %p to glibc, so %a there still printed subnormals unnormalised and rounded hexadecimal digits half to even, and CheckHexFloat, which runs on every host, failed on Linux. Route %a and %A to FormatWindows on Linux as well. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The libc debt entry for %a and %A still described the Windows-only formatter and said Linux hands %a to glibc; since Linux routes %a and %A to the same formatter, describe it for both platforms. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The printf family formatted floating-point conversions through the host, which prints every exact digit and rounds ties to even. The libc.prx that titles ship keeps the exact digits only down to a position derived from the binary exponent and prints zeros after them, rounds half up on the kept digits, and rounds an exact tie down once that exponent estimate reaches 8. So %.0f of 2.5 is 3 and %.1f of 0.25 is 0.3 there, and %.20f of 0.1 is 0.10000000000000000555. Format finite double and long double e, f and g conversions with those rules from exactly generated digits, on every host. On 600,000 random formats every output with up to 17 significant digits now matches the copies bundled with PPSA07923, PPSA05916 and PPSA13934; longer outputs still differ where the console's extended-precision digits end one unit lower. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2f7dcf5 to
182bd6a
Compare
What
The printf family formats
%e,%fand%gthrough the host. glibc and the UCRT print every exact digit and round ties to even. Thelibc.prxthat titles ship (Dinkumware_Printf) does neither. Console vsmain:main%.0fof 2.532%.1fof 0.250.30.2%#.3gof 20252.03e+032.02e+03%.20fof 0.10.100000000000000005550.10000000000000000555(same)%.40eof 0.11.0000000000000000555000000000000000000000e-011.0000000000000000555111512312578270211816e-01%.0fof 2^10012676506002282294014967000000001267650600228229401496703205376%.0fof 67108865.56710886567108866So a title's
"%.0f%%"or"%.1f"text can come out one digit different, for example a score or timer that sits on a .5 or .25 value.Measured rules. I read these from the outputs of three titles'
libc.prx, not by translating its code:kbe thefrexpbinary exponent times 30103 / 100000, truncated (an estimate of the decimal exponent). The console keeps the exact decimal digits down to position4 * floor(k / 4) - 20and prints zeros after them. That is 20 to 24 significant digits, aligned to groups of four. This rule predicts the kept-digit count of 112,609 of 112,612 sampled%.45eoutputs.kreaches 8, which is from 2^26 up. Below that, every exact tie rounds up. A tie probe over binary exponents -43…53, at every tie position and in both%eand%f, matches with no exceptions.This PR formats finite
doubleandlong doublee/E/f/F/g/Gwith those rules. A small big-integer routine generates the exact digits: division by 10^9 for the integer part, multiplication by 10^9 for the fraction. The result is the same on every host.RequiresGuestFormattingnow also routes these conversions toFormatWindows, so Linux uses the same code. The flag/width/precision parsing that%aused moves intoParseFloatSpecandPadFloat, which both conversions share.Remaining difference. The console computes the kept digits in extended precision, so its last kept digit is sometimes one unit lower than the exact digit. That affects about 7 % of outputs with more than 17 significant digits;
%fof 1e22 is9999999999999999999999.000000there. Matching it would mean reproducing the console's arithmetic step by step, so this PR keeps exact digits and records the gap as technical debt. Every output with up to 17 significant digits matches.Tested
Current Linux refresh:
182bd6aa78842891f29e00bf113524775a6b897bon 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 one decimal-formatting commit. 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. A final-stack Linux routing negative control reverts only the narrow decimal routing:guest_formattingthen prints0instead of1for%.0fof 0.5 and fails; wide/stdio groups still pass. The exact final head was restored, rebuilt and passes 3/3. This is an integration control, not a standalone-parent comparison. 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
2f7dcf59c7950119cafaf13a52bc9ec796eb85f9is 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 b1dd830, on #9699's head 184733f (main3bbd232).Differential run. A scratch loader runs a title's decrypted
libc.prxnatively. It compares that copy'ssnprintfwith this build'ssnprintf_nid_postfixon 600,000 random formats: random flags, width, precision 0–29,e/E/f/F/g/Gwith and withoutL, and values from random bits, binary fractions, decimal fractions, a mid-range exponent and small integers.main-basedThe copies bundled with PPSA07923, PPSA05916 and PPSA13934 give identical counts. A second seed gives 0 of 408,691 at ≤ 17 digits, against 3,173 for
main.guest_formatting. The newCheckDecimalFloathas 29 console-measured cases:0.1,2^100, the smallest subnormal, a value nearDBL_MAXthat keeps four digits fewer);#,+and0flags;%gstyle switching and999.5carrying to1e+03;long doublecases, including0x1p-16445L.The libc formatting, scanning, stream, wide-character and string tests (34) pass in three runs out of three. With the base's
WindowsFormatting.hppandFormatting.cppand this test,guest_formattingaborts.Micro-benchmark. Of
snprintf_nid_postfixalone, not a title trace:%.2f,%g,%eof UI-range values take about 0.41 µs per call against about 1.2 µs onmain.%.2fof random-bit doubles takes 1.7 µs against 12 µs, since the console keeps at most 24 digits.python tools/check_conventions.py --base origin/mainandgit diff --checkpass.Overlap. Earlier code comparisons with fix(libc): accept printf argument positions above 99 #9552, fix(libc): follow snprintf_s and sscanf_s constraints as measured on a PS5 #9087 and fix(libc): match title printf behavior on Windows #3987 were clean; the debt entries overlap fix(libc): accept printf argument positions above 99 #9552, fix(libc): convert multibyte text as UTF-8 like the console's C locale #8855 and fix(libc): follow measured wide printf behavior #5303. The latest review requests refreshing the debt entry against current main. fix(libc): format wide %a, %e, %f and %g with the narrow console rules #9927 builds on this formatter and adds the wide decimal path; retain its formatter and tests when refreshing that dependent branch. fix(libc): encode each UTF-16 unit of a narrow %ls on its own, as titles' libc.prx does #9939 independently changes narrow
%lsUTF-16 code-unit encoding. It sharesWindowsFormatting.hpp,core/libs/tests/Formatting.cppanddocs/dev/debt/libc.md; preserve both the decimal formatter/tests and fix(libc): encode each UTF-16 unit of a narrow %ls on its own, as titles' libc.prx does #9939's code-unit encoding/tests and debt text in either landing order. This is a static overlap review, not a combined-build result; fix(libc): encode each UTF-16 unit of a narrow %ls on its own, as titles' libc.prx does #9939 is not a functional prerequisite.Linux review (not an author-run product build). Dom3005 tested submitted head
b5e461750merged with main24c6cc33fon Ubuntu 26.04/GCC 15/glibc 2.43 in Docker/WSL2.guest_formattingfails in prerequisite fix(libc): format %a like the console on Windows #9699'sCheckHexFloat, because finite%astill routes to glibc on Linux. Removing only that call makes the remaining suite pass, supporting this PR's decimal cases but not a passing full suite. That historical failure is addressed by the retainedCheckHexFloatand the Linux production-route fix in prerequisite head4d3c9a73fa; the exact-head focused rerun below passes. The broader 19-case Linux libc selection now passes three repetitions at this exact head (see the broad Linux result below). Original failure details.Refresh (Windows complete; the broader 19-case Linux selection also passes at this head): fix(libc): format %a like the console on Windows #9699 and this branch are rebased onto
main895f47f and fix(libc): format wide %a, %e, %f and %g with the narrow console rules #9927 onto this head. On Windows the 34 formatting, scanning, stream, wide-character and string tests pass in three runs out of three on 4d3c9a7, d9653a1 and 72e9e54 (GCC 15.2.0 UCRT r7, Release). fix(libc): format %a like the console on Windows #9699's new commit routes%a/%Athrough the guest formatter on Linux, which addresses theCheckHexFloatfailure in the Linux report above; that report is for the older head. A fresh Linux run ofd9653a15e3passes both complete formatting executables, as recorded below. No console run is claimed. NaN and infinity still use the host. The wide printf family still uses the host in this branch; dependent fix(libc): format wide %a, %e, %f and %g with the narrow console rules #9927 changes its finite decimal path.Linux (reviewer run): MarcZX10 ran a focused Linux check in an existing configured Release build with GCC 12:
guest_formattingandguest_wide_formattingpassed 2/2 with the formatting and test sources of fix(libc): format %La like titles' libc.prx does #9958, which contains this PR and fix(libc): format %a like the console on Windows #9699. 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
d9653a15e3cca7746a2fce60f8ca51a2a5bc4bb4: 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.Broader Linux validation (exact head
d9653a15e3cca7746a2fce60f8ca51a2a5bc4bb4): 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 fix(libc): format wide %a, %e, %f and %g with the narrow console rules #9927 has a separate stream-test expectation failure under investigation; these passes do not establish that dependent branch passes.Independent Linux validation (attributed, no local rerun): Dextroid17 tested exact head
2f7dcf59c7and its clean merge onto maind284c98b2eon CachyOS / kernel7.3.0-4 / GCC16.2.1 / glibc2.44, Release, SPIRV-Tools off. Bothguest_formattingandguest_wide_formattingpass three repetitions on each tree. Reverting only this PR's implementation commit5291860811while keeping its tests and #9699 makes the first decimal regression fail:%.0fof0x1p-1returns[0]instead of[1];CheckHexFloatstill passes. Restoring the implementation passes. Wide formatting passes with or without that narrow-format change, consistent with its separate fix in #9927.On the merged tree the reporter ran the full suite: 1,971 passed,26 skipped,3 failed of2,000. All616 executed
guest_*tests passed. The three failures are theagc_driver_sample_order*tests on their RTX3080Ti and reproduce on plain maind284c98b2ein three runs each; lavapipe passes or skips them. This is an attributed exact-head/merged-tree CPU regression and baseline-failure report, not an all-green suite, a local reproduction, or a title/console/performance result.Checklist
main: the fix(libc): format %a like the console on Windows #9699 → fix(libc): round and cap %e, %f and %g as titles' libc.prx does #9916 stack is rebased ontomain895f47f (fix(libc): format %a like the console on Windows #9699 at 4d3c9a7, this PR at d9653a1, dependent fix(libc): format wide %a, %e, %f and %g with the narrow console rules #9927 at 72e9e54), and the focused suite was rerun on Windows on each head; both complete formatting executables also pass on Linux at each exact head; the broader 19-case Linux libc selection also passes three repetitions at this exact head (see Tested)NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)AI-assisted (Claude Code).