fix(libc): compute expm1 with FreeBSD msun's algorithm, as titles' libc.prx does #10306
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10306"
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 JJenkx on 2026-10-23T17:02:57Z.
What
expm1returned the host'sexpm1, so its last bit and itserrnodepended on the host. On Windows (UCRT) it differs from thelibc.prxthat titles ship on 35,152,346 of 320 million random arguments. For example,expm1(0x3fc78b9e474afed8)(about 0.184) is0x3fc9d99e60806b35in the bundledlibc.prxand0x3fc9d99e60806b36here.The titles' copy (NID
gqKfOiJaCOo) is FreeBSD msun'ss_expm1.c.expm1now computes it as a staticExpm1:|x| >= 56 ln2filter, with the large-negativetiny - 1return;k = ±1and general argument reductions with theccorrection;Q1–Q5rational;kcase of the reconstruction, includingk == 1024and the subnormal scaling.hugeis read at run time, as msun'svolatileread does. This is the double-precision counterpart of theexpm1fin #10222.errno: msun sets none. The titles' copy setsERANGEexactly when a finite argument overflows to infinity, which is the same rule as itsexpm1f. Large negative arguments return -1 withouterrno, and so do NaN and the infinities. The exportedexpm1setsERANGEin that case only.Tested
Current Linux refresh:
99abd2604d53b7588b6386de012527c60ad6dcc7on main6c52b649e7b1592f28db0cb8fe9ac604f0a242e7. Fresh isolated libc/math build passed;guest_mathandguest_dinkumware_internalseach passed three consecutive runs. Diff and conventions checks pass; Math.cpp and GuestMath.cpp topic changes remain unchanged after rebase. Linux logs and rebase checks.The Windows module comparisons and negative control below are historical evidence from original head
92e60da1cc495f62a17a81000fb5778dec79df44; Windows was not rerun on the refreshed commit. Results described as console results mean the supplied titles' bundled libraries executed on the Windows host, not measurements on a physical console.Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release,
BUILD_TESTING=ON,main1e1c355a54.Comparison: a scratch loader runs the decrypted
libc.prxof PPSA07923, PPSA05916 and PPSA13934 natively and supplies__error. It compared theirexpm1with this PR's code, checking result bits (NaN payloads included) anderrno, on:Results:
errnoon all of them.errno. The bits differ on 43,433 random arguments, because that copy is an FMA-contracted build.guest_math: the newCheckExpm1ConsoleBitshas 30 cases with the bundled library's results anderrno:±DBL_MAX, the infinities and NaN payloads of both signs;main's existingexpm1checks still pass.guest_mathandguest_dinkumware_internalspass in three runs out of three on the exact head.Negative control: with
main'sMath.cppand these tests,guest_mathaborts in aRequire, whileguest_dinkumware_internalsstill passes.python tools/check_conventions.py --base origin/mainandgit diff --checkpass.Overlap and order: Refreshed as one standalone expm1 topic on main
6c52b649e7b1592f28db0cb8fe9ac604f0a242e7. The prior #10283 dependency described series order, not a required implementation. Nearby math ports share text/test/debt anchors. #10316 still requires this PR's internal Expm1 helper.Not tested: macOS, a physical console, floating-point exception flags, and
expm1l. The original module comparison and negative control were Windows-only; the new Linux build and regression checks are scoped separately above.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)sinhfentry didAI-assisted (Claude Code).