fix(libc): lgamma stores 1 in signgam for -0 #17026
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/17026"
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 xXPBSXx on 2026-11-08T08:27:29Z.
What
lgammastored -1 insigngamfor an argument of -0, following FreeBSD'se_lgamma_r.c. On a PS5lgamma(-0.0)stores 1, aslgamma(+0.0)does. This stores 1 for both zeros. The result,errnoand the exception flags still come from the host'slgammaand are not changed. A test pins the sign for -0, and the debt entry forlgammaandsigngamindocs/dev/debt/libc.mdstates the measurement. A title process was not measured.Tested
Measured on a PS5 with firmware 11.60 (
kernel_get_fw_version0x11600005), from a homebrew payload process (ps5-payload-sdk v0.45, elfldr), on 2026-11-08 at 03:58 UTC. A title process may differ.signgamwas set to 7 before each call; the cases are 2.14 and 2.15 of the raw output in the first comment. The other 25 value cases of the run (positive values, negative non-integers, the poles -1 and -2, tiny and huge values, both infinities and NaN) store the same sign asmaindoes; only -0 differs.mainbeforelgamma(0.0), thensigngamerrno34)lgamma(-0.0), thensigngamerrno34)On this branch, Linux (WSL, Release) on
main62e7ca86763c: with only the test commitguest_mathfails in 3 of 3 runs (GuestMath.cpp:3677), and with the fix it passes in 3 of 3 runs.tools/check_conventions.py --base upstream/mainpasses. The probe source and its raw output are in the first comment. Not tested: Windows, macOS, the CI runner, a title process and any other firmware.Overlap (P2, 2026-11-08, list of open pull requests from 07:40 UTC,
main4b37092bef, checked 07:40-07:46 UTC, head78dc9f8bf733): of the 119 open pull requests that changecore/libs/prx/libc/src/Math.cpp,core/libs/tests/GuestMath.cppordocs/dev/debt/libc.md, each was merged with and without this branch. Two conflict only with this branch: #8417 (implement tgamma, lgamma, and gamma math functions), which rewrites the samelgammafunction inMath.cpp(aslgamma_r, built on #7544) and keeps the sign -1 for -0 that FreeBSD's source gives and this measurement did not find, so whichever lands second must take the measured sign; and #16613 (ours, a documentation change indocs/dev/debt/libc.md). 40 conflict withmainwithout this branch as well; the other 77 merge cleanly with and without it.Checklist
main; no other open PR implements the same functions (based on currentmain, but #8417 also rewriteslgamma; see Overlap)NotImplemented_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)AI-assisted (Claude Code).
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by gabichuuuuu on 2026-11-08T16:42:12Z.
Review: COMMENTED
Windows run of head
78dc9f8bf7, merged ontomain828e44310e. To save builds, this ran in one local tree together with 13 other open PRs that touch different files. All 14 merged cleanly. Setup: Windows 11, WinLibs GCC 15.2 (x86_64-ucrt-posix-seh), Release,BUILD_TESTING=ON.guest_mathwith--repeat until-fail:10: 10 / 10 pass.main'slibc/src/Math.cppand this PR's test: 5 / 5 runs fail. With the PR's file put back, it passes again.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-11-12T04:39:48Z.
Review: CHANGES_REQUESTED
Thanks for the PS5 measurement. Two things block this as it stands:
conventionsfails: the checklist lineBased on current main; no other open PR implements the same functionsis unchecked. The change to thesigngamline for-0inlgamma_nid_postfix(core/libs/prx/libc/src/Math.cpp:1897) and the matchingGuestMath.cpp:4019pin are the same one #7544 already makes (measured on firmware 12.70), and #7544 also covers theerrnoat poles. Please list #7544 under Depends on and tick the line, or drop the code and test change.lgammadebt entry (docs/dev/debt/libc.md:218), the useful part left here is your firmware 11.60 measurement: once #7544 lands, rebase on it and keep only the debt text that adds the 11.60 result (and the 25 other value cases), so the two measurements sit in one entry.The tests themselves look right: the
-0pin fails onmainand passes with the fix, as the Windows runs by @JJenkx and @gabichuuuuu show.Pull request closed