feat(libc): export tgammaf float math function #7876
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7876"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by ErenYeager1836 on 2026-10-19T11:58:19Z.
What
Export
tgammaf_nid_postfix(float x)incore/libs/prx/libc/src/Math.cppdelegating directly tostd::tgamma(float).Fixes part of #7624, unblocking unresolved import
B2ZbqV9geCMin PPSA26578 (Unity/IL2CPP).Tested
core/libs/tests/GuestMath.cpp:tgammaf(1.0f) == 1.0ftgammaf(5.0f) == 24.0f(exact 4!)tgammaf(0.5f)matches\sqrt{\pi}0.0f \to \inftypython tools/check_conventions.pypasses 100%.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repositoryImported 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
tgammaf_nid_postfixImported 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.
main)tgammaf_nid_postfixSome 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.
core/libs/tests/GuestMath.cppcore/libs/prx/libc/src/Math.cppcore/libs/tests/GuestMath.cppcore/libs/prx/libc/src/Math.cppcore/libs/tests/GuestMath.cppcore/libs/prx/libc/src/Math.cppcore/libs/prx/libc/src/Math.cppcore/libs/prx/libc/src/Math.cppcore/libs/tests/GuestMath.cppImported from boykopovar/AnyPS5. Originally posted by fogydes on 2026-10-19T12:24:52Z.
Review: COMMENTED
The implementation in
core/libs/prx/libc/src/Math.cppand unit test assertions incore/libs/tests/GuestMath.cppare clean and correct:tgammaf_nid_postfixmaps directly tostd::tgamma(float).0.0 \to \infty), and negative values are covered inGuestMath.cpp.guest_math_tests.exelocally with MinGW-w64 GCC 15.2.0 (Release) and verifiedguest_mathCTest passes in 0.05s.The CI
conventionsworkflow 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### Testedand### Checklistsections will resolve the CI failure:Currently,
core/libs/prx/libc/src/Math.cppimplementstgammal(long double). This exports the single-precision float varianttgammaf:float APS5_VABI tgammaf_nid_postfix(float x)delegating tostd::tgamma(float).GuestMath.cppverifying factorials, half-integers, poles, and negative values.Fixes part of #7624.
Tested
Windows 11, MinGW-w64 GCC 15.2.0 (Release). Built
guest_math_testsand verifiedguest_mathCTest passes.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)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
### Checklistand### Testedsections. Conventions CI is now passing green.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-19T17:22:05Z.
guest_mathaborts on our Linux CI with this head (run 39282906666; Windows passes). The cause is the new exact checks combined with the host's floattgamma.tgammaf_nid_postfixreturnsstd::tgamma(x)with afloatargument, so it calls the host'stgammaf. glibc only madetgammafcorrectly 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: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 floattgamma: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?
Imported from boykopovar/AnyPS5. Originally posted by ErenYeager1836 on 2026-10-19T17:35:47Z.
Thanks @oneandonlydean! Switched
tgammaf_nid_postfixto 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 confirmedtools/check_conventions.pypasses cleanly.