Repository navigation
feat(libc): implement lgammaf, tgamma, and tgammaf - #6158
freshstart2066-create wants to merge 1 commit into
Conversation
|
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.
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.
|
|
On Windows,
This is the float counterpart of #5775 (merged), which fixed the same MinGW behaviour for Also, the AI-assisted: yes (Claude Code); results above were run on this machine. |
adriadam10
left a comment
There was a problem hiding this comment.
Thanks for the PR. Changes needed:
core/libs/prx/libc/src/Math.cpp:251lgammaf_nid_postfixreturns the hoststd::lgamma(float), which is wrong on MinGW for tiny negative arguments (-2.6e-23fgivesinf, see @wachi35676's measurements above).lgamma_nid_postfixonmainalready handles this (#5775:-log|x|below a threshold, following FreeBSDe_lgamma_r.c; FreeBSD'se_lgammaf_r.chas the same branch). Please do the same for the float version.lgamma_nid_postfixonmainalso setssigngam_nid_postfix;lgammafshould set it the same way (FreeBSDlgammaf_rdoes).- Tests: add tiny-argument rows (
±1e-30f,±denorm_min) and asigngamcheck forlgammaf; with the current rows the Windows bug is invisible. Fortgamma/tgammaf, exact== 6style checks depend on the host libm (MinGW'stgammais not guaranteed exact for integers); either use a tolerance or implement it from FreeBSD msun, and add a pole row (0,-0) next to the-1NaN row. - The branch conflicts with
maininMath.cppandGuestMath.cpp(lgammaarea changed by #5775); please rebase. - #6414 also adds
tgamma/tgammaf; this PR came first, so that one should drop them.
|
Measurement for the open review point on tgamma exactness: how MinGW's host tgamma/tgammaf does on integer arguments. Windows 11, WinLibs GCC 15.2.0 r7 (x86_64-ucrt-posix-seh), -O0, arguments passed through volatile so nothing is folded at compile time. A standalone program, not this PR's code; it calls std::tgamma(double) and std::tgamma(float) and compares tgamma(n) with (n-1)!.
So an exact tgamma(4) == 6 style check passes here only for small n; tolerances or an own implementation are needed for the rest, as the review says. I did not build this PR; only the host functions were measured. Not measured: Linux/glibc, other MinGW versions. AI-assisted: yes (Claude Code). |
|
Console data for Compared with the host functions this PR calls, from a test program built with WinLibs GCC 15.2.0 on Windows:
The probe source and the full log are in lgamma-probes.zip (p14). For AI-assisted: yes; the host results above were run on this machine. |
|
Closing this in favour of #8417, which covers lgammaf, tgamma and tgammaf and merges cleanly with main. Thanks for the work here. |
What
Guest game engines, procedural generation systems, and audio synthesis runtimes require the true gamma function (
tgamma,tgammaf) and single-precision log-gamma (lgammaf). While double-precisionlgammawas previously supported, missingtgamma,tgammaf, andlgammafexports cause dynamic linker resolution failures at guest boot.This PR implements:
lgammaf(lgammaf_nid_postfix)tgamma(tgamma_nid_postfix)tgammaf(tgammaf_nid_postfix)Implementation Details
std::lgammaandstd::tgammaadhering to C99 standards and factorial/pole behaviors for integers and negative values.core/libs/tests/GuestMath.cppcovering standard factorial values (e.g.tgamma(4) == 6), half-integers (tgamma(0.5) == sqrt(pi)), negative integer pole NaNs, and single/double precision log-gamma.Tested
core/libs/tests/GuestMath.cpp(guest_math).upstream/mainwith 0 conflicts (tree:290489a8ffbf8ea7f85a891a13b1e526931fcac7).python tools/check_conventions.py --base 584cc4c57:All conventions checks passed.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)Co-authored-by: Nawasfadili nawasfadili@users.noreply.github.com