fix(libc): leave errno alone for subnormal strtod results #8379

Merged
hypermoist merged 1 commit from upstream-pr/8379 into main 2026-10-20 23:14:18 +00:00
hypermoist commented 2026-10-20 11:48:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hypermoist on 2026-10-20T11:48:44Z.


What

The console's strtof (0x731a0), strtod (0x65860) and strtold (0x749b0) from the decrypted libSceLibcInternal.sprx were run on the host through a loader. They set ERANGE only when the result underflows to zero, and leave errno untouched for a non-zero subnormal:

text strtof strtod strtold
1e-40 0x1.16c3p-133, no error normal normal
1e-46 0, ERANGE normal normal
1e-310 0, ERANGE 0x0.012688b70e62bp-1022, no error normal
1e-330 0, ERANGE 0, ERANGE normal
1e-4940 0, ERANGE 0, ERANGE 0x0.000000663278e62p-16385, no error
1e-4960 0, ERANGE 0, ERANGE 0, ERANGE

The shared ParseFloat passes through the host's strtod, strtof or strtold, which (glibc) set ERANGE for every subnormal result too. It now restores the caller's errno when the host reports ERANGE for a result that is non-zero and below the type's smallest normal value. Overflow and underflow to zero still set ERANGE. wcstod and the other callers of ParseFloat inherit the change.

Tested

Linux (CachyOS, GCC, Release). guest_math_tests has a new CheckFloatUnderflowErrno:

  • non-zero subnormal strtod, strtof and strtold results keep a preset errno;
  • underflow to zero and overflow set ERANGE;
  • the smallest normal double does not.

The check aborts without the fix and passes with it. guest_string_tests still passes.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes (Claude Code), reviewed by the contributor

🤖 Generated with Claude Code

https://claude.ai/code/session_01RbLgECLQ2bpDM7oe2urGZK

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4935274904 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8379). Originally posted by [hypermoist](https://github.com/hypermoist) on 2026-10-20T11:48:44Z. --- ### What The console's `strtof` (`0x731a0`), `strtod` (`0x65860`) and `strtold` (`0x749b0`) from the decrypted `libSceLibcInternal.sprx` were run on the host through a loader. They set `ERANGE` only when the result underflows to zero, and leave `errno` untouched for a non-zero subnormal: | text | strtof | strtod | strtold | |---|---|---|---| | `1e-40` | `0x1.16c3p-133`, no error | normal | normal | | `1e-46` | 0, `ERANGE` | normal | normal | | `1e-310` | 0, `ERANGE` | `0x0.012688b70e62bp-1022`, no error | normal | | `1e-330` | 0, `ERANGE` | 0, `ERANGE` | normal | | `1e-4940` | 0, `ERANGE` | 0, `ERANGE` | `0x0.000000663278e62p-16385`, no error | | `1e-4960` | 0, `ERANGE` | 0, `ERANGE` | 0, `ERANGE` | The shared `ParseFloat` passes through the host's `strtod`, `strtof` or `strtold`, which (glibc) set `ERANGE` for every subnormal result too. It now restores the caller's `errno` when the host reports `ERANGE` for a result that is non-zero and below the type's smallest normal value. Overflow and underflow to zero still set `ERANGE`. `wcstod` and the other callers of `ParseFloat` inherit the change. ### Tested Linux (CachyOS, GCC, Release). `guest_math_tests` has a new `CheckFloatUnderflowErrno`: - non-zero subnormal `strtod`, `strtof` and `strtold` results keep a preset `errno`; - underflow to zero and overflow set `ERANGE`; - the smallest normal double does not. The check aborts without the fix and passes with it. `guest_string_tests` still passes. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes (Claude Code), reviewed by the contributor 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01RbLgECLQ2bpDM7oe2urGZK
github-actions[bot] commented 2026-10-20 12:11:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-20T12:11:38Z.


Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 5021 core/libs/prx/libc/src/Strings.cpp
PR 6044 core/libs/tests/GuestMath.cpp
PR 6158 core/libs/tests/GuestMath.cpp
PR 6879 core/libs/prx/libc/src/Strings.cpp
PR 7201 core/libs/prx/libc/src/Strings.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6290546210 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8379#issuecomment-6290546210). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-20T12:11:38Z. --- <!-- pr-overlap --> Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/libs/prx/libc/src/Strings.cpp` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/tests/GuestMath.cpp` | | [PR 6158](https://www.github.com/boykopovar/AnyPS5/pull/6158) | `core/libs/tests/GuestMath.cpp` | | [PR 6879](https://www.github.com/boykopovar/AnyPS5/pull/6879) | `core/libs/prx/libc/src/Strings.cpp` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/prx/libc/src/Strings.cpp` |
xXPBSXx commented 2026-10-20 12:54:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-20T12:54:18Z.


Windows data point for b455c751b merged onto main 44e3389c8 (clean, git merge-tree rc 0): Windows 10.0.19045, MinGW-w64 GCC 15.2.0, Release. ctest -N -R '^guest_math$' lists exactly that one test; ctest --no-tests=error -R '^guest_math$' was run three times per tree.

  • With the PR: passes 3 of 3 (0.02-0.03 s).
  • Same tree with core/libs/prx/libc/src/Strings.cpp restored to main (the new CheckFloatUnderflowErrno kept): fails 3 of 3, exit code 0xc0000409 (the test process aborts).
    Not tested: other platforms, a title run.
    AI-assisted (Claude Code).
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6291314302 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8379#issuecomment-6291314302). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-20T12:54:18Z. --- Windows data point for `b455c751b` merged onto `main` `44e3389c8` (clean, `git merge-tree` rc 0): Windows 10.0.19045, MinGW-w64 GCC 15.2.0, Release. `ctest -N -R '^guest_math$'` lists exactly that one test; `ctest --no-tests=error -R '^guest_math$'` was run three times per tree. - With the PR: passes 3 of 3 (0.02-0.03 s). - Same tree with `core/libs/prx/libc/src/Strings.cpp` restored to `main` (the new `CheckFloatUnderflowErrno` kept): fails 3 of 3, exit code `0xc0000409` (the test process aborts). Not tested: other platforms, a title run. AI-assisted (Claude Code).
Sign in to join this conversation.
No reviewers
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!8379
No description provided.