fix(libc): powf(1, y) returns 1 for any y #3602

Merged
CouchRiv merged 1 commit from upstream-pr/3602 into main 2026-10-13 01:15:53 +00:00
CouchRiv commented 2026-10-11 14:08:48 +00:00 (Migrated from github.com)

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


What

powf(1.0f, y) with y the signalling NaN 0x7f800001 returns the quieted NaN 0x7fc00001 and raises FE_INVALID on main; FreeBSD msun returns 1.0f (0x3f800000) for every y, NaN included, and raises nothing (e_powf.c#L71-L75). A quiet NaN y already gives 1.0f on main.

powf now returns 1.0f whenever the base is 1.0f, without calling the host function, so the signalling-NaN case no longer raises FE_INVALID either (as in msun). Every other input still goes to the host function.

Also changes: flags (powf(1.0f, sNaN) no longer raises FE_INVALID, as in msun).

Tested

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

  • guest_math: the new powf_nid_postfix checks fail on main and pass with the change; 1/1 on NVIDIA, RADV and lavapipe.
  • 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:4819655158 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3602). Originally posted by [CouchRiv](https://github.com/CouchRiv) on 2026-10-11T14:08:48Z. --- ### What `powf(1.0f, y)` with `y` the signalling NaN `0x7f800001` returns the quieted NaN `0x7fc00001` and raises `FE_INVALID` on `main`; FreeBSD msun returns `1.0f` (`0x3f800000`) for every `y`, NaN included, and raises nothing ([e_powf.c#L71-L75](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/lib/msun/src/e_powf.c#L71-L75)). A quiet NaN `y` already gives `1.0f` on `main`. `powf` now returns `1.0f` whenever the base is `1.0f`, without calling the host function, so the signalling-NaN case no longer raises `FE_INVALID` either (as in msun). Every other input still goes to the host function. Also changes: flags (`powf(1.0f, sNaN)` no longer raises `FE_INVALID`, as in msun). ### Tested CachyOS Linux, RTX 4070 Ti (NVIDIA) and Radeon 610M (RADV), lavapipe for CI parity. - guest_math: the new `powf_nid_postfix` checks fail on `main` and pass with the change; 1/1 on NVIDIA, RADV and lavapipe. - `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:11 +00:00 (Migrated from github.com)

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


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:6110521473 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3602#issuecomment-6110521473). Originally posted by [blawesom](https://github.com/blawesom) on 2026-10-11T15:20:11Z. --- 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).
oneandonlydean commented 2026-10-13 00:18:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T00:18:55Z.


Conflicts with main in core/libs/tests/GuestMath.cpp since #3599; please rebase.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6135160856 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3602#issuecomment-6135160856). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-13T00:18:55Z. --- Conflicts with main in `core/libs/tests/GuestMath.cpp` since #3599; please rebase.
CouchRiv commented 2026-10-13 00:38:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by CouchRiv on 2026-10-13T00:38:13Z.


Rebased onto main at 1c5e62878. The conflict was two new test functions next to each other in GuestMath.cpp; both are kept (CheckExp2Errno from main and CheckPowfSpecialValue). The fix is unchanged.

Tested: Release, gcc, ctest -R guest_math passed on NVIDIA, RADV and lavapipe; tools/check_conventions.py passes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6135397353 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3602#issuecomment-6135397353). Originally posted by [CouchRiv](https://github.com/CouchRiv) on 2026-10-13T00:38:13Z. --- Rebased onto `main` at 1c5e62878. The conflict was two new test functions next to each other in `GuestMath.cpp`; both are kept (`CheckExp2Errno` from main and `CheckPowfSpecialValue`). The fix is unchanged. Tested: Release, gcc, `ctest -R guest_math` passed on NVIDIA, RADV and lavapipe; `tools/check_conventions.py` passes.
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!3602
No description provided.