fix(libc): asin(|x| > 1) returns the x86 default NaN and leaves errno unchanged #3605

Merged
CouchRiv merged 1 commit from upstream-pr/3605 into main 2026-10-11 21:43:45 +00:00
CouchRiv commented 2026-10-11 14:09:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by CouchRiv on 2026-10-11T14:09:52Z.


What

asin(x) for |x| > 1 (including +-inf) returns 0x7ff8000000000000 and sets errno to 33 on main; FreeBSD msun returns 0xfff8000000000000 and never sets errno (e_asin.c#L81-L85; math_errhandling is MATH_ERREXCEPT, math.h#L67-L69). Example: asin(2.0).

asin now handles |x| > 1 itself: it raises FE_INVALID, returns 0xfff8000000000000 and leaves errno as the caller set it. For |x| <= 1 and for NaN it still calls the host function, with the same result and flags as on main.

Also changes: errno (asin(|x| > 1) no longer sets errno to 33, as in msun).

Tested

CachyOS Linux, RTX 4070 Ti (NVIDIA) and Radeon 610M (RADV), lavapipe for CI parity.

  • guest_math: asin(2.0) returns 0xfff8000000000000 with errno unchanged and FE_INVALID raised; asin(NaN) raises nothing. The new checks fail on main and pass with the change. 1/1 (CPU-only test, so the three drivers run the same code).
  • Compared against main on 767 inputs (finite, subnormal, +-inf, quiet and signalling NaNs): only the 488 inputs with |x| > 1 change (the sign of the NaN, and errno from 33 to 0); every other input, NaN included, gives the same result, errno and flags as on main.
  • tools/check_conventions.py --base origin/main and git diff --check: clean.
  • Windows and macOS not run.

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 in TechnicalDebt
  • 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

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4819661651 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3605). Originally posted by [CouchRiv](https://github.com/CouchRiv) on 2026-10-11T14:09:52Z. --- ### What `asin(x)` for `|x| > 1` (including +-inf) returns `0x7ff8000000000000` and sets errno to 33 on `main`; FreeBSD msun returns `0xfff8000000000000` and never sets errno ([e_asin.c#L81-L85](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/lib/msun/src/e_asin.c#L81-L85); `math_errhandling` is `MATH_ERREXCEPT`, [math.h#L67-L69](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/lib/msun/src/math.h#L67-L69)). Example: `asin(2.0)`. `asin` now handles `|x| > 1` itself: it raises `FE_INVALID`, returns `0xfff8000000000000` and leaves errno as the caller set it. For `|x| <= 1` and for NaN it still calls the host function, with the same result and flags as on `main`. Also changes: errno (`asin(|x| > 1)` no longer sets errno to 33, as in msun). ### Tested CachyOS Linux, RTX 4070 Ti (NVIDIA) and Radeon 610M (RADV), lavapipe for CI parity. - guest_math: `asin(2.0)` returns `0xfff8000000000000` with errno unchanged and `FE_INVALID` raised; `asin(NaN)` raises nothing. The new checks fail on `main` and pass with the change. 1/1 (CPU-only test, so the three drivers run the same code). - Compared against `main` on 767 inputs (finite, subnormal, +-inf, quiet and signalling NaNs): only the 488 inputs with `|x| > 1` change (the sign of the NaN, and errno from 33 to 0); every other input, NaN included, gives the same result, errno and flags as on `main`. - `tools/check_conventions.py --base origin/main` and `git diff --check`: clean. - Windows and macOS not run. ### 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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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 AI-assisted: yes
blawesom commented 2026-10-11 15:20:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-11T15:20:08Z.


Independent pre-review on Linux (full CI runs only happen on manual trigger, so recording one): CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, BUILD_TESTING=ON.

  • Builds; tools/check_conventions.py --base origin/main passes.
  • Full suite: 832/832 passed (all tests including the Vulkan suites on AMD RX 9070 XT / RADV).
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6110520869 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3605#issuecomment-6110520869). Originally posted by [blawesom](https://github.com/blawesom) on 2026-10-11T15:20:08Z. --- Independent pre-review on **Linux** (full CI runs only happen on manual trigger, so recording one): CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, `BUILD_TESTING=ON`. - Builds; `tools/check_conventions.py --base origin/main` passes. - Full suite: **832/832 passed** (all tests including the Vulkan suites on AMD RX 9070 XT / RADV).
github-actions[bot] commented 2026-10-11 16:32:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T16:32:04Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#3598 core/libs/tests/GuestMath.cpp L284
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6111188422 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3605#issuecomment-6111188422). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-11T16:32:04Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #3598 | `core/libs/tests/GuestMath.cpp` [L284](https://github.com/boykopovar/AnyPS5/blob/41f013f664f6ec36a8111f2c6f9772b76e562288/core/libs/tests/GuestMath.cpp#L284) | | |
adriadam10 commented 2026-10-11 21:43:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T21:43:41Z.


Checked build + guest_math on current main (passes; fails with the Math.cpp change reverted), result matches FreeBSD msun e_asin.c (default x86 NaN, sign set, FE_INVALID, errno untouched), plus @blawesom's independent full run; merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6114113981 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3605#issuecomment-6114113981). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T21:43:41Z. --- Checked build + `guest_math` on current main (passes; fails with the Math.cpp change reverted), result matches FreeBSD msun `e_asin.c` (default x86 NaN, sign set, FE_INVALID, errno untouched), plus @blawesom's independent full run; merging.
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!3605
No description provided.