fix(libc): raise inexact for tiny asin and atan inputs #23972

Merged
HighDaddyLudo merged 1 commit from upstream-pr/23972 into main 2026-11-20 05:35:32 +00:00
HighDaddyLudo commented 2026-11-19 23:41:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by HighDaddyLudo on 2026-11-19T23:41:23Z.


What

The tiny-input paths in double-precision asin and atan returned the input without raising FE_INEXACT. The libc.prx comparison in #23411 reports this discrepancy. FreeBSD 11.4 msun raises inexact for nonzero inputs in the corresponding paths.

Raise FE_INEXACT for nonzero inputs at the existing cutoffs. The regression check covers preserved result bits, signed zero, subnormal inputs and unchanged errno.

Tested

  • Debian 13 x86-64, GCC 14. Linked the focused GuestMath regression check against the relevant functions from Math.cpp. It failed on main and passed with this change.
  • Syntax checks passed for the changed C++ files with GCC on Linux and LLVM-MinGW targeting Windows x86-64. The full guest_math CTest and a Windows runtime run are pending.
  • Conventions, whitespace and a test merge passed against main at dd9b766645. The overlap script received HTTP 403. Targeted GitHub searches found no competing fix for these two functions.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5404895827 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23972). Originally posted by [HighDaddyLudo](https://github.com/HighDaddyLudo) on 2026-11-19T23:41:23Z. --- ### What The tiny-input paths in double-precision `asin` and `atan` returned the input without raising `FE_INEXACT`. The libc.prx comparison in #23411 reports this discrepancy. FreeBSD 11.4 msun raises inexact for nonzero inputs in the corresponding paths. Raise `FE_INEXACT` for nonzero inputs at the existing cutoffs. The regression check covers preserved result bits, signed zero, subnormal inputs and unchanged `errno`. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> - Debian 13 x86-64, GCC 14. Linked the focused `GuestMath` regression check against the relevant functions from `Math.cpp`. It failed on `main` and passed with this change. - Syntax checks passed for the changed C++ files with GCC on Linux and LLVM-MinGW targeting Windows x86-64. The full `guest_math` CTest and a Windows runtime run are pending. - Conventions, whitespace and a test merge passed against `main` at `dd9b766645`. The overlap script received HTTP 403. Targeted GitHub searches found no competing fix for these two functions. ### 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) and the licence notice of code adapted from upstream (see AGENTS.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 <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: n/a <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no -->
PrivacyOnion commented 2026-11-19 23:50:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-19T23:50:59Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 3dfb4fbfe7:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_math_tests built cleanly.
  • CTest (guest_math):
    1/1 Test #1203: guest_math .......................   Passed    0.02 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libc/src/Math.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #1203: guest_math .......................Subprocess aborted***Exception:   2.36 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • core/libs/prx/libc/src/Math.cpp: verified asin_nid_postfix correctly raises FE_INEXACT via std::feraiseexcept for nonzero tiny inputs (|x| < 2^-26) while preserving +/-0.0 without exception
    • core/libs/prx/libc/src/Math.cpp: verified atan_nid_postfix correctly raises FE_INEXACT via std::feraiseexcept for nonzero tiny inputs (|x| < 2^-27) while preserving +/-0.0 without exception
    • core/libs/tests/GuestMath.cpp: verified CheckTinyInverseTrigFlags tests both asin and atan across zero (+/-0.0), subnormals (denorm_min), and normal tiny inputs (0x1p-30), asserting result bit identity, preserved errno, and exact expected FP exceptions
    • Conventions and AGENTS.md compliance: confirmed no comments added, no unhandled inputs, clean conventions check, and proper use of std::feraiseexcept

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5985281612 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23972#pullrequestreview-5985281612). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-19T23:50:59Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `3dfb4fbfe7`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_math_tests` built cleanly. - **CTest** (`guest_math`): ``` 1/1 Test #1203: guest_math ....................... Passed 0.02 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libc/src/Math.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/1 Test #1203: guest_math .......................Subprocess aborted***Exception: 2.36 sec 0% tests passed, 1 tests failed out of 1 ``` Restoring the change makes it pass again. - **Code reading**: - core/libs/prx/libc/src/Math.cpp: verified asin_nid_postfix correctly raises FE_INEXACT via std::feraiseexcept for nonzero tiny inputs (|x| < 2^-26) while preserving +/-0.0 without exception - core/libs/prx/libc/src/Math.cpp: verified atan_nid_postfix correctly raises FE_INEXACT via std::feraiseexcept for nonzero tiny inputs (|x| < 2^-27) while preserving +/-0.0 without exception - core/libs/tests/GuestMath.cpp: verified CheckTinyInverseTrigFlags tests both asin and atan across zero (+/-0.0), subnormals (denorm_min), and normal tiny inputs (0x1p-30), asserting result bit identity, preserved errno, and exact expected FP exceptions - Conventions and AGENTS.md compliance: confirmed no comments added, no unhandled inputs, clean conventions check, and proper use of std::feraiseexcept Looks Good To Me
MarcZX10 commented 2026-11-20 05:13:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T05:13:26Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change based on the code reviewed; the full guest_math CTest and Windows runtime check remain pending.

What I ran

Reviewed head 3dfb4fbfe7ff65e770a47cd865ebc0b599d69f17. No commands or tests were run; the author-reported checks in the PR description were not independently run.

Results

Check Result Note
Diff and changed code passed Both functions and regression check reviewed
Automated tests not run Full CTest and Windows runtime pending

Findings

Blocking

None.

Non-blocking

None.

Not verified

Did not run the focused regression, full guest_math CTest, syntax checks, or Windows runtime check. Read core/libs/prx/libc/src/Math.cpp and core/libs/tests/GuestMath.cpp; manifest.json lists both changed files as reviewed and included. The attempted read of files.json was unavailable; no excluded files were identified from the manifest.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5987842948 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23972#pullrequestreview-5987842948). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-20T05:13:26Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change based on the code reviewed; the full `guest_math` CTest and Windows runtime check remain pending. ## What I ran Reviewed head `3dfb4fbfe7ff65e770a47cd865ebc0b599d69f17`. No commands or tests were run; the author-reported checks in the PR description were not independently run. ## Results | Check | Result | Note | |---|---|---| | Diff and changed code | passed | Both functions and regression check reviewed | | Automated tests | not run | Full CTest and Windows runtime pending | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified Did not run the focused regression, full `guest_math` CTest, syntax checks, or Windows runtime check. Read `core/libs/prx/libc/src/Math.cpp` and `core/libs/tests/GuestMath.cpp`; `manifest.json` lists both changed files as reviewed and included. The attempted read of `files.json` was unavailable; no excluded files were identified from the manifest. ## To get this to a good state Nothing is required.
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!23972
No description provided.