fix(libc): compute atan and atan2 with FreeBSD msun's algorithm, as titles' libc.prx does #10229
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10229"
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-23T14:52:59Z.
What
atanandatan2returned the host'satanandatan2, so their last bit depended on the host. On Windows (UCRT) they differ from thelibc.prxthat titles ship on 157,812 and 19,525,273 of 320 million random arguments. For example,atan(0x3fad508ceb7f682c)is0x3fad485dbf410edfon the console, andatan2(0x3fe774163fc8a61c, 0xbfa03b1919b0841e)is0x3ff9d308efab3d4e; UCRT returns a value 1 ulp away for each.The titles' copies (NIDs
OXmauLdQ8kYandHUbZmOnT-Dg) are FreeBSD msun'ss_atan.cande_atan2.c. Both now compute them:atan: the five-range argument reduction, theatanhi/atanlotables and the 11-term polynomial split into odd and even halves.atan2: the NaN, signed-zero and infinity cases, thex == 1shortcut toatan, and the|y/x| > 2^60and< -2^-60shortcuts.tiny,pi_loand the low part ofatan(inf)are read at run time, as msun'svolatilereads do.Neither function sets
errno, as the titles' copies do not. This is the double-precision counterpart of #9777 and #9784, and it does not touch their code.Tested
Current Linux refresh (2026-10-25): head
0cb4709c54e709d11672fb55400f66c36b2e7911, the ownatan/atan2topic directly on newly published #10222 head057bca52441f84ec539e382428892d3dc3982d1c. The linear stack is based on main366dd4e6b704b048e05eee65e0edead78352811a, without merge commits; the ready public #9867 branch was not changed. The reviewedatan_nid_postfix,atan2_nid_postfix,CheckAtanConsoleBitsand the inheritedExpm1f,expm1f_nid_postfix,tanhf_nid_postfixand both inherited regression bodies are byte-identical to previous public head794e53b06f8a6a46523ab8307ff7261881d1130a. Each of the three regression functions is called once.Fresh Linux x86-64 Release validation:
guest_math,guest_math_exact,guest_dinkumware_internalsandpublic_headerseach pass three runs (12 passes). Substituting only productionMath.cppfrom the exact new #10222 parent makesguest_mathabort as expected; the other three groups pass 9/9. Restoring the candidate gives 12 more passes and a byte-identical rawlibc.prx. Conventions, whitespace and merge-tree checks pass.Exact-head logs, parent control and eight-body preservation proof (SHA-256
bcf94494f567f62073a02fc191a802f316071d19848e8cd4bb03274d92bc3281). Depends on remains #9784, #10222, #9850; the two separate earlier ports are not included in this refreshed combined test. Historical module/Windows/exhaustive figures retain their original measured revisions. No new original-module, Windows, exhaustive, exception-matrix, physical-console, game/GPU or performance result is claimed.Earlier Linux qualification (historical): head
794e53b06f8a6a46523ab8307ff7261881d1130a, one own topic commit directly on exact refreshed #10222 head3d8ff6b82ad249bba58a1b55a0d23a23ac228932(including its #9867 prerequisite). This public branch has no merge commits.atan_nid_postfix,atan2_nid_postfixandCheckAtanConsoleBitsare unchanged from previous public headefee4496e73e1f6a49128978a3f87608e80b314d; newer main math/tests and canonical public declarations are retained. A local merge-tree check against main57f506f8119252b43b851b0de18689bc5015a586is clean.Earlier requested #10222 combined qualification (historical): this tested head includes the exact refreshed #10222 commits, both ports' implementations and regression calls. Linux x86-64 Release
guest_math,guest_math_exact,guest_dinkumware_internalsandpublic_headerseach pass three consecutive runs, then all four pass three more after restoring this candidate from the negative control. Replacing only productionMath.cppwith the exact #10222 parent makesguest_mathabort as expected; exact-math and Dinkumware controls pass. Restoring the candidate produces a byte-identicallibc.prx. Conventions and whitespace checks pass.Earlier landing-order report (unchanged dependencies): #10222 lands before this PR and is carried as an actual parent. The previously declared earlier series positions of #9784 and #9850 are retained; their separate ports are not included in this new combined qualification. Depends on remains #9784, #10222, #9850. The shared #10222 insertion conflict is resolved by retaining both implementations, not by discarding either port.
Exact-head Linux logs, negative control and preservation/merge receipts (SHA-256
4af5d2eee9aae9ca09355b2f681b9ca8e8129aaf7a5faa19aeedbb0ff9efc815).Historical measurements below: earlier Windows/module comparisons remain pinned to their original measured revisions; no fresh Windows, title/module, console, exhaustive-sampling, exception-flag or performance claim is added by this refresh.
Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release,
BUILD_TESTING=ON,main4997726a5f; rebased ontomaind7948b09f9after #9777 merged, whereguest_mathandguest_dinkumware_internalspass in three runs out of three on 979f58705d.Sampled comparison: a scratch loader runs the decrypted
libc.prxof PPSA07923, PPSA05916 and PPSA13934 natively and supplies__error. It compared theiratanandatan2with this PR's code on two sets of inputs, checking result bits and whethererrnois set:DBL_MAX, the infinities and NaN.Results:
errnois never set.errnoeither. The bits differ on 35,741atanand 20,409atan2random arguments, because that copy is an FMA-contracted build, as with the float functions.Shipped
-O3build: that comparison compiled this PR's code at-O2.Math.cppbuilds at-O3, where GCC emitted msun's NaN returnx + ythe other way round, so two NaN arguments returnedx's NaN instead ofy's. The second commit returns the NaN explicitly. Loading the-O3libc.prxDLL of a combined series build next to PPSA07923's copy,atanandatan2now match on random inputs and every pair of 12 special values (comment).guest_math: the newCheckAtanConsoleBitshas 17atanand 23atan2cases with the console's results, six of them NaN pairs in both orders. They cover each range edge, ±0, the infinities, thex == 1and 2^60 shortcuts, and arguments where UCRT differs, plus NaN checks.guest_mathpasses in three runs out of three on the exact head. Withmain'sMath.cppand this test,guest_mathaborts in aRequire.python tools/check_conventions.py --base origin/mainandgit diff --checkpass. The branch merges cleanly with #10226.Overlap and order: #9784 (
atan2f) and #10222 (expm1f), both mine, replace one-line host wrappers on lines next to the ones this PR replaces, so they conflict textually; #9777 (atanf) has merged and this branch is rebased on it. This PR lands after them, in the series order #9777 → #9784 → #10222 → #9850 → #10229 → #10234 → #10245 → #10247 → #10250 → #10253 → thepowPR, with #10226 after #10222, #9857 before #10250 and #9771 before #10253. A combined preview of all seven exact heads (16575cdd36) resolves every conflict by keeping each port and dropping each host wrapper; each ported function is defined once and each console test is called once.guest_mathandguest_dinkumware_internalspass in three runs out of three on it.Not tested: Linux and macOS (the result no longer depends on the host's
atan), a console, the floating-point exception flags, andatanl/atan2l(still the host's, as listed in the debt file).Current Linux qualification (2026-10-28)
Rebased onto
main2227f1366188cda5699dd20e2e756a18006a5d4b. Linux CPU validation on 2026-10-28 at2b011faec6045105ac26138a06693907d82b1c60(Arch Linux 7.2.9, AMD Ryzen 9 7950X, GCC 16.2.1, Ninja Release, BUILD_TESTING=ON).libc,guest_math_testsandguest_math_exact_testsrebuilt from this exact source.guest_mathandguest_math_exacteach passed three consecutive runs (6/6, no skips); the same two suites each passed three runs on the pinned main (6/6). Conventions and whitespace checks pass.Exact source pins, preservation proofs, dependency checks, build logs and JUnit, SHA-256
1176269c9e6948b5252a5db9e660978d7f978fb2d9f4ed6c68bc050b10b5ae68. This is focused Linux CPU qualification; earlier Windows/title/reference measurements retain their original pins. No new title or performance result is claimed.Earlier qualification — 2026-10-30
Integrated current main
08a10d225306ad102b57408e2ef7566bcfb829b2into this existing topic at8bb1886d3ab535c1ac45c0c4409593f55fd8718c. Current-main functions, fixtures, unrelated debt rows and exact dependency gitlinks are preserved; original topic functions and authored commits are retained.Rebuilt actual Linux libc and focused test binaries.
guest_math,guest_math_exact,guest_dinkumware_internalseach passed three consecutive runs (9 runtime passes), pluspublic_headers; conventions and whitespace checks pass. Pinned main passed all seven selected runtime suites plus the header audit three times (24 runs). This is focused Linux CPU qualification; prior Windows/reference evidence retains its original pins. No new Windows, console, SDK-module, title, GPU or performance claim. AI-assisted: yes.Evidence: https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/owned-math6-main08a10-linux-20261030.tar.gz (SHA-256 b984a6334dce65b5c9148e3791ba21605074a5e762ea0f07f96de2f38062ef6e).
Qualification update — 2026-10-30, repeat 2
Integrated pinned main
e471817c68d4e1b1e44b0ce369ed88bafe4ae8edat2b1276d808f075b4250f854da87f8cc855480875, retaining original topic commits as ancestors. Actual parent ancestry: #1022274fceb9201aa7e636bd0a59dcb0e7e1ab023ffbb. The full current-main logb/logbf debt entry is retained; inherited unused TanhfExpm1 is absent where shared Expm1f supersedes it.Actual Linux libc/focused binaries rebuilt from this final head;
guest_math,guest_math_exact,guest_dinkumware_internalseach pass three consecutive runs (9 runtime passes), plus public_headers. Conventions against current origin/main and whitespace pass. Pinned main passed all seven runtime groups plus the header audit three times (24 runs). Full source/function/test/debt/header and 31 recursive dependency / 17,742 tracked-blob proofs are attached. Later main1c6b316cf762has 17 off-topic commits, no relevant libc/numeric/qsort/gitlink changes, and all 9 merge previews are clean; those preview trees were not executed.Focused Linux CPU scope only: prior Windows/SDK/reference reports keep original pins. No fresh Windows, console, SDK-module, title/GPU or speed measurement is claimed by this report. AI-assisted: yes. Evidence: https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/owned-math9-maine471-linux-20261030-repeat2.tar.gz (SHA256 5da4ce1732b45bb3fc566c31078c8c9ae8bf0c403654dfc60d15ee28490e20bf).
AI-assisted: yes (Codex).
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 did853b370f0191; #9850 merged at5a36b2df1e20; included in main snapshot5454cd2e455)AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T15:05:22Z.
Review: CHANGES_REQUESTED
The test report is unusually thorough, including exact bundled-console comparisons and a main-code negative control. One required integration item is still missing: the description says this change overlaps
Math.cppwith #10222 and that the branches conflict textually, but its checklist does not declare the merge order inDepends on.Please coordinate the order with the #10222 author and record the prerequisite on this checklist (or explain why the edits can land independently). After the chosen order is settled, please rerun
guest_mathon the combined exact heads; the current single-branch run does not validate the conflicting pair. I have not independently run the math tests.