fix(libc): set ERANGE for decimal subnormals in wcstod as strtod does #11892

Merged
JJenkx merged 1 commit from upstream-pr/11892 into main 2026-11-02 12:28:06 +00:00
JJenkx commented 2026-10-27 11:55:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-27T11:55:41Z.


What

strtod sets ERANGE for a decimal input whose result is a nonzero subnormal (#9833). wcstod parses through the host strtod directly, so it skips that rule and leaves errno alone. The wcstod of the libc.prx that titles ship sets ERANGE in the same cases as its strtod. wcstod now parses through strtod, as #9833 offered as a follow-up.

Tested

Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release, BUILD_TESTING=ON, main 8ff4baf534.

  • Comparison: a scratch loader runs the decrypted libc.prx of eleven titles natively: PPSA04158, PPSA05916, PPSA07923, PPSA09614, PPSA13934, PPSA20423, PPSA25636, PPSA26528, PPSA33655, PPSA34008 and PPSA35169.
    • Measured cases:

      Input Bits errno
      1e-310 000012688b70e62b ERANGE
      -4.9406564584124654e-324 8000000000000001 ERANGE
      1e-330 0 ERANGE
      2.2250738585072014e-308 0010000000000000 0
      0x1p-1074 1 0
      0x1.8p-1075 1 ERANGE
      -0x1.000001p-1075 8000000000000001 ERANGE
    • Their wcstod gives these results, and all eleven set ERANGE for 1e-310, 4.9406564584124654e-324 and 0x1.8p-1075.

    • Random strings: 100,000 random decimal strings in the subnormal range (exponents -300 to -329) went through PPSA07923's wcstod and main's.

      • main differs on 40,900, every one in errno.
      • strtod matches on all 100,000, which shows the rule wcstod now reuses.
  • guest_math: CheckFloatUnderflowErrno gains the seven wcstod cases above.
  • guest_math and guest_wide_strings pass in three runs out of three on the exact head.
  • Negative control: with main's Strings.cpp and these tests, guest_math aborts (exit 0xc0000409).
  • python tools/check_conventions.py --base origin/main and git diff --check pass.
  • Not tested: a console's libSceLibcInternal.sprx wcstod (the debt entry keeps that as unmeasured), Linux and macOS (the change is target-independent).

Current Linux qualification (2026-10-28)

Rebased onto main 2227f1366188cda5699dd20e2e756a18006a5d4b. Linux CPU validation on 2026-10-28 at 6219aaaff1520be4d484d6b618c3c3977024be58 (Arch Linux 7.2.9, AMD Ryzen 9 7950X, GCC 16.2.1, Ninja Release, BUILD_TESTING=ON).

libc, guest_math_tests and guest_math_exact_tests rebuilt from this exact source. guest_math and guest_math_exact each passed three consecutive runs (6/6, no skips); the same two suites each passed three runs on the pinned main (6/6). Conventions and whitespace checks pass.

Exact source pins, preservation proofs, dependency checks, build logs and JUnit, SHA-256 1176269c9e6948b5252a5db9e660978d7f978fb2d9f4ed6c68bc050b10b5ae68. This is focused Linux CPU qualification; earlier Windows/title/reference measurements retain their original pins. No new title or performance result is claimed.

Current Linux qualification — 2026-10-29

Refreshed against main 5454cd2e455994d992aca39335ce60507eeda1eb.

Linux qualification at f6ca8993e813d818781a29f86148c52f58df4d4b (Arch Linux 7.2.9, Ryzen 9 7950X, GCC 16.2.1, Ninja Release, BUILD_TESTING=ON): guest_math, guest_math_exact, guest_dinkumware_internals, guest_wide_strings, guest_strtod_subnormal, guest_wide_conversion each pass three consecutive runs (18/18, no skips). The public_headers audit passes at this exact head. All tracked public-header files match the pinned main; the affected test targets rebuild against those headers. Conventions and whitespace checks pass. The same focused groups passed three times on the pinned main.

The combined debt entry retains the decimal wcstod qualification, the PPSA08329-only hexadecimal measurements and glibc 2.35 rounding limitation from merged #12291, with console wcstod still unmeasured. The focused set includes inherited hexadecimal-underflow cases and wide-string conversions. No new title measurements are claimed.

Evidence: immutable Linux qualification bundle. Its SHA-256 is 53b095da2f67f55b8aa56ba273681e0330fb39739be844458038dde410fb8cc4. No fresh Windows runtime execution is claimed; older measurements retain their recorded source pins.

AI-assisted: yes (Codex).

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: none
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5033475135 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11892). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-27T11:55:41Z. --- ### What `strtod` sets `ERANGE` for a decimal input whose result is a nonzero subnormal (#9833). `wcstod` parses through the host `strtod` directly, so it skips that rule and leaves `errno` alone. The `wcstod` of the `libc.prx` that titles ship sets `ERANGE` in the same cases as its `strtod`. `wcstod` now parses through `strtod`, as #9833 offered as a follow-up. ### Tested Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release, `BUILD_TESTING=ON`, `main` 8ff4baf534. - **Comparison:** a scratch loader runs the decrypted `libc.prx` of eleven titles natively: PPSA04158, PPSA05916, PPSA07923, PPSA09614, PPSA13934, PPSA20423, PPSA25636, PPSA26528, PPSA33655, PPSA34008 and PPSA35169. - **Measured cases:** | Input | Bits | `errno` | |---|---|---| | `1e-310` | `000012688b70e62b` | `ERANGE` | | `-4.9406564584124654e-324` | `8000000000000001` | `ERANGE` | | `1e-330` | `0` | `ERANGE` | | `2.2250738585072014e-308` | `0010000000000000` | 0 | | `0x1p-1074` | `1` | 0 | | `0x1.8p-1075` | `1` | `ERANGE` | | `-0x1.000001p-1075` | `8000000000000001` | `ERANGE` | - Their `wcstod` gives these results, and all eleven set `ERANGE` for `1e-310`, `4.9406564584124654e-324` and `0x1.8p-1075`. - **Random strings:** 100,000 random decimal strings in the subnormal range (exponents -300 to -329) went through PPSA07923's `wcstod` and `main`'s. - `main` differs on 40,900, every one in `errno`. - `strtod` matches on all 100,000, which shows the rule `wcstod` now reuses. - **`guest_math`:** `CheckFloatUnderflowErrno` gains the seven `wcstod` cases above. - `guest_math` and `guest_wide_strings` pass in three runs out of three on the exact head. - **Negative control:** with `main`'s `Strings.cpp` and these tests, `guest_math` aborts (exit 0xc0000409). - `python tools/check_conventions.py --base origin/main` and `git diff --check` pass. - **Not tested:** a console's `libSceLibcInternal.sprx` `wcstod` (the debt entry keeps that as unmeasured), Linux and macOS (the change is target-independent). <!-- codex-math-refresh-20261028-repeat-pr11892 --> ### Current Linux qualification (2026-10-28) Rebased onto `main` `2227f1366188cda5699dd20e2e756a18006a5d4b`. Linux CPU validation on 2026-10-28 at `6219aaaff1520be4d484d6b618c3c3977024be58` (Arch Linux 7.2.9, AMD Ryzen 9 7950X, GCC 16.2.1, Ninja Release, BUILD_TESTING=ON). `libc`, `guest_math_tests` and `guest_math_exact_tests` rebuilt from this exact source. `guest_math` and `guest_math_exact` each passed three consecutive runs (6/6, no skips); the same two suites each passed three runs on the pinned main (6/6). Conventions and whitespace checks pass. [Exact source pins, preservation proofs, dependency checks, build logs and JUnit](https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/owned-math25-main2227-linux-20261028-repeat.tar.gz), SHA-256 `1176269c9e6948b5252a5db9e660978d7f978fb2d9f4ed6c68bc050b10b5ae68`. This is focused Linux CPU qualification; earlier Windows/title/reference measurements retain their original pins. No new title or performance result is claimed. <!-- codex-maintenance-20261029-repeat-11892 --> **Current Linux qualification — 2026-10-29** Refreshed against main `5454cd2e455994d992aca39335ce60507eeda1eb`. Linux qualification at `f6ca8993e813d818781a29f86148c52f58df4d4b` (Arch Linux 7.2.9, Ryzen 9 7950X, GCC 16.2.1, Ninja Release, BUILD_TESTING=ON): `guest_math`, `guest_math_exact`, `guest_dinkumware_internals`, `guest_wide_strings`, `guest_strtod_subnormal`, `guest_wide_conversion` each pass three consecutive runs (18/18, no skips). The `public_headers` audit passes at this exact head. All tracked public-header files match the pinned main; the affected test targets rebuild against those headers. Conventions and whitespace checks pass. The same focused groups passed three times on the pinned main. The combined debt entry retains the decimal wcstod qualification, the PPSA08329-only hexadecimal measurements and glibc 2.35 rounding limitation from merged #12291, with console wcstod still unmeasured. The focused set includes inherited hexadecimal-underflow cases and wide-string conversions. No new title measurements are claimed. Evidence: [immutable Linux qualification bundle](https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/owned-math10-main5454-linux-20261029-repeat.tar.gz). Its SHA-256 is `53b095da2f67f55b8aa56ba273681e0330fb39739be844458038dde410fb8cc4`. No fresh Windows runtime execution is claimed; older measurements retain their recorded source pins. AI-assisted: yes (Codex). ### 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: none - [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 AI-assisted (Claude Code).
MarcZX10 commented 2026-10-27 12:03:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-27T12:03:27Z.

Review: APPROVED


I reviewed the delegation and the errno rule: wcstod still parses the ASCII prefix and maps endptr through ParseAsciiPrefix, while the delegated strtod_nid_postfix adds the same decimal nonzero-subnormal ERANGE behavior as strtod. I built and ran guest_math on native Linux using this PR's exact Strings.cpp and GuestMath.cpp changes; 1/1 passed. The hosted Windows build also passes, along with conventions and the Linux relinker checks. I found no blocking issue in this focused change. The console libSceLibcInternal behavior remains explicitly documented as unmeasured.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5666729657 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11892#pullrequestreview-5666729657). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-27T12:03:27Z. **Review:** APPROVED --- I reviewed the delegation and the errno rule: `wcstod` still parses the ASCII prefix and maps `endptr` through `ParseAsciiPrefix`, while the delegated `strtod_nid_postfix` adds the same decimal nonzero-subnormal `ERANGE` behavior as `strtod`. I built and ran `guest_math` on native Linux using this PR's exact `Strings.cpp` and `GuestMath.cpp` changes; 1/1 passed. The hosted Windows build also passes, along with conventions and the Linux relinker checks. I found no blocking issue in this focused change. The console `libSceLibcInternal` behavior remains explicitly documented as unmeasured.
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!11892
No description provided.