fix(libc): compute cosh with fdlibm's algorithm, as titles' libc.prx does #12122
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12122"
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-27T22:02:27Z.
Fulfilled prerequisite: #10234 merged; its head
2c8a5d59f81da182b1ec734ea0914c587eb3f784is an ancestor of pinned main and refreshed head598429f215aae6bde10e0eb3703bb6bd24fe8157.What
coshreturned the host'sstd::cosh. On 300,000 random arguments, that is one unit in the last place away from thelibc.prxthat titles ship on 20,045 of them (about 7%). It now follows fdlibm'se_cosh.c, using this file'sexpm1andexp:abs(x)x * x1 + t²/(2(1 + t)), wheret = expm1(abs(x));1 + tbelow 2^-55(exp(abs(x)) + 1/exp(abs(x)))/2exp(abs(x))/2w/2 · w, wherew = exp(abs(x)/2)ERANGEIn the second-to-last range, FreeBSD 11.4's msun uses
__ldexp_exp. The titles don't: with__ldexp_exp, 111,042 of 400,000 arguments around the thresholds came out 2 ulp away from them. fdlibm's originalexp(abs(x)/2)product, with its exact low-word threshold, matches.Tested
Current-main integration — 2026-11-03. Head
598429f215aae6bde10e0eb3703bb6bd24fe8157includes main4f41f4c375f5abb487dbd184fbc150f31994d762and retains the prior public history and attribution/licence notices. Main’s newer math implementations and fixtures remain alongside this topic. #10234 is merged; its actual head is already in main. One duplicate, byte-identical exp fixture definition was removed; its unchanged body and single call remain.Linux x86-64 Release, GCC 16.2.1, Ninja, BUILD_TESTING=ON: rebuilt actual libc and math executables.
guest_math,guest_math_exact, andguest_dinkumware_internalseach pass 3/3 (9 passes, zero skips);public_headersand conventions pass. The same three groups pass 3/3 plus headers on pinned main. All 34 recursive dependency trees and 31,551 tracked blobs verify with zero errors; the update=none QuickJS test262 corpus is excluded from these library inputs.git diff --checkreports the preserved verbatim licence trailing-space line; no other whitespace warnings occur.Source/parent/gitlink proofs, exact library/test hashes, raw logs/JUnit, and head-leased push receipts: qualification archive, SHA-256
e6a50522bc28e30871fdc2c12a88d2537515914239e8166f6237f48895126a06(download verified). Older platform/reference reports retain their original pins; no new Windows/macOS, SDK-module, console, title/GPU or performance claim. AI-assisted: yes (Codex).Earlier dated qualifications below retain their recorded source/platform pins.
Current-main refresh — 2026-11-02. Published head
e02f1f640e09a52019066824002eb976db1c8bf4includes pinned maina4eca2a056bf3bbbec98ab42e9d28163e4ea9cb8. The actualc988f73cexp prerequisite ancestry and full retained Sun/FreeBSD notice remain. The exp and cosh bodies are byte-identical to the previous public head; exact cosh(+1)/cosh(-1) bits and errno fixtures remain. Main’s atan/log10/log2 functions and fixtures are retained.Rebuilt actual libc/Ampr and selected tests from the final input tree.
guest_math,guest_math_exact,guest_dinkumware_internalseach pass three consecutive runs: 9 runtime passes, zero skips, plus public_headers. Conventions and whitespace pass. Source/input manifests, exact dependencies, library/test hashes, logs/JUnit and head-leased push receipts are attached. The same pinned main passes 18 selected groups three times (54 runtime passes) plus headers. All 34 recursive dependency trees/31,551 tracked blobs verify with zero errors; QuickJS’s update=none test262 corpus is explicitly excluded because it is not a library build input.Linux-7.2.11-arch1-1-x86_64-with-glibc2.44, Ryzen 9 7950X, GCC 16.2.1, Ninja Release, BUILD_TESTING=ON. Focused Linux CPU qualification only. Older Windows/module/reference reports retain their original pins; no fresh Windows/macOS, SDK-module, console, title/GPU or speed claim. AI-assisted: yes (Codex).
Evidence: https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/math-six-main-a4eca-linux-extra10321-20261102.tar.gz; SHA-256 525ccb31a5d3d0f5adced5fda58818d8432f06c0afa7290139adb60ae6664b54.
Earlier dated qualifications below retain their recorded source/platform pins.
Current Linux review follow-up (2026-10-31), head
5abea905c268ab1e44f60c15da751fdfbfd976e9: test-only fast-forward ofe0415047dc; productionMath.cppis unchanged. Clean merge-tree against checked main32bf44ca7c6.CPU-only native calls to the original PPSA07923 bundled libc module, with default floating controls and
FE_TONEAREST, produce0x3ff8b07551d9f550for bothcosh(+1)andcosh(-1)and preserve seedederrno=7. The unpatched converted function matches all 261 bytes in the unwrapped original. These are bundled-module results on Linux, not physical-console measurements.CheckHyperbolicnow checks those exact result bits and errno for both signs.Negative control: substituting msun's alternate
exp(1)bit inside cosh's ±1 calculation produces the one-ULP-higher0x3ff8b07551d9f551. The old tolerance fixture passes; the new exact fixture fails at its new assertion. After restoring production code,guest_math,guest_math_exactandguest_dinkumware_internalspass (3/3, no skips), with matching direct HLE/reference results. Conventions and whitespace checks pass. Arch Linux 7.2.11, Ryzen9 7950X, GCC16.2.1, Release/BUILD_TESTING=ON.Reference hashes/results, probe, negative-control logs, final JUnit, linkage and test patch, download-verified SHA-256
3b464a76ae9be24bf07b54c1b1f4c023144987e14951236216bb165f541c5fd1. No SDK/game code or binaries are attached. AI-assisted: yes (Codex).Original Windows qualification (original pins):
Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release,
BUILD_TESTING=ON, onmainf759e165d9with #10234's head138f4397d7.Comparison: a scratch loader runs the decrypted
libc.prxof three titles natively. Each call compares the result bits anderrno:mainvs PPSA07923errnoerrnoTests:
guest_mathpins titles' bits for one argument in each finite range. It also checks that these leaveerrnoalone, that an overflowing argument setsERANGE, and that-infand NaN leaveerrnoalone.std::coshline and these tests,guest_mathfails.python tools/check_conventions.py --base origin/mainandgit diff --checkpass.coshentry records what was measured.Not tested: macOS and floating-point exception flags. Linux qualification is recorded 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)2c8a5d59f81da182b1ec734ea0914c587eb3f784retained in ancestry)AI-assisted (Claude Code).