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

Closed
opened 2026-10-22 08:39:09 +00:00 by JJenkx · 2 comments
JJenkx commented 2026-10-22 08:39:09 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-22T08:39:09Z.


strtod and strtof follow the console's libSceLibcInternal.sprx, measured from a payload process (b455c751bb and the strtod, strtof, strtold entry in docs/dev/debt/libc.md, which says "that a title's own libc.prx does the same is assumed"). But titles import these functions from the libc.prx they ship. PPSA13934, PPSA05916 and PPSA20423 all bind 2vDqwBlpF-o (strtod) to libc.prx. And that module differs in two ways.

I ran the decrypted libc.prx of PPSA13934, PPSA07923 and PPSA05916 natively on Windows: a loader maps the ELF, applies its relocations and supplies __error. I compared it with this libc (main at the Strings.cpp of a1f95a523f, 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. strtod gives identical bits and end positions for every input, including the nan(...) payloads.

errno for subnormal results. The bundled libc.prx sets ERANGE where this libc, following libSceLibcInternal, leaves errno alone:

Input Bundled libc.prx Here
strtod("4.9e-324"), ("1e-310"), ("2.2250738585072011e-308") subnormal, ERANGE same value, errno 0
strtod of the exact 751-digit decimal expansion of 2^-1074 or 2^-1023 subnormal, ERANGE errno 0
strtod("0x1.8p-1075") 0x1, ERANGE errno 0
strtod("0x1p-1074"), ("0x1.ffffffffffffe8p-1023") subnormal, errno 0 errno 0
strtof("1e-45") (inexact) 0x00000001, ERANGE errno 0
strtof of the exact decimal 2^-149 0x00000001, errno 0 errno 0

So decimal strtod reports ERANGE for any subnormal result, even an exact one. strtof only reports it for an inexact one. Hex strtod reports it for some inexact subnormals but not others. I did not pin down that rule.

strtof with NaN and with a failed conversion after a sign. The debt entry gives strtof the default NaN and the letters-digits-underscore sequence, from libSceLibcInternal. The bundled strtof instead reads the sequence as its strtod does:

Input Bundled libc.prx Here
strtof("nan(a b)") 0x7fc0000a, end 8 0x7fc00000, end 3
strtof("nan( )"), ("nan(-)"), ("nan(\t)") 0x7fc00000, end 6 end 3
strtof("-."), ("- 1"), ("-x") (no conversion) -0.0 (0x80000000), end 0 +0.0, end 0

strtod of -. gives +0.0 on 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 errno after parsing a subnormal, or parse a NaN with a payload through strtof. I'm not opening a PR for it. A full run log is available on request.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5975988836 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/9691). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-22T08:39:09Z. --- `strtod` and `strtof` follow the console's `libSceLibcInternal.sprx`, measured from a payload process (b455c751bb and the `strtod, strtof, strtold` entry in `docs/dev/debt/libc.md`, which says "that a title's own `libc.prx` does the same is assumed"). But titles import these functions from the `libc.prx` they ship. PPSA13934, PPSA05916 and PPSA20423 all bind `2vDqwBlpF-o` (`strtod`) to `libc.prx`. And that module differs in two ways. I ran the decrypted `libc.prx` of PPSA13934, PPSA07923 and PPSA05916 natively on Windows: a loader maps the ELF, applies its relocations and supplies `__error`. I compared it with this libc (`main` at the `Strings.cpp` of a1f95a523f, 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.** `strtod` gives identical bits and end positions for every input, including the `nan(...)` payloads. **`errno` for subnormal results.** The bundled `libc.prx` sets `ERANGE` where this libc, following `libSceLibcInternal`, leaves `errno` alone: | Input | Bundled `libc.prx` | Here | |---|---|---| | `strtod("4.9e-324")`, `("1e-310")`, `("2.2250738585072011e-308")` | subnormal, `ERANGE` | same value, errno 0 | | `strtod` of the exact 751-digit decimal expansion of 2^-1074 or 2^-1023 | subnormal, `ERANGE` | errno 0 | | `strtod("0x1.8p-1075")` | `0x1`, `ERANGE` | errno 0 | | `strtod("0x1p-1074")`, `("0x1.ffffffffffffe8p-1023")` | subnormal, errno 0 | errno 0 | | `strtof("1e-45")` (inexact) | `0x00000001`, `ERANGE` | errno 0 | | `strtof` of the exact decimal 2^-149 | `0x00000001`, errno 0 | errno 0 | So decimal `strtod` reports `ERANGE` for any subnormal result, even an exact one. `strtof` only reports it for an inexact one. Hex `strtod` reports it for some inexact subnormals but not others. I did not pin down that rule. **`strtof` with NaN and with a failed conversion after a sign.** The debt entry gives `strtof` the default NaN and the letters-digits-underscore sequence, from `libSceLibcInternal`. The bundled `strtof` instead reads the sequence as its `strtod` does: | Input | Bundled `libc.prx` | Here | |---|---|---| | `strtof("nan(a b)")` | `0x7fc0000a`, end 8 | `0x7fc00000`, end 3 | | `strtof("nan( )")`, `("nan(-)")`, `("nan(\t)")` | `0x7fc00000`, end 6 | end 3 | | `strtof("-.")`, `("- 1")`, `("-x")` (no conversion) | `-0.0` (`0x80000000`), end 0 | `+0.0`, end 0 | `strtod` of `-.` gives `+0.0` on 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 `errno` after parsing a subnormal, or parse a NaN with a payload through `strtof`. I'm not opening a PR for it. A full run log is available on request. AI-assisted (Claude Code).
hypermoist commented 2026-10-22 13:35:24 +00:00 (Migrated from github.com)
Author
Contributor

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 system libc module and libSceLibcInternal here doesn't export strtof at all. So the libc.prx results 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).

  • strtof and wcstof: both builds agree with your three titles.
    • A decimal nonzero subnormal sets ERANGE only when inexact.
    • Hex never sets it for a nonzero subnormal, but does on underflow to zero and overflow.
    • nan(...) is consumed as by strtod and keeps its sign.
    • A failed parse after - gives -0.0.
  • #8865 changes: it now implements the ERANGE rules. It already had the -0.0 results, and I re-checked those on both builds. The strtof NaN payload isn't reproduced. It depends on the digit count: nan(123) gives 0x7fc00123, nan(000000123) gives 0x7fc00012, nan(0000000123) gives 0x7fc00001. I recorded it in a debt entry instead.
  • Decimal strtod subnormals depend on the build: J03547016 sets ERANGE (as your copies do), while J03848509 and libSceLibcInternal don't. I've left strtod as it is on main. If you think the older behaviour is the more common one in shipped titles, I can change it.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6342097862 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/9691#issuecomment-6342097862). Originally posted by [hypermoist](https://github.com/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 system `libc` module and `libSceLibcInternal` here doesn't export `strtof` at all. So the `libc.prx` results 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). - **`strtof` and `wcstof`:** both builds agree with your three titles. - A decimal nonzero subnormal sets `ERANGE` only when inexact. - Hex never sets it for a nonzero subnormal, but does on underflow to zero and overflow. - `nan(...)` is consumed as by `strtod` and keeps its sign. - A failed parse after `-` gives `-0.0`. - **#8865 changes:** it now implements the `ERANGE` rules. It already had the `-0.0` results, and I re-checked those on both builds. The `strtof` NaN payload isn't reproduced. It depends on the digit count: `nan(123)` gives `0x7fc00123`, `nan(000000123)` gives `0x7fc00012`, `nan(0000000123)` gives `0x7fc00001`. I recorded it in a debt entry instead. - **Decimal `strtod` subnormals depend on the build:** J03547016 sets `ERANGE` (as your copies do), while J03848509 and `libSceLibcInternal` don't. I've left `strtod` as it is on `main`. If you think the older behaviour is the more common one in shipped titles, I can change it.
JJenkx commented 2026-10-22 13:41:18 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-22T13:41:18Z.


@hypermoist thanks, that settles strtof. For decimal strtod, here is a count over the title copies I have: nine libc.prx builds, nine different SHA-256s, run natively on Windows.

Title libc.prx sha256 (prefix)
PPSA05916 5293254b88e7
PPSA07923 40061431f3f3
PPSA09614 ae937fb62848
PPSA13934 f0f83624b925
PPSA20423 8af8cbe1fb22
PPSA25636 60f8c460806d
PPSA26528 f11539a7368c
PPSA33655 f7bae982117c
PPSA34008 d4e224f60ccb

All nine set errno to ERANGE (34) for strtod("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 setting ERANGE for every decimal subnormal, but it's your call.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6342223968 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/9691#issuecomment-6342223968). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-22T13:41:18Z. --- @hypermoist thanks, that settles `strtof`. For decimal `strtod`, here is a count over the title copies I have: nine `libc.prx` builds, nine different SHA-256s, run natively on Windows. | Title | `libc.prx` sha256 (prefix) | |---|---| | PPSA05916 | 5293254b88e7 | | PPSA07923 | 40061431f3f3 | | PPSA09614 | ae937fb62848 | | PPSA13934 | f0f83624b925 | | PPSA20423 | 8af8cbe1fb22 | | PPSA25636 | 60f8c460806d | | PPSA26528 | f11539a7368c | | PPSA33655 | f7bae982117c | | PPSA34008 | d4e224f60ccb | All nine set `errno` to `ERANGE` (34) for `strtod("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 setting `ERANGE` for every decimal subnormal, but it's your call. AI-assisted (Claude Code).
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5#9691
No description provided.