feat(libc): export tgammaf float math function #7876

Merged
ErenYeager1836 merged 2 commits from upstream-pr/7876 into main 2026-10-20 00:52:11 +00:00
ErenYeager1836 commented 2026-10-19 11:58:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ErenYeager1836 on 2026-10-19T11:58:19Z.


What

Export tgammaf_nid_postfix(float x) in core/libs/prx/libc/src/Math.cpp delegating directly to std::tgamma(float).

Fixes part of #7624, unblocking unresolved import B2ZbqV9geCM in PPSA26578 (Unity/IL2CPP).

Tested

  • Added unit test assertions in core/libs/tests/GuestMath.cpp:
    • tgammaf(1.0f) == 1.0f
    • tgammaf(5.0f) == 24.0f (exact 4!)
    • tgammaf(0.5f) matches \sqrt{\pi}
    • Pole at 0.0f \to \infty
    • NaN propagation
  • python tools/check_conventions.py passes 100%.

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
  • Fixes: part of #7624
  • Unblocks: PPSA26578
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4920554249 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7876). Originally posted by [ErenYeager1836](https://github.com/ErenYeager1836) on 2026-10-19T11:58:19Z. --- ### What Export `tgammaf_nid_postfix(float x)` in `core/libs/prx/libc/src/Math.cpp` delegating directly to `std::tgamma(float)`. Fixes part of #7624, unblocking unresolved import `B2ZbqV9geCM` in PPSA26578 (Unity/IL2CPP). ### Tested - Added unit test assertions in `core/libs/tests/GuestMath.cpp`: - `tgammaf(1.0f) == 1.0f` - `tgammaf(5.0f) == 24.0f` (exact 4!) - `tgammaf(0.5f)` matches $\sqrt{\pi}$ - Pole at $0.0f \to \infty$ - NaN propagation - `python tools/check_conventions.py` passes 100%. ### 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] Fixes: part of #7624 - [x] Unblocks: PPSA26578 - [x] GPUs tested: n/a - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-19 11:59:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-19T11:59:04Z.


Progress report (b6583dd → 64fa4c2)

➖ System libraries: 79.86% (+0.0%, +1 implemented functions)

✅ 1 implemented
Library Name
libc tgammaf_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6266674022 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7876#issuecomment-6266674022). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-19T11:59:04Z. --- <!-- progress-report --> ### Progress report (b6583dd → 64fa4c2) ➖ **System libraries**: 79.86% (+0.0%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libc | `tgammaf_nid_postfix` | </details>
github-actions[bot] commented 2026-10-19 12:10:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-19T12:10: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
PR 6158 tgammaf_nid_postfix

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 6044 core/libs/tests/GuestMath.cpp
PR 6158 core/libs/prx/libc/src/Math.cpp
core/libs/tests/GuestMath.cpp
PR 6295 core/libs/prx/libc/src/Math.cpp
core/libs/tests/GuestMath.cpp
PR 6879 core/libs/prx/libc/src/Math.cpp
PR 7201 core/libs/prx/libc/src/Math.cpp
PR 7332 core/libs/prx/libc/src/Math.cpp
core/libs/tests/GuestMath.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6266869635 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7876#issuecomment-6266869635). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-19T12:10: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 | |---|---|---|---| | [PR 6158](https://www.github.com/boykopovar/AnyPS5/pull/6158) | | `tgammaf_nid_postfix` | | Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/tests/GuestMath.cpp` | | [PR 6158](https://www.github.com/boykopovar/AnyPS5/pull/6158) | `core/libs/prx/libc/src/Math.cpp`<br>`core/libs/tests/GuestMath.cpp` | | [PR 6295](https://www.github.com/boykopovar/AnyPS5/pull/6295) | `core/libs/prx/libc/src/Math.cpp`<br>`core/libs/tests/GuestMath.cpp` | | [PR 6879](https://www.github.com/boykopovar/AnyPS5/pull/6879) | `core/libs/prx/libc/src/Math.cpp` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/prx/libc/src/Math.cpp` | | [PR 7332](https://www.github.com/boykopovar/AnyPS5/pull/7332) | `core/libs/prx/libc/src/Math.cpp`<br>`core/libs/tests/GuestMath.cpp` |
fogydes commented 2026-10-19 12:24:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fogydes on 2026-10-19T12:24:52Z.

Review: COMMENTED


The implementation in core/libs/prx/libc/src/Math.cpp and unit test assertions in core/libs/tests/GuestMath.cpp are clean and correct:

  • tgammaf_nid_postfix maps directly to std::tgamma(float).
  • Factorials, half-integers, poles (0.0 \to \infty), and negative values are covered in GuestMath.cpp.
  • Built guest_math_tests.exe locally with MinGW-w64 GCC 15.2.0 (Release) and verified guest_math CTest passes in 0.05s.

The CI conventions workflow is currently failing because the pull request description does not include the template sections from .github/pull_request_template.md. Updating the PR body with the required ### Tested and ### Checklist sections will resolve the CI failure:

### What

PPSA26578 (issue #7624) imports `tgammaf` (NID `B2ZbqV9geCM`) from `libc`, and its bundled `libc.prx` does not export it, causing the process to exit at start-up on `main` with:

```text
0xC0000139 (GetLastError: 127)
unresolved ELF import B2ZbqV9geCM from libc.prx

Currently, core/libs/prx/libc/src/Math.cpp implements tgammal (long double). This exports the single-precision float variant tgammaf:

  • float APS5_VABI tgammaf_nid_postfix(float x) delegating to std::tgamma(float).
  • Unit test coverage in GuestMath.cpp verifying factorials, half-integers, poles, and negative values.

Fixes part of #7624.

Tested

Windows 11, MinGW-w64 GCC 15.2.0 (Release). Built guest_math_tests and verified guest_math CTest passes.

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: PPSA26578 #7624
  • GPUs tested: n/a
  • AI-assisted: no
*(If AI assistance was used, adjust `AI-assisted` to `yes`)*.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5571485255 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7876#pullrequestreview-5571485255). Originally posted by [fogydes](https://github.com/fogydes) on 2026-10-19T12:24:52Z. **Review:** COMMENTED --- The implementation in `core/libs/prx/libc/src/Math.cpp` and unit test assertions in `core/libs/tests/GuestMath.cpp` are clean and correct: - `tgammaf_nid_postfix` maps directly to `std::tgamma(float)`. - Factorials, half-integers, poles ($0.0 \to \infty$), and negative values are covered in `GuestMath.cpp`. - Built `guest_math_tests.exe` locally with MinGW-w64 GCC 15.2.0 (Release) and verified `guest_math` CTest passes in 0.05s. The CI `conventions` workflow is currently failing because the pull request description does not include the template sections from `.github/pull_request_template.md`. Updating the PR body with the required `### Tested` and `### Checklist` sections will resolve the CI failure: ```markdown ### What PPSA26578 (issue #7624) imports `tgammaf` (NID `B2ZbqV9geCM`) from `libc`, and its bundled `libc.prx` does not export it, causing the process to exit at start-up on `main` with: ```text 0xC0000139 (GetLastError: 127) unresolved ELF import B2ZbqV9geCM from libc.prx ``` Currently, `core/libs/prx/libc/src/Math.cpp` implements `tgammal` (long double). This exports the single-precision float variant `tgammaf`: - `float APS5_VABI tgammaf_nid_postfix(float x)` delegating to `std::tgamma(float)`. - Unit test coverage in `GuestMath.cpp` verifying factorials, half-integers, poles, and negative values. Fixes part of #7624. ### Tested Windows 11, MinGW-w64 GCC 15.2.0 (Release). Built `guest_math_tests` and verified `guest_math` CTest passes. ### 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 (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: PPSA26578 #7624 - [x] GPUs tested: n/a - [x] AI-assisted: no ``` *(If AI assistance was used, adjust `AI-assisted` to `yes`)*.
ErenYeager1836 commented 2026-10-19 13:44:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ErenYeager1836 on 2026-10-19T13:44:19Z.


Thanks for the verification @fogydes! Updated the PR description with the required ### Checklist and ### Tested sections. Conventions CI is now passing green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6268696214 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7876#issuecomment-6268696214). Originally posted by [ErenYeager1836](https://github.com/ErenYeager1836) on 2026-10-19T13:44:19Z. --- Thanks for the verification @fogydes! Updated the PR description with the required `### Checklist` and `### Tested` sections. Conventions CI is now passing green.
oneandonlydean commented 2026-10-19 17:22:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-19T17:22:05Z.


guest_math aborts on our Linux CI with this head (run 39282906666; Windows passes). The cause is the new exact checks combined with the host's float tgamma.

tgammaf_nid_postfix returns std::tgamma(x) with a float argument, so it calls the host's tgammaf. glibc only made tgammaf correctly rounded in 2.41. The CI runners use Ubuntu 24.04 (glibc 2.39, GCC 13.3), and there the results for small integers are 1 ulp off:

tgammaf(3)  = 0x1.000002p+1   (2.00000024, want 2)
tgammaf(4)  = 0x1.800002p+2   (want 6)
tgammaf(6)  = 0x1.e00002p+6   (want 120)
tgammaf(10) = 0x1.626002p+18
tgammaf(12) = 0x1.308a82p+25

So Require(... tgammaf_nid_postfix(3.0f) == 2.0f) fails and the test aborts. It passes on newer glibc (2.41+) and on Windows UCRT, which is why it looks fine locally.

FreeBSD's msun, which the console libc follows, computes the float version in double (lib/msun/src/s_tgammaf.c: return (tgamma(x));). Doing the same here fixes it and makes the result independent of the host's float tgamma:

float APS5_VABI tgammaf_nid_postfix(float x) { return static_cast<float>(std::tgamma(static_cast<double>(x))); }

On glibc 2.39 this gives exact results for 1..12 and 1.7724539 for 0.5, so the existing test passes unchanged. Could you switch to the double computation and keep the exact checks?

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6273048489 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7876#issuecomment-6273048489). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-19T17:22:05Z. --- `guest_math` aborts on our Linux CI with this head (run 39282906666; Windows passes). The cause is the new exact checks combined with the host's float `tgamma`. `tgammaf_nid_postfix` returns `std::tgamma(x)` with a `float` argument, so it calls the host's `tgammaf`. glibc only made `tgammaf` correctly rounded in 2.41. The CI runners use Ubuntu 24.04 (glibc 2.39, GCC 13.3), and there the results for small integers are 1 ulp off: ``` tgammaf(3) = 0x1.000002p+1 (2.00000024, want 2) tgammaf(4) = 0x1.800002p+2 (want 6) tgammaf(6) = 0x1.e00002p+6 (want 120) tgammaf(10) = 0x1.626002p+18 tgammaf(12) = 0x1.308a82p+25 ``` So `Require(... tgammaf_nid_postfix(3.0f) == 2.0f)` fails and the test aborts. It passes on newer glibc (2.41+) and on Windows UCRT, which is why it looks fine locally. FreeBSD's msun, which the console libc follows, computes the float version in double (`lib/msun/src/s_tgammaf.c`: `return (tgamma(x));`). Doing the same here fixes it and makes the result independent of the host's float `tgamma`: ```cpp float APS5_VABI tgammaf_nid_postfix(float x) { return static_cast<float>(std::tgamma(static_cast<double>(x))); } ``` On glibc 2.39 this gives exact results for 1..12 and 1.7724539 for 0.5, so the existing test passes unchanged. Could you switch to the double computation and keep the exact checks?
ErenYeager1836 commented 2026-10-19 17:35:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ErenYeager1836 on 2026-10-19T17:35:47Z.


Thanks @oneandonlydean! Switched tgammaf_nid_postfix to compute in double (static_cast<float>(std::tgamma(static_cast<double>(x)))), matching FreeBSD msun (s_tgammaf.c). Verified under Linux (glibc 2.39) that small integer values return exact floats (e.g. tgammaf(3.0f) == 2.0f, tgammaf(5.0f) == 24.0f) without the 1-ULP deviation, keeping the exact test checks intact. Also confirmed tools/check_conventions.py passes cleanly.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6273319646 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7876#issuecomment-6273319646). Originally posted by [ErenYeager1836](https://github.com/ErenYeager1836) on 2026-10-19T17:35:47Z. --- Thanks @oneandonlydean! Switched `tgammaf_nid_postfix` to compute in double (`static_cast<float>(std::tgamma(static_cast<double>(x)))`), matching FreeBSD msun (`s_tgammaf.c`). Verified under Linux (glibc 2.39) that small integer values return exact floats (e.g. `tgammaf(3.0f) == 2.0f`, `tgammaf(5.0f) == 24.0f`) without the 1-ULP deviation, keeping the exact test checks intact. Also confirmed `tools/check_conventions.py` passes cleanly.
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!7876
No description provided.