fix(libc): return the x86 default NaN from acosf for |x| > 1 #5154

Closed
coltken95 wants to merge 1 commit from upstream-pr/5154 into main
coltken95 commented 2026-10-13 13:03:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by coltken95 on 2026-10-13T13:03:29Z.


What

guest_math fails on Linux at current main (0f2683cb7): CheckAcosfErrno from #3688 pins acosf(±2.0f) to 0xffc00000, FreeBSD's (x-x)/(x-x) on x86, but acosf passed out-of-range arguments to the host, and glibc 2.39 (ubuntu-latest) returns 0x7fc00000. acosf now raises FE_INVALID and returns the negative quiet NaN for |x| > 1, as asin does.

Tested

Linux x86-64 (Ubuntu 24.04, glibc 2.39, GCC 13, Release):

  • guest_math aborts with main's Math.cpp and passes with this change; the test now also covers ±infinity and FE_INVALID.
  • All other guest_* tests match main.
    Windows not tested.

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
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none (Linux CI guest_math on main)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4843650930 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5154). Originally posted by [coltken95](https://github.com/coltken95) on 2026-10-13T13:03:29Z. --- ### What `guest_math` fails on Linux at current `main` (0f2683cb7): `CheckAcosfErrno` from #3688 pins `acosf(±2.0f)` to `0xffc00000`, FreeBSD's `(x-x)/(x-x)` on x86, but `acosf` passed out-of-range arguments to the host, and glibc 2.39 (ubuntu-latest) returns `0x7fc00000`. `acosf` now raises `FE_INVALID` and returns the negative quiet NaN for |x| > 1, as `asin` does. ### Tested Linux x86-64 (Ubuntu 24.04, glibc 2.39, GCC 13, Release): - `guest_math` aborts with main's `Math.cpp` and passes with this change; the test now also covers ±infinity and `FE_INVALID`. - All other `guest_*` tests match `main`. Windows not tested. ### 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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's technical debt file - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none (Linux CI `guest_math` on `main`) - [x] AI-assisted: yes
LeandroLP23 commented 2026-10-13 13:13:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-13T13:13:17Z.


Windows check, since the description covers Linux only: Windows 11 (26300), WinLibs GCC 15.2.0 (UCRT), Release. Head c8872b450 merged onto main 0f2683cb7 with a clean merge.

  • ctest -R '^guest_math$': 1/1 passed. That includes the new ±infinity and FE_INVALID checks.
  • ctest -R '^guest_' -j 4: 379/379 passed.

On unmodified main, guest_math already passes here, because UCRT's acos returns 0xffc00000 for |x| > 1. So the red main is Linux-only, and with this PR both hosts agree.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6146360451 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5154#issuecomment-6146360451). Originally posted by [LeandroLP23](https://github.com/LeandroLP23) on 2026-10-13T13:13:17Z. --- Windows check, since the description covers Linux only: Windows 11 (26300), WinLibs GCC 15.2.0 (UCRT), Release. Head `c8872b450` merged onto `main` `0f2683cb7` with a clean merge. - `ctest -R '^guest_math$'`: 1/1 passed. That includes the new ±infinity and `FE_INVALID` checks. - `ctest -R '^guest_' -j 4`: 379/379 passed. On unmodified `main`, `guest_math` already passes here, because UCRT's `acos` returns `0xffc00000` for |x| > 1. So the red `main` is Linux-only, and with this PR both hosts agree.
coltken95 commented 2026-10-13 18:22:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by coltken95 on 2026-10-13T18:22:27Z.


Superseded by #5256, which merged the same fix (FreeBSD's 0xffc00000 for |x| > 1, plus the quieted input NaN) into main. Closing.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6152279574 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5154#issuecomment-6152279574). Originally posted by [coltken95](https://github.com/coltken95) on 2026-10-13T18:22:27Z. --- Superseded by #5256, which merged the same fix (FreeBSD's 0xffc00000 for |x| > 1, plus the quieted input NaN) into main. Closing. AI-assisted: yes (Claude Code)

Pull request closed

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!5154
No description provided.