feat(libc): implement the Dinkumware _Stod, _Stoll, _Sin and _Log helpers #8376
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8376"
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 hypermoist on 2026-10-20T11:46:07Z.
What
Implements seven absent Dinkumware helpers from
libSceLibcInternal. CUSA00223 (#8214) imports_Stod,_Stoll,_Log,_FLogand_Sin. The evidence is the decryptedlibSceLibcInternal.sprx, plus a differential run that loads that module on the host and calls its exports directly.Dispatchers (each body is a branch and a tail call to a public export):
_Sin(cCXjU72Z0Ow)test edi, edi: non-zero callscos, zero callssincos_nid_postfixorsin_nid_postfix_FSin(ZtjspkJQ+vw)cosf/sinf_LSin(m-Bu5Tzr82A)cosl/sinl_Log(zXCi78bYrEI)log10, 0 callslog, < 0 callslog2_FLog(jjjRS7l1MPM)log10f/logf/log2f_Stoll(7pNKcscKrf8)_Stollx(s, end, base, 0)strtoll_nid_postfix; identical to the console'sstrtollin value, end pointer andERANGEfor every probed inputOnly real dispatchers are included:
_LLogis a real implementation in the firmware, not a dispatcher, so it is left out._Stod(c41UEHVtiEA) is_Stodx(s, end, pten, 0). Run against the console module, it behaves as follows:10^(exponent + pten), so the scale is applied before rounding. For example,"-2.25e3"with 300 is-0x1.a3f7f806a8135p+1007, notstrtod * 1e300."1e-400"with 300 is1e-100with no error."5"with 2^40 overflows toHUGE_VALwithERANGE.ERANGE. Text that overflows on its own but is brought back into range by the scale is rescaled:"1e400"with -100 is1e300with no error.infandnanpass through unscaled ("inf"text sets noERANGE, so it is not mistaken for an overflow), the end pointer isstrtod's, and text without a number gives 0.The implementation reparses the consumed text with the exponent rewritten, through
strtod_nid_postfix, and restores the guesterrnobetween the two parses. The firmware's hexadecimal path with a non-zero scale does not follow a simple rule (0x3with -1 gives0.29999999999999999), so that one path throwsNotImplemented_nid_no_patch; unscaled hexadecimal works. The throw is recorded indocs/dev/debt/libc.md.The console's
strtodand_Stodleaveerrnoclear for a non-zero subnormal result; #8379 (merged) made upstream'sstrtoddo the same, so_Stodfollows it throughstrtod_nid_postfix.Tested
Linux (CachyOS, GCC, Release). The new
guest_dinkumware_internalstest passes. Its_Stodexpectations, including the bit patterns anderrnovalues, are the console module's outputs from the differential run. It also checks the 64-bit scale, an overflow rescaled into range,_Stollsaturation andERANGE, and every dispatch branch.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)_Stod,_Stoll,_Log,_FLogand_Sin; not run with the title🤖 Generated with Claude Code
https://claude.ai/code/session_01RbLgECLQ2bpDM7oe2urGZK
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-20T11:46:47Z.
Progress report (
eea640a→e321a04)📈 System libraries: 62.87% (+0.03%, +6 implemented, +1 declared functions)
✅ 6 implemented
_FLog_nid_postfix_FSin_nid_postfix_LSin_nid_postfix_Log_nid_postfix_Sin_nid_postfix_Stoll_nid_postfix🆕 1 declared as stubs
_Stod_nid_postfixImported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T22:48:52Z.
@hypermoist thanks. The dispatchers match the console module (
_Sinsends a non-zero quadrant tocos,_Logpickslog10/log/log2by sign, and_Stod/_Stolltail-call thexvariants with 0), and the test passes on Linux. Three changes:DinkumwareInternals.cpp:42:_Stod_nid_postfix(const char* text, char** end, long pten). The guest'slongis 64 bits, but on Windowslongis 32 bits, so the top half of the scale is dropped. With the Windows build,_Stod("1", &end, 4294967297)returns 10 with errno 0, while Linux returns inf with ERANGE. Please takestd::int64_t ptenas the other guest-long exports do (strtol,labs,ftell), change the test's declaration to match, and add a case with a scale above 2^32 (the current largest, 2147483647, fits in 32 bits).DinkumwareInternals.cpp:47: the!std::isfinite(value)early return also skips an inf that came from digits overflowing before the scale._Stod("1e-400", &end, 300)gives 1e-100, but_Stod("1e400", &end, -100)gives inf with ERANGE, where the description's rule (digits times 10^(exponent + pten), rounded once) gives 1e300. nikowolf123's suggestion on #8384 (rescale when the inf came with ERANGE;"inf"text sets no ERANGE) covers it. A test case for it, with the value checked against the console module, would pin it.docs/dev/debt/libc.md(AGENTS.md: "throw and record it in docs/dev/debt/.md"), with the0x3/ -1 data point from the description.After that, the bar is a full CI run with
guest_dinkumware_internalspassing on Linux and Windows.Imported from boykopovar/AnyPS5. Originally posted by hypermoist on 2026-10-20T23:11:54Z.
@oneandonlydean the three points also apply here and are fixed on this branch:
_Stodtakesstd::int64_t pten, and its test declaration and helper match. New vector:"5"with a scale of 2^40 gives HUGE_VAL with ERANGE, where a 32-bit scale would have been cut to 0._Stod("1e400", -100)is 1e300 (checked against the firmware)."inf"text sets no ERANGE and is not scaled. There is also a"0.01e41"with -2 → 1e37 vector.docs/dev/debt/libc.mdentry. It sits before "Long double math in MathExact.cpp" so it doesn't touch lines other open PRs edit.#8384 has merged these changes and carries the same fixes for
_Stodx/_Stofx/_Stoldx/_Stolx/_Stoulx.