fix(libc): keep lgamma finite for subnormal arguments on Windows #5775
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5775"
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 wachi35676 on 2026-10-14T10:04:12Z.
What
lgamma_nid_postfix(core/libs/prx/libc/src/Math.cpp) forwards to the hoststd::lgamma. The MinGW-w64lgammareturns +inf and raises FE_OVERFLOW for nonzero |x| at or below 2^-1024 (e.g.lgamma(0x1p-1074)), where the value is finite: -log(2^-1074) ≈ 744.44.FreeBSD's msun handles this range explicitly before its general path (
lib/msun/src/e_lgamma_r.c, releng/11.4):lgamma_nid_postfixnow takes the same branch for nonzero |x| < 2^-56 and otherwise still calls the host. Zero, infinities, NaN and every |x| ≥ 2^-56 are unchanged. Compared with an unmodified FreeBSD 11.4 msun build,lgamma(±0x1p-1074)now returns the same bits (0x40874385446d71c3); for 2^-60 … 2^-1000 the host already agreed with-log|x|to the last digit.Tested
Windows 11 26200, WinLibs GCC 15.2.0 UCRT, full build with
BUILD_TESTING=ONonmaineecf90953.core/libs/tests/GuestMath.cpp(guest_math) for ±denorm_min, ±2^-1025, ±2^-1022 and ±2^-57, and that no FE_OVERFLOW, FE_DIVBYZERO or FE_INVALID is raised. Fails onmain, passes with this change.python tools/check_conventions.py --base origin/mainpasses.The new check fails on
mainonly on Windows; glibc'slgammaalready returns the finite value, so on Linux it passes before and after. Not tested: Linux and macOS builds.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T00:40:40Z.
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)core/libs/prx/libc/src/Math.cppL304-305core/libs/prx/libc/src/Math.cppL305core/libs/tests/GuestMath.cppL926core/libs/prx/libc/src/Math.cppL305core/libs/tests/GuestMath.cppL926lgamma_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.cppImported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-15T12:50:38Z.
Checked the threshold (0x3c70000000000000 = 2^-56) and the -log|x| branch against FreeBSD
e_lgamma_r.c; zero, inf, NaN and |x| ≥ 2^-56 still go to the host. Build and ctest (incl.guest_math) pass on Linux; the new rows only fail on MinGW, so the Windows job of the full Build is the evidence. Merging once it is green.