fix(libc): compute log1pl, acoshl, asinhl and atanhl as titles' libc.prx does #18694
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/18694"
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-11-12T02:43:49Z.
What
libc's
log1pl,acoshl,asinhlandatanhlreturned the host C library's results. Thelibc.prxthat titles bundle computes them with its own Dinkumware code on top of_LLog,sqrtland_Feraise, all of which this libc already has. Run natively on Linux, that code andmaindisagree on a large share of arguments (table below).This PR follows that code (PPSA08194's
libc.prx, relinked:log1pl0x40a80,acoshl0x40990,asinhl0x41620,atanhl0x42110), operation by operation. All four run at the caller's x87 precision and never touch the control word, as the binary does.log1pl(x):x < -1raisesFE_INVALID(_Feraise(1),EDOM) and returns a quiet NaN.-1raisesFE_DIVBYZERO(_Feraise(4)) and returns −∞.|x| < 2^-66returnsx.u = 1 + x, the result is_LLog(u, 0) + ((u - 1) - x) * (-1 / u).acoshl(x):x < 1, −∞ included, raisesFE_INVALIDand returns NaN.1returns +0.x >= 2^67returns_LLog(x, 0) + ln 2.t = x - 1, the result islog1pl(sqrtl(x * t + t) + t).asinhl(x):a = |x|: below2^-66the result isa; from2^67it is_LLog(a, 0) + ln 2; otherwise it islog1pl(a / (sqrtl(a * a + 1) + 1) * a + a).xis applied to the result.atanhl(x):a = |x|:a > 1, ±∞ included, raisesFE_INVALIDand returns NaN, anda == 1raisesFE_DIVBYZEROand returns ±∞.2^-33the result isx; otherwise it is0.5 * log1pl(2 * (a / (1 - a))), with the sign ofx.Comparisons follow the binary's branches for unordered operands as well: a pseudo-infinity such as
ffff:0000000000000000is not a NaN to_LDtest, compares unordered, and goes where the binary'sjbesends it (acoshltakes theloglbranch and reportsEDOMfrom_LLog).The constants, read from the loaded module, are a quiet NaN, +∞,
2^-66,2^-33,2.0f(giving2 / 2^-66 = 2^67),0.5f, and the 80-bitln 20xb.17217f7d1cf79acp-4. The binary'sloglis_LLog(x, 0)(#18110 routes the export there), so this PR calls_LLogdirectly and does not depend on #18110.Tested
Oracle. A small probe
dlopens the title's relinkedlibc.prx(PPSA08194,libc.prx.guest.prx) next to this libc and calls both on the same arguments. There are 1,000,160 arguments per function: random exponents across the whole range and near 1, random mantissas, and fixed cases (zeros, infinities, NaNs, a pseudo-infinity, and both sides of every cutoff). It compares result bits,errno, andFE_INVALID/FE_DIVBYZERO/FE_OVERFLOW/FE_UNDERFLOW, with the x87 control word set to 64-, 53- or 24-bit precision for the call.main, 64 bitsmain, 53 bitsmain, 24 bitslog1placoshlerrno)errno)errno)asinhlatanhlmainalso differs in exception flags on 3 to 16 arguments per function and precision; this PR differs on none.Tests.
guest_dinkumware_internals_testsgainsTestLongInverseHyperbolic: 51 exact-bit cases at 64 bits, including every cutoff on both sides, ±1, ±∞, a pseudo-infinity and the error results with theirerrnoand flags. It adds 12 cases at 53 bits that also check the control word is unchanged. The expected values come from the binary through the probe.The "this PR" column uses this branch's built
libc.prx(headc0d823f4da). A control run ofmain's build through the same probe reproducesmain's differences.ctest -R "guest_dinkumware_internals|guest_math|guest_bessel": 5/5 pass (guest_dinkumware_internals,guest_math,guest_math_elementary,guest_math_exact,guest_bessel). Linux 7.2.14, Ryzen 9 7950X, GCC 16, Release. Not run on Windows or macOS.python3 tools/check_conventions.py --base origin/main: no errors. The one warning is the host-computed long-double entry, which was already over 1,000 characters; this PR shortens it by removing these four functions.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)Current branch: one commit
d035a8ebd3ccon main7b60f8ad8662. The four reviewed function bodies are unchanged. A debt fragment updates main's current host-results entry in place, removing these four names and retaining one separate implementation entry; erfl/erfcl are not re-added. Fresh Linux rebuiltguest_mathandguest_dinkumware_internalsboth pass with frozen executable/dependency hashes; conventions and debt folding pass. Current validation and rendered debt. Prior numerical/module comparisons above are historical evidence, not rerun in this refresh.Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-12T06:12:01Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
c0d823f4da:tools/check_conventions.pypassed;git diff --checkclean.guest_dinkumware_internals_testsbuilt cleanly.guest_dinkumware_internals):core/libs/prx/libc/src/Math.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Generated withfooter from the description; the AI-assisted checkbox can stay.Looks Good To Me