libc: titles' own libc.prx strtod/strtof differ from libSceLibcInternal for subnormal ERANGE and strtof NaN #9691
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 JJenkx on 2026-10-22T08:39:09Z.
strtodandstrtoffollow the console'slibSceLibcInternal.sprx, measured from a payload process (b455c751bband thestrtod, strtof, strtoldentry indocs/dev/debt/libc.md, which says "that a title's ownlibc.prxdoes the same is assumed"). But titles import these functions from thelibc.prxthey ship. PPSA13934, PPSA05916 and PPSA20423 all bind2vDqwBlpF-o(strtod) tolibc.prx. And that module differs in two ways.I ran the decrypted
libc.prxof PPSA13934, PPSA07923 and PPSA05916 natively on Windows: a loader maps the ELF, applies its relocations and supplies__error. I compared it with this libc (mainat theStrings.cppofa1f95a523f, Windows build) on 200,082 strings: about 80 hand-picked edge cases plus random decimal and hex forms. All three copies give the same results.Values match.
strtodgives identical bits and end positions for every input, including thenan(...)payloads.errnofor subnormal results. The bundledlibc.prxsetsERANGEwhere this libc, followinglibSceLibcInternal, leaveserrnoalone:libc.prxstrtod("4.9e-324"),("1e-310"),("2.2250738585072011e-308")ERANGEstrtodof the exact 751-digit decimal expansion of 2^-1074 or 2^-1023ERANGEstrtod("0x1.8p-1075")0x1,ERANGEstrtod("0x1p-1074"),("0x1.ffffffffffffe8p-1023")strtof("1e-45")(inexact)0x00000001,ERANGEstrtofof the exact decimal 2^-1490x00000001, errno 0So decimal
strtodreportsERANGEfor any subnormal result, even an exact one.strtofonly reports it for an inexact one. Hexstrtodreports it for some inexact subnormals but not others. I did not pin down that rule.strtofwith NaN and with a failed conversion after a sign. The debt entry givesstrtofthe default NaN and the letters-digits-underscore sequence, fromlibSceLibcInternal. The bundledstrtofinstead reads the sequence as itsstrtoddoes:libc.prxstrtof("nan(a b)")0x7fc0000a, end 80x7fc00000, end 3strtof("nan( )"),("nan(-)"),("nan(\t)")0x7fc00000, end 6strtof("-."),("- 1"),("-x")(no conversion)-0.0(0x80000000), end 0+0.0, end 0strtodof-.gives+0.0on both.This is for whoever owns these entries to decide (@hypermoist): which module's behaviour this libc should follow for these NIDs, or both if the modules can be told apart at import. Neither is likely to change a title's behaviour: a title would have to check
errnoafter parsing a subnormal, or parse a NaN with a payload throughstrtof. I'm not opening a PR for it. A full run log is available on request.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by hypermoist on 2026-10-22T13:35:24Z.
Thanks for the survey. My view: these NIDs come from the title's own
libc.prx, since the firmware has no systemlibcmodule andlibSceLibcInternalhere doesn't exportstrtofat all. So thelibc.prxresults should win. I checked two more builds by running them side by side with this libc on a Linux host: PPSA08427 (J03547016) and PPSA03671 (J03848509).strtofandwcstof: both builds agree with your three titles.ERANGEonly when inexact.nan(...)is consumed as bystrtodand keeps its sign.-gives-0.0.ERANGErules. It already had the-0.0results, and I re-checked those on both builds. ThestrtofNaN payload isn't reproduced. It depends on the digit count:nan(123)gives0x7fc00123,nan(000000123)gives0x7fc00012,nan(0000000123)gives0x7fc00001. I recorded it in a debt entry instead.strtodsubnormals depend on the build: J03547016 setsERANGE(as your copies do), while J03848509 andlibSceLibcInternaldon't. I've leftstrtodas it is onmain. If you think the older behaviour is the more common one in shipped titles, I can change it.Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-22T13:41:18Z.
@hypermoist thanks, that settles
strtof. For decimalstrtod, here is a count over the title copies I have: ninelibc.prxbuilds, nine different SHA-256s, run natively on Windows.libc.prxsha256 (prefix)All nine set
errnotoERANGE(34) forstrtod("1e-310"),("4.9e-324")and("2.2250738585072011e-308")(subnormal results) and for("1e-400")(zero). All nine leave it 0 for("1e-300"). The values are the same in all nine. So 9 of 9 behave like your J03547016, and J03848509 is the only exception so far. I'd lean towards settingERANGEfor every decimal subnormal, but it's your call.AI-assisted (Claude Code).