Skip to content

fix(libc): match title libc.prx for hexadecimal strtod underflow - #12291

Merged
oneandonlydean merged 4 commits into
boykopovar:mainfrom
B-Howell:claude/fix-issue-9691-hex-strtod-erange
Oct 28, 2026
Merged

oneandonlydean merged 4 commits into
boykopovar:mainfrom
B-Howell:claude/fix-issue-9691-hex-strtod-erange

Conversation

@B-Howell

Copy link
Copy Markdown
Contributor

What

Hexadecimal strtod and wcstod now follow the libc.prx that titles ship when the exact value is below 2^-1074, the last open item of #9691. The rule, measured from God of War Ragnarök's (PPSA08329) bundled libc.prx (SHA-256 a485b34ef160ee635d357f21f4a93586bed1cf499b82918c734dcfd78b04e443):

  • An exact value of at least 2^-1074 is correctly rounded and errno is left alone (unless it overflows, which sets ERANGE).
  • A nonzero exact value below 2^-1074 sets ERANGE. Between 2^-1075 and 2^-1074 the result is 2^-1074 only from 2^-1075 * (1 + 2^-52) up, otherwise a signed zero. So 0x1.8p-1075 and 0x1.0000000000001p-1075 give 2^-1074, but 0x1p-1075, 0x1.00000000000001p-1075 and 0x1.0000000000000fp-1075 give 0.
  • wcstod gives the same bits, end positions and errno as strtod.

How it was measured: a small loader maps that decrypted libc.prx, applies its relocations, supplies __error and calls its strtod and wcstod natively in a Linux (WSL2) host process. This is a title-shipped SDK module run on a PC, not a console measurement. An exact rational model of the rule above matches every result of that libc.prx on 260,055 hexadecimal inputs (200,046 hand-built edge and boundary cases plus 60,009 random forms; 9,735 of them between 2^-1075 and 2^-1074), with 0 mismatches. wcstod output was byte-identical to strtod on both sets.

The main bug: the old check classified only results equal to 2^-1074, and used std::strtold to recover the exact value. That keeps 64 bits, so 0x1.fffffffffffffffffp-1075 looked like 2^-1074 and kept errno, and values just above 2^-1075 were rounded by the host instead of truncated to zero. The new code reads the subject itself: the first 64 significant bits plus a sticky bit, and an exponent that saturates at 2^62 (digit runs add at most about ±2^59, so the sum cannot overflow). strtof, strtold and decimal input are unchanged.

docs/dev/debt/libc.md: the strtod entry records that the hex rule rests on one title's libc.prx, and that results of at least 2^-1074 come from the host strtod, where glibc 2.35 rounds some a unit low (for example 0x3ffffffffffff5p-1077). The _Stod/_Stodx entry records that libSceLibcInternal.sprx is unverified for hexadecimal underflow and follows this rule here.

Tested

  • Windows 11 Pro 10.0.26300, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release, at 864f310 (this branch on main b99bbeb): guest_strtod_subnormal, guest_math, guest_dinkumware_internals, guest_wide_strings 4/4 passed. Strings.cpp and GuestStrtodSubnormal.cpp rebuilt with 0 warnings.
  • Control: main's Strings.cpp with the new tests aborts guest_strtod_subnormal at "long hexadecimal just below the smallest subnormal".
  • One-off runs, not committed: the 1,048,576-digit tests rerun with 300,000,000-digit runs (integer and fraction digits, at and past the boundaries, saturated exponents; strtod and wcstod) passed in 20.25 s. A further 36 boundary inputs (endptr, 0x with no digits, 0x.p1, uppercase P/X, signs, -0x0p0, leading and fraction zeros, the band edges with sticky bits) passed. They gave the same results as that libc.prx run directly.
  • The Windows host strtod rounds the glibc cases from the debt entry (0x3ffffffffffff5p-1077, 0x20000000000003p-1076 and four others) the same as that libc.prx.
  • Ubuntu 22.04.1 (WSL2), GCC 11.4.0, glibc 2.35, Ninja, Release, at 864f310: the same 4 tests passed, 0 warnings. No other PR was needed.
  • Rebased onto main 660a0b3 (82c8a51), which only changes libkernel_sys files. tools/check_conventions.py --base origin/main passes.

Checklist

🤖 Generated with Claude Code

B-Howell and others added 3 commits October 28, 2026 03:49
Classify hexadecimal strtod and wcstod input from its own digits rather
than a long double approximation. As measured on God of War Ragnarok's
bundled libc.prx, ERANGE is set only on overflow or when the exact value
is below 2^-1074, and a value between 2^-1075 and 2^-1074 becomes the
smallest subnormal only from 2^-1075 * (1 + 2^-52) up.

Refs boykopovar#9691

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Keep only the gaps: the rule is measured on one title-bundled libc.prx,
and on Linux glibc 2.35's strtod rounds some hexadecimal subnormal
results a unit low.

Refs boykopovar#9691

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The explicit binary exponent stopped accumulating near 1e9 while the
digits add 4 per character without bound, so a subject with a few
hundred million digits was classified against the wrong exponent:
0x1 followed by 3e8 zeros and p-1200000005000 kept errno, and a long
zero fraction with p+1000000000000 underflowed instead of overflowing.
Saturate the explicit exponent at 2^62, beyond what any addressable
digit run can offset, so the sum never overflows or changes sign.

Record that _Stod and _Stodx follow the title libc.prx rule for
hexadecimal underflow, unverified for libSceLibcInternal.

Refs boykopovar#9691

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 11892 docs/dev/debt/libc.md L126

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.

Pull request Shared files not compared
PR 5021 core/libs/prx/libc/src/Strings.cpp
docs/dev/debt/libc.md
PR 6713 docs/dev/debt/libc.md
PR 7081 docs/dev/debt/libc.md
PR 7386 docs/dev/debt/libc.md
PR 7447 docs/dev/debt/libc.md
PR 7648 docs/dev/debt/libc.md
PR 7715 docs/dev/debt/libc.md
PR 8150 docs/dev/debt/libc.md
PR 8937 docs/dev/debt/libc.md
PR 9371 docs/dev/debt/libc.md
PR 9447 docs/dev/debt/libc.md
PR 9526 docs/dev/debt/libc.md
PR 9929 docs/dev/debt/libc.md
PR 10002 docs/dev/debt/libc.md
PR 10253 docs/dev/debt/libc.md
PR 10324 docs/dev/debt/libc.md
PR 10433 docs/dev/debt/libc.md
PR 10620 docs/dev/debt/libc.md
PR 11332 docs/dev/debt/libc.md
PR 11625 docs/dev/debt/libc.md
PR 11849 docs/dev/debt/libc.md
PR 11850 docs/dev/debt/libc.md
PR 11870 docs/dev/debt/libc.md
PR 11872 docs/dev/debt/libc.md
PR 11969 docs/dev/debt/libc.md
PR 12397 docs/dev/debt/libc.md

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the hexadecimal subject parser and underflow decision against the documented title-bundled libc.prx rule. The 64-bit significand plus sticky bit and saturated exponent retain the boundary information needed for the measured threshold; the tests cover below/at/above the cutoff, signed zero, normal transition, overflow, very long runs, and matching wcstod bits/end pointers/errno. The author reports a direct module comparison over 260,055 inputs and Windows/WSL focused runs; hosted Windows, registration, relinker, ASan, and write-watch checks pass, while hosted Linux is skipped. The PR clearly limits the claim to one title build run on a host, not a console. No blocking issue found.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

@B-Howell the code and the measurement look right to me. One conventions point: docs/dev/debt/libc.md names the game ("God of War Ragnarök") in both the strtod and the _Stod… entries. Debt docs may cite title IDs but not game names, so could both read PPSA08329 (keeping the SHA-256)? Also, #11892 edits the same strtod debt line, so whichever of the two merges second will need a small rebase there.

@oneandonlydean oneandonlydean self-assigned this Oct 28, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@B-Howell

Copy link
Copy Markdown
Contributor Author

@oneandonlydean Done in a252638. Both debt entries (strtod and _Stod…) now cite PPSA08329 with the SHA-256 kept, and there's no game name left in docs/dev/debt. Only that doc changed, and check_conventions.py passes. I'll rebase whichever lands second with #11892.

AI-assisted (Claude Code).

@B-Howell

B-Howell commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor Author

Manual follow-up to the skipped comparisons in the overlap report (comment6463890106). Reviewed target head: a252638976717e8a4e23058c606cd6ed16962cbd.

I inspected the listed shared-file patches for all 26 candidates. No duplicate target export/implementation was found in this scoped review. The table records the specific shared-file changes and integration requirements; shared debt/header changes still need to preserve both sides. This is not a claim that every pair merges cleanly or that a combined branch has been built/tested.

This follow-up addresses the skipped-comparison request only. Existing CI limitations, dependency ordering and outstanding re-review requirements remain in force; approvals or tests from older heads do not become current-head evidence through this audit.

Delta review: added #10002 (9bbf84ead3b761fba399c40788bb783b98934e64) and #12397 (f2548977ea559a13c157c8ad0e5109983745dccd) at the unchanged target head above. Both new pairs share only docs/dev/debt/libc.md; the new rows below describe those exact debt patches. Earlier rows retain their recorded candidate heads. This supplement does not re-review their newer heads, establish a landing agreement or claim a clean merge/combined build/test.

Candidate heads, shared files and manual dispositions
Candidate Reviewed head Shared files Disposition
#5021 151294f979ab00aaff2f702314425caf61a72790 Strings.cpp, libc.md Strings.cpp adds Darwin ConvertInteger/integer wrappers and aarch64 long-double guards, and removes strlen from this file; the new helper sits adjacent to ParseFloat. It does not duplicate target hexadecimal-underflow rounding. Debt-only statements in libc.md concern ARM64 native aggregate builds reuse the integer, binary32/binary64 and UTF-16 string implementations. The x87 strtold/. These are documentation claims, not independently reviewed candidate implementations. No scoped hexadecimal-underflow implementation/debt duplicate identified. Preserve Darwin integer helper/aarch64 guards together with hexadecimal ParseFloat rule; recheck combined narrow/wide hexadecimal tests on supported platforms.
#6713 668d51adbdb91248f49fdd28acbfd0b85adb98cd libc.md Debt-only statements in libc.md concern Application heap without process parameters. These are documentation claims, not independently reviewed candidate implementations. No scoped hexadecimal-underflow implementation/debt duplicate identified. Preserve both debt changes; no implementation integration inferred from debt-only scope.
#7081 e6f5d4c71b6ff42a43ee1c90b9b3fc912efdad7b libc.md Debt-only statements in libc.md concern localeconv; set_constraint_handler_s. These are documentation claims, not independently reviewed candidate implementations. No scoped hexadecimal-underflow implementation/debt duplicate identified. Preserve both debt changes; no implementation integration inferred from debt-only scope.
#7386 bf7352321cf85d1bfdfe402f3fba7b2d90c683eb libc.md Debt-only statements in libc.md concern The scanf family. These are documentation claims, not independently reviewed candidate implementations. No scoped hexadecimal-underflow implementation/debt duplicate identified. Preserve both debt changes; no implementation integration inferred from debt-only scope.
#7447 dead12ebad24a3c4b01a05c14ab60cc06aacaf7d libc.md Debt-only statements in libc.md concern app0.zar. These are documentation claims, not independently reviewed candidate implementations. No scoped hexadecimal-underflow implementation/debt duplicate identified. Preserve both debt changes; no implementation integration inferred from debt-only scope.
#7648 bdf0d319632cb330c4ca909fe9d76577d6e58ae9 libc.md Debt-only statements in libc.md concern std::_Throw_C_error. These are documentation claims, not independently reviewed candidate implementations. No scoped hexadecimal-underflow implementation/debt duplicate identified. Preserve both debt changes; no implementation integration inferred from debt-only scope.
#7715 783fa9b83f5f0ac617d4b0f05321a34c1279cb7f libc.md Debt-only statements in libc.md concern getenv, setenv, unsetenv, putenv. These are documentation claims, not independently reviewed candidate implementations. No scoped hexadecimal-underflow implementation/debt duplicate identified. Preserve both debt changes; no implementation integration inferred from debt-only scope.
#8150 6a9b1285c596904698bb0511c14f7c04302b708b libc.md Debt-only statements in libc.md concern fopen of /dev/random and /dev/urandom. These are documentation claims, not independently reviewed candidate implementations. No scoped hexadecimal-underflow implementation/debt duplicate identified. Preserve both debt changes; no implementation integration inferred from debt-only scope.
#8937 27aeb1feb4a533bb0d8ca20b9450ea4c0cc45efc libc.md Debt-only statements in libc.md concern fesetenv. These are documentation claims, not independently reviewed candidate implementations. No scoped hexadecimal-underflow implementation/debt duplicate identified. Preserve both debt changes; no implementation integration inferred from debt-only scope.
#9371 9ea4c6561be22466166fb26fa61cd2eb0d23f2cf libc.md Debt-only statements in libc.md concern Windows link before ... These are documentation claims, not independently reviewed candidate implementations. No scoped hexadecimal-underflow implementation/debt duplicate identified. Preserve both debt changes; no implementation integration inferred from debt-only scope.
#9447 2dc7b701a4d72515be281c8e469fb14c5a588d63 libc.md Debt-only statements in libc.md concern std::__sce_v2::_Thrd_hardware_concurrency, _Cnd_timedwait, chrono::steady_clock::now_v1_compat. These are documentation claims, not independently reviewed candidate implementations. No scoped hexadecimal-underflow implementation/debt duplicate identified. Preserve both debt changes; no implementation integration inferred from debt-only scope.
#9526 1da5b7cd5c8904a515d275f1677f7fbaedf8fe34 libc.md Debt-only statements in libc.md concern std::__sce_v2::setw; std::__sce_v2::_Fiopen; std::__sce_v2::_Xregex_error. These are documentation claims, not independently reviewed candidate implementations. No scoped hexadecimal-underflow implementation/debt duplicate identified. Preserve both debt changes; no implementation integration inferred from debt-only scope.
#9929 57c6df1f5620c34835e450490fbc574c854e74d1 libc.md Debt-only statements in libc.md concern syslog. These are documentation claims, not independently reviewed candidate implementations. No scoped hexadecimal-underflow implementation/debt duplicate identified. Preserve both debt changes; no implementation integration inferred from debt-only scope.
#10253 5b96a875888056c5bd758270593be17d1a3f5542 libc.md Debt-only statements in libc.md concern asin and acos. These are documentation claims, not independently reviewed candidate implementations. No scoped hexadecimal-underflow implementation/debt duplicate identified. Preserve both debt changes; no implementation integration inferred from debt-only scope.
#10324 5e32fdc2a5ccd4050a6a2e7f46f94e31966f8cca libc.md Debt-only statements in libc.md concern fwide. These are documentation claims, not independently reviewed candidate implementations. No scoped hexadecimal-underflow implementation/debt duplicate identified. Preserve both debt changes; no implementation integration inferred from debt-only scope.
#10433 1e32d23a9c221fffeca70ba8a7f709b0057dbd77 libc.md Debt-only statements in libc.md concern fopen and freopen. These are documentation claims, not independently reviewed candidate implementations. No scoped hexadecimal-underflow implementation/debt duplicate identified. Preserve both debt changes; no implementation integration inferred from debt-only scope.
#10620 2a999da21f5650bfb9aacf88c0d0194d3c5d66ad libc.md Debt-only statements in libc.md concern fopen and freopen of /dev/random and /dev/urandom. These are documentation claims, not independently reviewed candidate implementations. No scoped hexadecimal-underflow implementation/debt duplicate identified. Preserve both debt changes; no implementation integration inferred from debt-only scope.
#11332 793a55ba18497e36f1038242dae9d7e707641f35 libc.md Debt-only statements in libc.md concern snprintf and vsnprintf. These are documentation claims, not independently reviewed candidate implementations. No scoped hexadecimal-underflow implementation/debt duplicate identified. Preserve both debt changes; no implementation integration inferred from debt-only scope.
#11625 e97bbf045122e4326b0f5332a9844df37bd1d5dc libc.md Debt-only statements in libc.md concern app0.zar. These are documentation claims, not independently reviewed candidate implementations. No scoped hexadecimal-underflow implementation/debt duplicate identified. Preserve both debt changes; no implementation integration inferred from debt-only scope.
#11849 cd97f141d91cbd1e47f670a3d4eec4c1cfeed609 libc.md Debt-only statements in libc.md concern asinl. These are documentation claims, not independently reviewed candidate implementations. No scoped hexadecimal-underflow implementation/debt duplicate identified. Preserve both debt changes; no implementation integration inferred from debt-only scope.
#11850 663230eaafcdc8da7e52b6067e287261c335bb9b libc.md Debt-only statements in libc.md concern reallocalign. These are documentation claims, not independently reviewed candidate implementations. No scoped hexadecimal-underflow implementation/debt duplicate identified. Preserve both debt changes; no implementation integration inferred from debt-only scope.
#11870 3670a1509408a983806f09933d5be619263bb44b libc.md Debt-only statements in libc.md concern malloc_stats_fast. These are documentation claims, not independently reviewed candidate implementations. No scoped hexadecimal-underflow implementation/debt duplicate identified. Preserve both debt changes; no implementation integration inferred from debt-only scope.
#11872 21d5a977f993346c5f762d31eebfb15ce349f76f libc.md Debt-only statements in libc.md concern setjmp, longjmp. These are documentation claims, not independently reviewed candidate implementations. No scoped hexadecimal-underflow implementation/debt duplicate identified. Preserve both debt changes; no implementation integration inferred from debt-only scope.
#11969 560f498196e7db59ef8b4f41463105dadb96e15a libc.md Debt-only statements in libc.md concern setjmp, longjmp. These are documentation claims, not independently reviewed candidate implementations. No scoped hexadecimal-underflow implementation/debt duplicate identified. Preserve both debt changes; no implementation integration inferred from debt-only scope.
#10002 9bbf84ead3b761fba399c40788bb783b98934e64 libc.md Debt-only addition for asinhf/FreeBSD msun range reduction and title-libc survey differences; system-library and FMA results remain unverified. Separate from the strtod/_Stod-family entries. Preserve both debt edits and their measurement limits. No candidate implementation review, author-order agreement or combined test is established.
#12397 f2548977ea559a13c157c8ad0e5109983745dccd libc.md Debt-only changes to the narrow printf family and conversions entries plus a new printf length-modifiers entry. Separate from strtod/_Stod hexadecimal underflow; retain the #11892 debt-line landing seam and measured/unverified limits. Preserve all entries. No combined merge/build/test claim.

AI-assisted: yes (Codex).

@B-Howell

Copy link
Copy Markdown
Contributor Author

Follow-up to the actual compared conflicts in overlap comment6463890106, for this PR at a252638976717e8a4e23058c606cd6ed16962cbd.

I inspected the listed shared-file patches for 1 compared candidate at the heads below. This is separate from the earlier skipped-comparison review.

These scoped findings do not establish clean pairwise merges or a successful combined build/test. They do not clear other review, CI, dependency or current-head verification obligations.

@JJenkx For the shared strtod paragraph I propose #11892 first, then I will reconcile this PR onto it, preserve both decimal and hexadecimal qualifications, and rerun the focused narrow/wide regressions. Please confirm or propose another order. I will record the confirmed ordering dependency; the current landing watch remains active and this proposal is not an agreement.

AI-assisted: yes (Codex).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs fix error Closes an issue (Fixes #N) libc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

libc: titles' own libc.prx strtod/strtof differ from libSceLibcInternal for subnormal ERANGE and strtof NaN

3 participants