fix(libc): compute sinf, cosf, tanf and sincosf with FreeBSD msun's algorithms, as titles' libc.prx does #9857
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9857"
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-22T19:09:25Z.
What
sinf,cosf,tanfandsincosfreturned the host'ssin,cosandtan, so their last bit depended on the host. On Windows (UCRT), counted over all 2^32 floats against thelibc.prxthat titles ship:sinfdiffers on 3,349,410;cosfon 3,382,210;tanfon 303,874,018 (7 %).For example,
tanf(0x3fc00321)is0x4161edb0on the console.The titles' versions are FreeBSD msun's
s_sinf.c,s_cosf.cands_tanf.c. Theirsincosf(NIDpztV4AF18iI) returns exactlysinf's andcosf's results. This PR ports:k_sinf.c,k_cosf.candk_tanf.c;n·π/2octant tables of the three entry points;e_rem_pio2f.c: its medium path (|x| < 2^28·π/2) uses three double operations, and larger arguments go throughk_rem_pio2.c;k_rem_pio2.conly for what a float uses: one input word,prec0, and the first 66ipio2digits, of which a float reaches only a few.All of this goes into
Math.cppas static helpers;sincosfcalls the two ports.errno: only an infinite argument setsEDOMon the console; NaN leaves it alone. The ports do the same.sinf,cosfandtanfare each imported by 21 of the 22 titles whose relinker registries I audited, for example PPSA01528, PPSA02630 and PPSA09614. Because the kernels work in double precision, the FMA-contracted copy of PPSA13934 gives the same bits here, so one port matches every copy checked.Tested
Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release,
BUILD_TESTING=ON,maina6fc8a467d.Exhaustive comparison: a scratch loader runs the decrypted
libc.prxof PPSA07923, PPSA05916 and PPSA13934 natively and supplies__error.sinf,cosfandtanfand this build's give the same bits anderrnofor all 2^32 arguments: 9 runs, 0 differences.sincosfequals the portedsinf/cosfpair for all 2^32 arguments.guest_math: the newCheckTrigfConsoleBitshas 21 inputs, each checked through all four functions with the console's results anderrno:2^28·π/2boundary and thek_rem_pio2range up to±FLT_MAX;EDOM) and a NaN payload.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.Overlap: the branch merges without conflicts with my other math PRs (#9771, #9777, #9784, #9839, #9841, #9844, #9850).
tools/pr_overlap.pyfinds one adjacency inMath.cppwith #8417, whose new gamma functions end just abovesinf; keeping both resolves it.Independent Linux review: Dom3005's report tested head
e601dbd7amerged cleanly ontomainfcd455870: Ubuntu 26.04 in Docker on Windows, GCC 15, glibc 2.43, WSL2 kernel 6.6, Release,BUILD_TESTING=ON. The reviewer reports five passingguest_mathruns (--repeat until-fail:5). Keeping this PR's test while restoring main's changed production sources makes the test fail on Linux as well. This supplies a Linux regression comparison in addition to the Windows evidence above; it is reviewer-supplied evidence for those revisions, not a local rerun or a latest-main claim.Not tested: macOS, 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 did (this one is larger because of the argument reduction)AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T03:46:01Z.
Review: APPROVED
Reviewed exact head
e601dbd7a41f92133e62c300214d63b187c98e3b. The float entry points and reduction/kernel code follow the FreeBSD 11.4 msun routines named in the change; the PR also records exact console-library comparisons for all 2^32 float inputs and errno behavior. The production and test files are unchanged between their tested base and current upstreammain; only the debt index changed in that interval.I locally built the exact PR
Math.cppand test source and ran its isolatedCheckTrigfConsoleBitscheck on Linux; all 21 inputs acrosssinf,cosf,tanf, andsincosfpassed. This used an existing older configured build, not a fresh current-main build. Independent reviewer evidence on this head reports five passing Linuxguest_mathruns; the author reports repeated Windows tests and exhaustive comparisons. Required hosted checks pass; product jobs are skipped.