fix(libc): compute atanf with FreeBSD msun's algorithm, as titles' libc.prx does #9777
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9777"
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-22T14:35:24Z.
What
atanfreturned the host'satan, so its last bit depended on the host. On Windows (UCRT) it differs from thelibc.prxthat titles ship on 6,481,820 of the 2^32 floats. Examples, console thenmain:0x3f40077e→0x3f24c148,maingives0x3f24c149;0x4080055c→0x3fa9b5a8,maingives0x3fa9b5a7.The titles'
atanf(NIDweDug8QD-lE) is FreeBSD msun'ss_atanf.c.atanfnow computes it the same way:atanhi/atanlotables and the odd/even split of theaTpolynomial;atanlo[3]read at run time, as msun'svolatileread does.The constants are written as msun writes them, decimal values converted to float. The build targets baseline x86-64, so nothing is contracted into FMA. Tiny arguments return
xwithout raisingFE_INEXACT. None of the copies checked setserrno, and neither does this.atanfis imported by 21 of the 22 titles whose relinker registries I audited, for example PPSA01528, PPSA02630 and PPSA09614. Unlikeasinf(#9771) andacosf(#9668), the FMA-contracted copy bundled with PPSA13934 gives the same bits here, so one port matches every copy checked. This is a separate topic from #9771 and does not depend on it; the two branches merge without conflicts.Tested
Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release,
BUILD_TESTING=ON,main8b3e39832a.libc.prxof PPSA07923, PPSA05916 and PPSA13934 natively and supplies__error. Theiratanfand this build'satanf_nid_postfixgive the same bits for all 2^32 arguments, NaN payloads included, and neither setserrno.guest_math: the newCheckAtanfConsoleBitshas 17 cases with the console's outputs: each of the five argument ranges, both signs, 1,2^26and the infinities, a NaN payload, -0, the smallest subnormal and tiny.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.5e03230c2merged 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.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).
Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-22T18:17:13Z.
Review: APPROVED
Checked against main
a6646f8464and FreeBSD 11.4lib/msun/src/s_atanf.c:a6646f8464, and main still returns the hoststd::atan.x+x, the odd/evenaTsplit and the sign handling matchs_atanf.cline by line. The float-rounded tables give exactly the hex values in msun's comments (0x3eed6338 … 0x33a22168).volatilelocal foratanlo[3]has the same effect as msun's volatile-pointer read.huge+x>oneraises FE_INEXACT, which this skips, and that is already in the debt entry.-marchflags in main's CMake, so baseline x86-64 holds.CheckAtanfConsoleBitsexpectations with a float32-rounded emulation of msun's algorithm, and all 16 match.Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.