fix(libc): store EDOM and raise FE_INVALID from acosf and asinf domain errors #12319

Merged
JJenkx merged 1 commit from upstream-pr/12319 into main 2026-10-28 14:34:51 +00:00
JJenkx commented 2026-10-28 09:19:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-28T09:19:52Z.


What

For |x| > 1, the infinities and NaN, titles' libc.prx stores EDOM and raises FE_INVALID from acosf, for a quiet NaN input too. For a quiet NaN, asinf also raises FE_INVALID. Here acosf returned the same NaN bits without either. asinf stored EDOM but raised nothing for a quiet NaN, because (x - x) / (x - x) only raises for a signalling one.

Both now call _Feraise_nid_postfix(0x01), the helper nextafter already uses. It stores EDOM and raises the invalid flag in the x87 and SSE units. Every result is unchanged.

The acosf test from #3688 asserted that errno stays unchanged, following FreeBSD's MATH_ERREXCEPT. The titles' library doesn't do that, and the debt entry already recorded "the console stores EDOM and raises FE_INVALID". CheckAcosfErrno now checks EDOM and FE_INVALID, along with the result bits, for ±2, ±inf, 1 + ulp and quiet NaNs, and that acosf(0.5) still sets neither. CheckAsinfErrno also checks the flag. The acosf debt entry is updated.

Tested

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

  • guest_math and guest_math_exact pass in each of 3 runs.
  • Negative control: with main's Math.cpp and this test, guest_math fails.
  • Against titles' own libc.prx: I loaded the bundled libc.prx natively and called acosf and asinf by NID, side by side with this build.
    • 15 edge inputs, comparing result bits, errno and raised FE_INVALID/FE_INEXACT/FE_DIVBYZERO: ±1.5, ±2.5, ±(1 + ulp), ±inf, ±quiet NaN, a signalling NaN, ±1, 0.5, the smallest subnormal, -0 and FLT_MAX.
      • On PPSA07923 (non-FMA) and PPSA13934 (FMA-contracted), with identical results: main differs in all 10 domain-error acosf cases and in the two quiet-NaN asinf cases. With this change none of those differ.
    • The random-input comparison, result bits and errno, on PPSA07923 and PPSA05916:
main this PR
acosf 0 value, 224,233 errno differences 0, 0
asinf 0, 0 0, 0

One difference remains, and this PR leaves it alone. For the smallest subnormal, the titles' asinf raises FE_INEXACT (on both titles), while the debt entry says tiny arguments don't. I didn't change that or its entry here.

Not tested on Linux or macOS.

Overlap: tools/pr_overlap.py reports #11849 editing the neighbouring asinl debt entry (lines 147–148). It's a textual adjacency only, so either can land first.

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)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5048078798 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12319). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-28T09:19:52Z. --- ### What For |x| > 1, the infinities and NaN, titles' `libc.prx` stores `EDOM` and raises `FE_INVALID` from `acosf`, for a quiet NaN input too. For a quiet NaN, `asinf` also raises `FE_INVALID`. Here `acosf` returned the same NaN bits without either. `asinf` stored `EDOM` but raised nothing for a quiet NaN, because `(x - x) / (x - x)` only raises for a signalling one. Both now call `_Feraise_nid_postfix(0x01)`, the helper `nextafter` already uses. It stores `EDOM` and raises the invalid flag in the x87 and SSE units. Every result is unchanged. The `acosf` test from #3688 asserted that `errno` stays unchanged, following FreeBSD's `MATH_ERREXCEPT`. The titles' library doesn't do that, and the debt entry already recorded "the console stores `EDOM` and raises `FE_INVALID`". `CheckAcosfErrno` now checks `EDOM` and `FE_INVALID`, along with the result bits, for ±2, ±inf, `1 + ulp` and quiet NaNs, and that `acosf(0.5)` still sets neither. `CheckAsinfErrno` also checks the flag. The `acosf` debt entry is updated. ### Tested Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release, `BUILD_TESTING=ON`, on `main` `ab168194d4`. - `guest_math` and `guest_math_exact` pass in each of 3 runs. - **Negative control:** with `main`'s `Math.cpp` and this test, `guest_math` fails. - **Against titles' own `libc.prx`:** I loaded the bundled `libc.prx` natively and called `acosf` and `asinf` by NID, side by side with this build. - **15 edge inputs**, comparing result bits, `errno` and raised `FE_INVALID`/`FE_INEXACT`/`FE_DIVBYZERO`: ±1.5, ±2.5, `±(1 + ulp)`, ±inf, ±quiet NaN, a signalling NaN, ±1, 0.5, the smallest subnormal, -0 and `FLT_MAX`. - On PPSA07923 (non-FMA) and PPSA13934 (FMA-contracted), with identical results: `main` differs in all 10 domain-error `acosf` cases and in the two quiet-NaN `asinf` cases. With this change none of those differ. - **The random-input comparison**, result bits and `errno`, on PPSA07923 and PPSA05916: | | `main` | this PR | |---|---|---| | `acosf` | 0 value, **224,233 `errno`** differences | 0, 0 | | `asinf` | 0, 0 | 0, 0 | One difference remains, and this PR leaves it alone. For the smallest subnormal, the titles' `asinf` raises `FE_INEXACT` (on both titles), while the debt entry says tiny arguments don't. I didn't change that or its entry here. Not tested on Linux or macOS. **Overlap:** `tools/pr_overlap.py` reports #11849 editing the neighbouring `asinl` debt entry (lines 147–148). It's a textual adjacency only, so either can land first. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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)
BunnyFl commented 2026-10-28 13:38:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-10-28T13:38:48Z.

Review: APPROVED


Approving head 8b5c02ca61. I read the whole diff and ran firmware 13.42's acosf and asinf: the decrypted system libSceLibcInternal.sprx's exports, natively on a PC (not a console), on 19 inputs: every value the new tests use plus ±1.5, ±2.5, -(1 + ulp), a signalling NaN, ±1, the smallest subnormal, -0 and FLT_MAX. Three identical runs.

  • Domain errors: for ±2, ±1.5, ±2.5, ±(1 + ulp), ±inf, FLT_MAX and the NaNs, both functions store EDOM and raise FE_INVALID, the quiet NaN 0x7fc00000 included. They return 0xffc00000 for the non-NaN inputs and the quieted input for a NaN (0x7fc00000, 0xffc00000, and 0x7fa00000 → 0x7fe00000).
  • In range: acosf(0.5) returns 0x3f860a92 without touching errno or raising FE_INVALID; ±1, -0 and the smallest subnormal leave errno alone too.

This matches the new CheckAcosfErrno and CheckAsinfErrno expectations and the titles' measurements in the description. #3688's "errno unchanged" came from FreeBSD's source rather than a measurement; the module disagrees with it the same way the titles' copies do.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5683537605 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12319#pullrequestreview-5683537605). Originally posted by [BunnyFl](https://github.com/BunnyFl) on 2026-10-28T13:38:48Z. **Review:** APPROVED --- Approving head `8b5c02ca61`. I read the whole diff and ran firmware 13.42's `acosf` and `asinf`: the decrypted system `libSceLibcInternal.sprx`'s exports, natively on a PC (not a console), on 19 inputs: every value the new tests use plus ±1.5, ±2.5, `-(1 + ulp)`, a signalling NaN, ±1, the smallest subnormal, -0 and `FLT_MAX`. Three identical runs. - **Domain errors:** for ±2, ±1.5, ±2.5, `±(1 + ulp)`, ±inf, `FLT_MAX` and the NaNs, both functions store `EDOM` and raise `FE_INVALID`, the quiet NaN `0x7fc00000` included. They return `0xffc00000` for the non-NaN inputs and the quieted input for a NaN (`0x7fc00000`, `0xffc00000`, and `0x7fa00000` → `0x7fe00000`). - **In range:** `acosf(0.5)` returns `0x3f860a92` without touching `errno` or raising `FE_INVALID`; ±1, -0 and the smallest subnormal leave `errno` alone too. This matches the new `CheckAcosfErrno` and `CheckAsinfErrno` expectations and the titles' measurements in the description. #3688's "errno unchanged" came from FreeBSD's source rather than a measurement; the module disagrees with it the same way the titles' copies do.
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!12319
No description provided.