fix(libc): compute expf with FreeBSD msun's algorithm, as titles' libc.prx does #9839
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9839"
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-22T17:09:31Z.
What
expfreturned the host'sexp, so its last bit and itserrnodepended on the host. On Windows (UCRT) the bits differ from thelibc.prxthat titles ship on 19,194,808 of the 2^32 floats, for example0x3f000306→0x3fd30bca. UCRT also setsERANGEon a different set of arguments from the titles' copy.The titles'
expf(NID8zsu04XNsZ4) is FreeBSD msun'se_expf.c.expfnow computes it the same way:k = invln2*x + halF[xsb]truncated toint;P1/P2rational and the2^kscaling, with thek < -125andk == 128paths;hugeandtwom100read at run time, as msun'svolatilereads do.errno: msun sets none, but the titles' copy setsERANGEin exactly two places: msun's overflow branch (x > o_threshold) and its underflow branch (x < u_threshold). A result that rounds to zero or a subnormal on the general path leaveserrnoalone. For example,expf(0xc2cff1b5)returns+0with noerrnoandexpf(0xc2cff1b6)returns+0withERANGE. NaN and the infinities never set it. This port setsERANGEin those two branches only.expfis imported by 20 of the 22 titles whose relinker registries I audited, for example PPSA01528, PPSA02630 and PPSA04158.Tested
Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release,
BUILD_TESTING=ON,mainb7d1d47a5f.libc.prxof PPSA07923, PPSA05916 and PPSA13934 natively and supplies__error. It compared theirexpfwith this build'sexpf_nid_postfixfor all 2^32 arguments, bits anderrno(an untouched sentinel on our side must match "noerrno" there).errnoeverywhere.errnoeverywhere. The bits differ by 1 ulp on 82,009 arguments, because that copy is an FMA-contracted build, as withasinf(#9771) andacosf(#9668). No single port matches every title's last bit.guest_math: the newCheckExpfConsoleBitshas 23 cases with the console's results anderrno: values in each range where UCRT differs, ±0, tiny, 1, the overflow edge on both sides,FLT_MAX, the infinities, the subnormal-result range, the underflow edge on both sides,-FLT_MAXand NaN payloads of both signs.guest_mathand the libc tests (8) pass in three runs out of three. Withmain'sMath.cppand this test,guest_mathaborts in aRequire.python tools/check_conventions.py --base origin/mainandgit diff --checkpass.tools/pr_overlap.py --branchfinds no conflicting pull request among those it could compare. The branch also merges cleanly with #9771, #9777 and #9784.expf), a console, the floating-point exception flags.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).
Pull request closed