feat(libc): implement sinl, cosl, logl, powl and truncl #2213

Closed
reyani-dev wants to merge 1 commit from upstream-pr/2213 into main
reyani-dev commented 2026-10-09 11:46:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-09T11:46:45Z.


What

Exports the long double versions of sin, cos, log, pow and trunc. Each one forwards to the C++ standard library in long double. The guest long double is x87 extended precision, as strtold_nid_postfix already relies on (static_assert(sizeof(long double) == 16)), and both host ABIs use that format with APS5_VABI.

Title: PPSA99169 RetroArch imports all five from libSceLibcInternal (resolved through libc.prx), per the #1578 audit. I haven't run the title.

Tested

Windows 11, WinLibs GCC 15.2.0 r7, Release, -DBUILD_TESTING=ON:

  • New checks in guest_math_tests, next to frexpf. Each needs the 64-bit significand, so an implementation through double fails:
    • truncl(2^62 + 1.5) == 2^62 + 1 (double rounds the input to 2^62), and truncl(-0.5) is -0;
    • logl(1 + 2^-60) is 2^-60 within 1e-9 relative (double: 0);
    • powl(1 + 2^-60, 2) == 1 + 2^-59 (double: 1), and powl(2, 64) == 2^64;
    • cosl(2^-31) < 1 (the exact value 1 - 2^-63 rounds to 1 in double);
    • |sinl(π)| < 1e-18 for the nearest long double to π (double sin of the nearest double gives 1.2e-16).
  • Mutation check: routing each of the five through double makes guest_math fail.
  • cmake --build build --target libs: the patched libc.prx exports all 5 NIDs.
  • tools/check_conventions.py passes, and tools/pr_overlap.py --branch reports no overlap.

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 in TechnicalDebt
  • 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
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4799970878 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2213). Originally posted by [reyani-dev](https://github.com/reyani-dev) on 2026-10-09T11:46:45Z. --- ### What Exports the `long double` versions of `sin`, `cos`, `log`, `pow` and `trunc`. Each one forwards to the C++ standard library in `long double`. The guest `long double` is x87 extended precision, as `strtold_nid_postfix` already relies on (`static_assert(sizeof(long double) == 16)`), and both host ABIs use that format with `APS5_VABI`. Title: PPSA99169 RetroArch imports all five from `libSceLibcInternal` (resolved through `libc.prx`), per the #1578 audit. I haven't run the title. ### Tested Windows 11, WinLibs GCC 15.2.0 r7, Release, `-DBUILD_TESTING=ON`: - New checks in `guest_math_tests`, next to `frexpf`. Each needs the 64-bit significand, so an implementation through `double` fails: - `truncl(2^62 + 1.5) == 2^62 + 1` (`double` rounds the input to 2^62), and `truncl(-0.5)` is `-0`; - `logl(1 + 2^-60)` is 2^-60 within 1e-9 relative (`double`: 0); - `powl(1 + 2^-60, 2) == 1 + 2^-59` (`double`: 1), and `powl(2, 64) == 2^64`; - `cosl(2^-31) < 1` (the exact value 1 - 2^-63 rounds to 1 in `double`); - `|sinl(π)| < 1e-18` for the nearest `long double` to π (`double` sin of the nearest `double` gives 1.2e-16). - Mutation check: routing each of the five through `double` makes `guest_math` fail. - `cmake --build build --target libs`: the patched `libc.prx` exports all 5 NIDs. - `tools/check_conventions.py` passes, and `tools/pr_overlap.py --branch` reports no overlap. ### Checklist - [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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-09 11:47:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T11:47:12Z.


Progress report (d70b899 → 7c8e142)

📈 System libraries: 84.72% (+0.03%, +5 implemented functions)

✅ 5 implemented
Library Name
libc cosl_nid_postfix
libc logl_nid_postfix
libc powl_nid_postfix
libc sinl_nid_postfix
libc truncl_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6080230970 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2213#issuecomment-6080230970). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-09T11:47:12Z. --- <!-- progress-report --> ### Progress report (d70b899 → 7c8e142) 📈 **System libraries**: 84.72% (+0.03%, +5 implemented functions) <details> <summary>✅ 5 implemented</summary> | Library | Name | | - | - | | libc | `cosl_nid_postfix` | | libc | `logl_nid_postfix` | | libc | `powl_nid_postfix` | | libc | `sinl_nid_postfix` | | libc | `truncl_nid_postfix` | </details>
reyani-dev commented 2026-10-09 12:13:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-09T12:13:55Z.


Full Linux and Windows builds and tests for this head (7c8e142c), using the project's Build workflow. I can't start the upstream manual run, so I ran the same build.yml in my fork through a mirror PR. Like the upstream run, the jobs check out the PR head merged into current main (d70b8998):

Job Result
linux success; full build, ctest: 516/516 passed
windows success; full build, ctest: 507/507 passed
relinker (Linux, Windows, macOS) success

Run: https://github.com/AchrafReyani/AnyPS5/actions/runs/37925841113

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6080656022 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2213#issuecomment-6080656022). Originally posted by [reyani-dev](https://github.com/reyani-dev) on 2026-10-09T12:13:55Z. --- Full Linux and Windows builds and tests for this head (`7c8e142c`), using the project's Build workflow. I can't start the upstream manual run, so I ran the same `build.yml` in my fork through a mirror PR. Like the upstream run, the jobs check out the PR head merged into current `main` (`d70b8998`): | Job | Result | |---|---| | [linux](https://github.com/AchrafReyani/AnyPS5/actions/runs/37925841113/job/113804490181) | success; full build, `ctest`: 516/516 passed | | [windows](https://github.com/AchrafReyani/AnyPS5/actions/runs/37925841113/job/113804490207) | success; full build, `ctest`: 507/507 passed | | relinker (Linux, Windows, macOS) | success | Run: https://github.com/AchrafReyani/AnyPS5/actions/runs/37925841113
oneandonlydean commented 2026-10-09 20:10:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T20:10:07Z.


Same as #2167, for sinl, cosl, logl, powl and truncl.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6088444374 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2213#issuecomment-6088444374). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-09T20:10:07Z. --- Same as #2167, for `sinl`, `cosl`, `logl`, `powl` and `truncl`.

Pull request closed

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!2213
No description provided.