Repository navigation
fix(libc): keep lgamma finite for subnormal arguments on Windows - #5775
Merged
adriadam10 merged 1 commit intoOct 15, 2026
Merged
Conversation
The MinGW-w64 lgamma overflows to infinity for nonzero |x| at or below 2^-1024. FreeBSD msun e_lgamma_r.c returns -log(|x|) for every nonzero |x| below 2^-56, so take that branch before the host function. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
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.
|
This was referenced Oct 15, 2026
11 tasks done
11 tasks done
Collaborator
|
Checked the threshold (0x3c70000000000000 = 2^-56) and the -log|x| branch against FreeBSD |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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