fix(libc): set ERANGE for decimal strtod subnormals #9833
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9833"
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 MarcZX10 on 2026-10-22T16:49:58Z.
What
Follows the title-bundled
libc.prxbehavior for decimalstrtodinputs that produce nonzero subnormal values: setERANGE, including when the decimal exactly represents the result. This is based on the nine distinctlibc.prxbuilds reported in #9691; two other builds and the systemlibSceLibcInternal.sprxleaveerrnounchanged. This updates thestrtodbehavior established by #8379 using the newer title-module evidence. Hexadecimalstrtodhandling is unchanged here because the title rule is not fully established.atofinherits the behavior through its existingstrtodcall.Adds a focused registered regression test for inexact and exact decimal subnormals, a negative value, a normal result, hexadecimal subnormal errno preservation, underflow to zero, and end-pointer results. The existing
guest_mathassertions are updated to match.This covers only the decimal
strtodpart of #9691; that issue also records unresolvedstrtofNaN payload behavior. Depends on #8865 because both changes touch the shared parser regression coverage; thestrtofchanges in that PR remain separate.Tested
Linux x86-64, GCC 12.2:
Strings.cppandGuestStrtodSubnormal.cppwith-ffunction-sections -fdata-sectionsand--gc-sections, failed against currentmainat the inexact-subnormal errno assertion, then passed with this change.GuestMath.cpppassesg++ -std=c++20 -Wall -Wextra -Werror -I core/libs -fsyntax-only.python3 tools/check_conventions.py --base upstream/main --head HEADpasses.git diff --check upstream/main...HEADpasses.The full project CMake build was not available in this container: the bundled SDL2 submodule has no
CMakeLists.txt, and system-dependency configuration cannot find SDL2. The normal SDL configuration also reports missing XRandR support.Checklist
main; no open PR implements decimalstrtodERANGE for nonzero subnormal results (#8865 covers the separatestrtofwork and is declared as a dependency for shared parser test integration)Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-22T18:17:15Z.
Review: COMMENTED
Checked against main
a6646f8464and FreeBSD 11.4contrib/gdtoa/strtod.c,gethex.c,gdtoaimp.handlib/libc/locale/wcstod.c:a6646f8464.Avoid_Underflow,scaleis set whenever the decimal scale is at least 256, which every subnormal result needs (the leading ≤16 digits are below 10^16). The end ofstrtod_lthen sets ERANGE whenever the exponent field is 0, with no inexact test. So exact subnormals get ERANGE too, and inputs that round up to DBL_MIN don't, exactly asmagnitude < DBL_MINdoes here.wcstodstill goes straight toParseFloat(Strings.cpp:701-702), sowcstod(u"1e-310")keeps errno whilestrtod("1e-310")now sets ERANGE. FreeBSD 11.4'swcstodconverts the string and callsstrtod_l, so there the two agree. Could the check live in a shared helper both use, or could the debt entry mentionwcstod? As far as I know, the titles' ownwcstodhasn't been measured.gethex.c, ERANGE is only set whenn = emin - e >= nbits, i.e. the exact value is below 2^-1074 and the result is 0 or the smallest denormal. That gives ERANGE for0x1.8p-1075(matching the console result reported above) and none for0x1p-1074(matching your new test). Inexact hex subnormals above 2^-1074 would keep errno. That could go in the debt line as the rule to verify.Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T20:29:42Z.
Review: COMMENTED
I reviewed the current head
5084be7aa7deb887259aacaebfdfdf4a07b0f57b, including the errno reset added after the independentstrtodcalls. The reported focused GCC harnesses and Windows differential run cover the identified regression; current hosted checks pass conventions, eligibility, labels, register-context, relinker, ASan, and write-watch jobs, while Linux and Windows product jobs are skipped by policy. I did not run the code locally. No further actionable issue found in this pass. #8865 remains declared for the shared parser test integration.