fix(libc): preserve tgammaf underflow sign #10467
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10467"
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 MarcZX10 on 2026-10-24T01:55:10Z.
What
The Windows
tgammafwrapper delegates to the host's doubletgammaand casts the result, matching FreeBSD 11'ss_tgammaf.c. For negative non-integer inputs whose result underflows to zero, the sign of Γ alternates with the parity offloor(-x). Nine title-bundledlibc.prxbuilds return the corresponding signed zero, while Windows UCRT can return the opposite sign for those inputs. This preserves the host result except when the float result is zero and the input is a finite negative non-integer.The measurements and broader platform survey are in #9707. This PR fixes only the
tgammafsigned-zero discrepancy; it does not claim to resolve the survey's other math differences.Tested
Math.cppand a focused executable with-Wall -Wextra -Werror; negative and positive underflow cases passed and produced-0and+0respectively.core/libs/tests/GuestMath.cpp.-Wall -Wextra -Werror; the full MinGW syntax check ofMath.cppwas also attempted, but this toolchain does not declare the existing POSIXj0/j1/jn/y0/y1/ynsymbols; no Windows runtime was available.tools/check_conventions.py --base upstream/mainandgit diff --checkpass.guest_mathand the full project build were not run locally. No title or console run was performed.Checklist
main; no other open PR implements the sametgammafbehaviorNotImplemented_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 harisibrar1 on 2026-10-24T04:57:49Z.
Review: APPROVED
Checked against main
6c52b649e7and FreeBSD release/11.4.0lib/msun/src/s_tgammaf.candlib/msun/bsdsrc/b_tgamma.c:tgammafis justreturn (tgamma(x));, so keeping the double delegation matches it.neg_gammakes the result negative whenceil(x)is even and returnssgn*tiny*tinybelow -190, so your "floor(-x)even ⇒ negative" rule is the same condition. A Python check over 2M random negative non-integer floats gave 0 mismatches, and both test inputs give the right sign.tgammaadded there would need the same sign handling?Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.