fix(libc): match title libc.prx for hexadecimal strtod underflow #12291
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12291"
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 B-Howell on 2026-10-28T07:50:05Z.
What
Hexadecimal
strtodandwcstodnow follow thelibc.prxthat 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) bundledlibc.prx(SHA-256a485b34ef160ee635d357f21f4a93586bed1cf499b82918c734dcfd78b04e443):errnois left alone (unless it overflows, which setsERANGE).ERANGE. Between 2^-1075 and 2^-1074 the result is 2^-1074 only from 2^-1075 * (1 + 2^-52) up, otherwise a signed zero. So0x1.8p-1075and0x1.0000000000001p-1075give 2^-1074, but0x1p-1075,0x1.00000000000001p-1075and0x1.0000000000000fp-1075give 0.wcstodgives the same bits, end positions anderrnoasstrtod.How it was measured: a small loader maps that decrypted
libc.prx, applies its relocations, supplies__errorand calls itsstrtodandwcstodnatively 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 thatlibc.prxon 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.wcstodoutput was byte-identical tostrtodon both sets.The main bug: the old check classified only results equal to 2^-1074, and used
std::strtoldto recover the exact value. That keeps 64 bits, so0x1.fffffffffffffffffp-1075looked like 2^-1074 and kepterrno, 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,strtoldand decimal input are unchanged.docs/dev/debt/libc.md: thestrtodentry records that the hex rule rests on one title'slibc.prx, and that results of at least 2^-1074 come from the hoststrtod, where glibc 2.35 rounds some a unit low (for example0x3ffffffffffff5p-1077). The_Stod/_Stodxentry records thatlibSceLibcInternal.sprxis unverified for hexadecimal underflow and follows this rule here.Tested
mainb99bbebacd):guest_strtod_subnormal,guest_math,guest_dinkumware_internals,guest_wide_strings4/4 passed. Strings.cpp and GuestStrtodSubnormal.cpp rebuilt with 0 warnings.main's Strings.cpp with the new tests abortsguest_strtod_subnormalat "long hexadecimal just below the smallest subnormal".strtodandwcstod) passed in 20.25 s. A further 36 boundary inputs (endptr,0xwith no digits,0x.p1, uppercaseP/X, signs,-0x0p0, leading and fraction zeros, the band edges with sticky bits) passed. They gave the same results as thatlibc.prxrun directly.strtodrounds the glibc cases from the debt entry (0x3ffffffffffff5p-1077,0x20000000000003p-1076and four others) the same as thatlibc.prx.main660a0b306d(82c8a51391), which only changes libkernel_sys files.tools/check_conventions.py --base origin/mainpasses.Checklist
main; no other open PR implements the same functionsNotImplemented_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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T08:49:36Z.
Review: APPROVED
Reviewed the hexadecimal subject parser and underflow decision against the documented title-bundled
libc.prxrule. 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 matchingwcstodbits/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.