feat(libc): implement the hyperbolic functions #2166

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

Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-09T10:31:28Z.


What

Exports sinh, cosh, coshf, asinh, asinhf, acosh, acoshf and atanh. Each one forwards to the C++ standard library, like the existing tanh/tanhf and sin/cos. Only the variants that titles import are added.

Titles: open-source homebrew from the #1578 catalog audit imports them from libSceLibcInternal (resolved through libc.prx), for example:

  • PPSA68091 Ruffle: cosh, coshf, sinh, asinh, asinhf, acosh, acoshf
  • PPSA99001 ProsperoRadio and PPSA99003 ProsperoTV: sinh, cosh, asinh, acosh, atanh
  • PPSA74126 Stremio Plus, PPSA99169 RetroArch, PPSA99764 Porpoise: sinh/cosh/asinh

I haven't run any of these titles.

Tested

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

  • New CheckHyperbolic in guest_math_tests:
    • exact values: sinh(±0) keeps the sign, cosh(0) == 1, acosh(1) == 0, atanh(±1) == ±inf;
    • NaN outside the domain: acosh(0.5), acoshf(0.5f), atanh(2);
    • reference values at 1 and 2, within 1e-15 relative for double and 1e-6 for float;
    • cases that rule out naive formulas: sinh, asinh and atanh of 1e-300 return 1e-300, cosh(710.4) and sinh(-710.4) stay finite, and asinh(-1e300)/acosh(1e300) are ±691.4686750787736.
  • Mutation check: replacing sinh, cosh or asinh with the textbook exp/log formula makes guest_math fail.
  • cmake --build build --target libs: the patched libc.prx exports all 8 NIDs.
  • tools/check_conventions.py passes, and tools/pr_overlap.py --branch reports no overlap. The new lines sit next to sin/cos, away from #2050's _FSinh/_FCosh change.

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:4799216337 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2166). Originally posted by [reyani-dev](https://github.com/reyani-dev) on 2026-10-09T10:31:28Z. --- ### What Exports `sinh`, `cosh`, `coshf`, `asinh`, `asinhf`, `acosh`, `acoshf` and `atanh`. Each one forwards to the C++ standard library, like the existing `tanh`/`tanhf` and `sin`/`cos`. Only the variants that titles import are added. Titles: open-source homebrew from the #1578 catalog audit imports them from `libSceLibcInternal` (resolved through `libc.prx`), for example: - PPSA68091 Ruffle: `cosh`, `coshf`, `sinh`, `asinh`, `asinhf`, `acosh`, `acoshf` - PPSA99001 ProsperoRadio and PPSA99003 ProsperoTV: `sinh`, `cosh`, `asinh`, `acosh`, `atanh` - PPSA74126 Stremio Plus, PPSA99169 RetroArch, PPSA99764 Porpoise: `sinh`/`cosh`/`asinh` I haven't run any of these titles. ### Tested Windows 11, WinLibs GCC 15.2.0 r7, Release, `-DBUILD_TESTING=ON`: - New `CheckHyperbolic` in `guest_math_tests`: - exact values: `sinh(±0)` keeps the sign, `cosh(0) == 1`, `acosh(1) == 0`, `atanh(±1) == ±inf`; - NaN outside the domain: `acosh(0.5)`, `acoshf(0.5f)`, `atanh(2)`; - reference values at 1 and 2, within 1e-15 relative for `double` and 1e-6 for `float`; - cases that rule out naive formulas: `sinh`, `asinh` and `atanh` of `1e-300` return `1e-300`, `cosh(710.4)` and `sinh(-710.4)` stay finite, and `asinh(-1e300)`/`acosh(1e300)` are ±691.4686750787736. - Mutation check: replacing `sinh`, `cosh` or `asinh` with the textbook `exp`/`log` formula makes `guest_math` fail. - `cmake --build build --target libs`: the patched `libc.prx` exports all 8 NIDs. - `tools/check_conventions.py` passes, and `tools/pr_overlap.py --branch` reports no overlap. The new lines sit next to `sin`/`cos`, away from #2050's `_FSinh`/`_FCosh` change. ### 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 10:31:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T10:31:50Z.


Progress report (51f69aa → d6129e5)

📈 System libraries: 84.73% (+0.04%, +8 implemented functions)

✅ 8 implemented
Library Name
libc acosh_nid_postfix
libc acoshf_nid_postfix
libc asinh_nid_postfix
libc asinhf_nid_postfix
libc atanh_nid_postfix
libc cosh_nid_postfix
libc coshf_nid_postfix
libc sinh_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6079128969 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2166#issuecomment-6079128969). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-09T10:31:50Z. --- <!-- progress-report --> ### Progress report (51f69aa → d6129e5) 📈 **System libraries**: 84.73% (+0.04%, +8 implemented functions) <details> <summary>✅ 8 implemented</summary> | Library | Name | | - | - | | libc | `acosh_nid_postfix` | | libc | `acoshf_nid_postfix` | | libc | `asinh_nid_postfix` | | libc | `asinhf_nid_postfix` | | libc | `atanh_nid_postfix` | | libc | `cosh_nid_postfix` | | libc | `coshf_nid_postfix` | | libc | `sinh_nid_postfix` | </details>
reyani-dev commented 2026-10-09 11:24:35 +00:00 (Migrated from github.com)

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


Full Linux and Windows builds and tests for this head (d6129e5a), 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 full build, ctest: 516/516 passed
windows full build, ctest: 507/507 passed
relinker (Linux, Windows, macOS) passed

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

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6079901852 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2166#issuecomment-6079901852). Originally posted by [reyani-dev](https://github.com/reyani-dev) on 2026-10-09T11:24:35Z. --- Full Linux and Windows builds and tests for this head (`d6129e5a`), 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/37920405682/job/113786768266) | full build, `ctest`: 516/516 passed | | [windows](https://github.com/AchrafReyani/AnyPS5/actions/runs/37920405682/job/113786767977) | full build, `ctest`: 507/507 passed | | relinker (Linux, Windows, macOS) | passed | Run: https://github.com/AchrafReyani/AnyPS5/actions/runs/37920405682
oneandonlydean commented 2026-10-09 20:09:20 +00:00 (Migrated from github.com)

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


Closing for the same reason as #2158: these come from the import audit, and none is shown to be a title's next stop on main. Reopen with the title ID and the log line when one stops on them.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6088432255 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2166#issuecomment-6088432255). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-09T20:09:20Z. --- Closing for the same reason as #2158: these come from the import audit, and none is shown to be a title's next stop on main. Reopen with the title ID and the log line when one stops on them.
reyani-dev commented 2026-10-10 04:24:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-10T04:24:14Z.


For the record, in case this comes back: according to @babyhuey's run on #2174 (main c963432d), ProsperoTV (PPSA99003) moves past __isinf with #2174 and then stops at ZjtRqSMJwdw, which is sinh, one of the functions this PR adds. Their Windows log line is FAIL: unresolved ELF import ZjtRqSMJwdw from libSceLibcInternal.prx. So this becomes a title's next stop as soon as #2174 is in. I'll rebase it then if you'd like to reopen it.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6093735253 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2166#issuecomment-6093735253). Originally posted by [reyani-dev](https://github.com/reyani-dev) on 2026-10-10T04:24:14Z. --- For the record, in case this comes back: according to @babyhuey's run on #2174 (main c963432d), ProsperoTV (PPSA99003) moves past `__isinf` with #2174 and then stops at `ZjtRqSMJwdw`, which is `sinh`, one of the functions this PR adds. Their Windows log line is `FAIL: unresolved ELF import ZjtRqSMJwdw from libSceLibcInternal.prx`. So this becomes a title's next stop as soon as #2174 is in. I'll rebase it then if you'd like to reopen it.
babyhuey commented 2026-10-11 00:33:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-11T00:33:50Z.


@AchrafReyani with alarm (#2765) merged, Porpoise (PPSA99764) now stops at asinh on main 06da1176 (catalog build, sce_module/libc.prx unwrapped): app.elf: symbol lookup error: app.elf: undefined symbol: 2eQpqTjJ5Y4. That's the condition you mentioned for rebasing this.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6103798532 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2166#issuecomment-6103798532). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-11T00:33:50Z. --- @AchrafReyani with `alarm` (#2765) merged, Porpoise (PPSA99764) now stops at `asinh` on `main` 06da1176 (catalog build, `sce_module/libc.prx` unwrapped): `app.elf: symbol lookup error: app.elf: undefined symbol: 2eQpqTjJ5Y4`. That's the condition you mentioned for rebasing this.
reyani-dev commented 2026-10-11 00:47:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-11T00:47:24Z.


Thanks @babyhuey, resubmitted as #3190, rebased onto current main with your Porpoise stop.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6103899498 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2166#issuecomment-6103899498). Originally posted by [reyani-dev](https://github.com/reyani-dev) on 2026-10-11T00:47:24Z. --- Thanks @babyhuey, resubmitted as #3190, rebased onto current `main` with your Porpoise stop.

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