fix(libc): compute atan2l with FreeBSD msun's e_atan2l.c #19328

Merged
AlfaRojo merged 4 commits from upstream-pr/19328 into main 2026-11-13 22:51:48 +00:00
AlfaRojo commented 2026-11-13 03:44:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AlfaRojo on 2026-11-13T03:44:27Z.


What

atan2l returned the host's std::atan2. It now follows FreeBSD msun's e_atan2l.c (release/11.4.0, ld80 constants from invtrig.c) on top of the existing msun atanl: signed zeros, infinities, x = 1, the huge and tiny y / x branches and the quadrant corrections follow the source, so the last bits match msun where the host libm differs. docs/dev/debt/libc.md drops atan2l from the host-math list and records the new entry.

Tested

Windows 11 Pro 10.0.26200, WinLibs GCC 15.2.0 r7, Release, no title or homebrew run.

  • guest_math (new CheckAtan2l): on main it fails with Guest atan2l failed for 0x8p-3, 0xep+0; with the change ctest -R '^guest_math' passes 3 of 3, three runs (guest_math, guest_math_elementary, guest_math_exact).
  • Expected bits come from an independent C transcription of e_atan2l.c and s_atanl.c with the raw decimal constants, not from the host libm. It matched the port bit for bit on a 601x601 integer grid (361k inputs) and at 53-bit precision. The pinned cases include inputs where the host libm differs, the exponent-difference thresholds, a subnormal y, signed zeros, infinities and NaN.
  • Not compared against a real libc.prx: no title binary was available, so the console's own atan2l is not compared (stated in the debt entry).
  • tools/check_conventions.py --base upstream/main: 0 errors. tools/pr_overlap.py reports line overlap in Math.cpp with #18513 and #18694 and could not complete the comparison for PRs that conflict with main. #18481, #18513, #18525 and #18694 are neighbours editing the same files or list line; none defines atan2l (checked with gh pr diff; #18694 only keeps atan2l in the host-math list). Every PR the tool could not confirm was also grepped for added atan2l lines with gh pr diff: none.
  • Head b16c2b5725 (merged with upstream/main 51790c7533): guest_math, guest_math_elementary and guest_math_exact, all three test executables rebuilt, pass in 3/3 runs; check_conventions.py --base upstream/main reports no errors.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5289578837 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19328). Originally posted by [AlfaRojo](https://github.com/AlfaRojo) on 2026-11-13T03:44:27Z. --- ### What `atan2l` returned the host's `std::atan2`. It now follows FreeBSD msun's [`e_atan2l.c`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/lib/msun/src/e_atan2l.c) (release/11.4.0, ld80 constants from `invtrig.c`) on top of the existing msun `atanl`: signed zeros, infinities, `x = 1`, the huge and tiny `y / x` branches and the quadrant corrections follow the source, so the last bits match msun where the host libm differs. `docs/dev/debt/libc.md` drops `atan2l` from the host-math list and records the new entry. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows 11 Pro 10.0.26200, WinLibs GCC 15.2.0 r7, Release, no title or homebrew run. - `guest_math` (new `CheckAtan2l`): on `main` it fails with `Guest atan2l failed for 0x8p-3, 0xep+0`; with the change `ctest -R '^guest_math'` passes 3 of 3, three runs (`guest_math`, `guest_math_elementary`, `guest_math_exact`). - Expected bits come from an independent C transcription of `e_atan2l.c` and `s_atanl.c` with the raw decimal constants, not from the host libm. It matched the port bit for bit on a 601x601 integer grid (361k inputs) and at 53-bit precision. The pinned cases include inputs where the host libm differs, the exponent-difference thresholds, a subnormal `y`, signed zeros, infinities and NaN. - Not compared against a real `libc.prx`: no title binary was available, so the console's own `atan2l` is not compared (stated in the debt entry). - `tools/check_conventions.py --base upstream/main`: 0 errors. `tools/pr_overlap.py` reports line overlap in `Math.cpp` with #18513 and #18694 and could not complete the comparison for PRs that conflict with `main`. #18481, #18513, #18525 and #18694 are neighbours editing the same files or list line; none defines `atan2l` (checked with `gh pr diff`; #18694 only keeps `atan2l` in the host-math list). Every PR the tool could not confirm was also grepped for added `atan2l` lines with `gh pr diff`: none. - Head `b16c2b5725` (merged with upstream/main `51790c7533`): `guest_math`, `guest_math_elementary` and `guest_math_exact`, all three test executables rebuilt, pass in 3/3 runs; `check_conventions.py --base upstream/main` reports no errors. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!19328
No description provided.