feat(libc): implement the hyperbolic functions #3190

Merged
reyani-dev merged 1 commit from upstream-pr/3190 into main 2026-10-11 06:05:18 +00:00
reyani-dev commented 2026-10-11 00:47:22 +00:00 (Migrated from github.com)

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


Resubmission of #2166, which was closed because no title was shown stopping on these functions. With alarm (#2765) merged, Porpoise (PPSA99764) now stops at asinh on main 06da1176, per @babyhuey's catalog run with sce_module/libc.prx unwrapped (comment):

app.elf: symbol lookup error: app.elf: undefined symbol: 2eQpqTjJ5Y4

2eQpqTjJ5Y4 is asinh.

A second title: with malloc_usable_size (#3225) merged, OpenRCT2 (PPSA99728) on main 961b25fe stops at cosh (m7iLTaO9RMs), and with this branch it goes on to expm1 (comment). @babyhuey also checked this branch stacked with #3191 and #3192 on Linux and Windows: Porpoise gets past asinh to dirname.

The functions here are still absent on current main (tanh/tanhf, which main already has, are not part of this change), and no open libc PR implements them. The branch is rebased onto current main. Windows 11 (WinLibs GCC 15.2.0), Release: guest_math passes 3/3, and check_conventions.py and pr_overlap.py --branch pass.


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:4815568136 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3190). Originally posted by [reyani-dev](https://github.com/reyani-dev) on 2026-10-11T00:47:22Z. --- Resubmission of #2166, which was closed because no title was shown stopping on these functions. With `alarm` (#2765) merged, Porpoise (PPSA99764) now stops at `asinh` on `main` 06da1176, per @babyhuey's catalog run with `sce_module/libc.prx` unwrapped ([comment](https://github.com/boykopovar/AnyPS5/pull/2166#issuecomment-6103798532)): ``` app.elf: symbol lookup error: app.elf: undefined symbol: 2eQpqTjJ5Y4 ``` `2eQpqTjJ5Y4` is `asinh`. A second title: with `malloc_usable_size` (#3225) merged, OpenRCT2 (PPSA99728) on `main` 961b25fe stops at `cosh` (`m7iLTaO9RMs`), and with this branch it goes on to `expm1` ([comment](https://github.com/boykopovar/AnyPS5/pull/3190#issuecomment-6105046281)). @babyhuey also checked this branch stacked with #3191 and #3192 on Linux and Windows: Porpoise gets past `asinh` to `dirname`. The functions here are still absent on current `main` (`tanh`/`tanhf`, which main already has, are not part of this change), and no open libc PR implements them. The branch is rebased onto current `main`. Windows 11 (WinLibs GCC 15.2.0), Release: `guest_math` passes 3/3, and `check_conventions.py` and `pr_overlap.py --branch` pass. --- ### 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-11 00:47:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T00:47:44Z.


Progress report (06da117 → 1191ed3)

📈 System libraries: 85.99% (+0.03%, +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:6103901819 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3190#issuecomment-6103901819). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-11T00:47:44Z. --- <!-- progress-report --> ### Progress report (06da117 → 1191ed3) 📈 **System libraries**: 85.99% (+0.03%, +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-11 01:08:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-11T01:08:15Z.


Fork CI for this head merged onto current main (run 38099620418):

  • Windows: 759/759 passed.
  • Linux: 752/755 passed. The 3 failures are agc_unit_shadow, agc_driver_flat_apertures (timeout) and agc_driver_image_packed16_load, which fail identically in main's own push build (run 38098335801). This PR only touches libc, so they're unrelated.
  • Relinker jobs: green.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6104052214 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3190#issuecomment-6104052214). Originally posted by [reyani-dev](https://github.com/reyani-dev) on 2026-10-11T01:08:15Z. --- Fork CI for this head merged onto current `main` ([run 38099620418](https://github.com/AchrafReyani/AnyPS5/actions/runs/38099620418)): - **Windows**: 759/759 passed. - **Linux**: 752/755 passed. The 3 failures are `agc_unit_shadow`, `agc_driver_flat_apertures` (timeout) and `agc_driver_image_packed16_load`, which fail identically in `main`'s own push build ([run 38098335801](https://github.com/boykopovar/AnyPS5/actions/runs/38098335801)). This PR only touches libc, so they're unrelated. - Relinker jobs: green.
babyhuey commented 2026-10-11 01:36:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-11T01:36:58Z.


Checked with #3190, #3191 and #3192 stacked on main d31b57a4 (all merge cleanly), catalog builds with sce_module/libc.prx unwrapped. Linux (Ubuntu 24.04, GCC 13) and Windows 11 (WinLibs GCC 15.2), Release: guest_math and guest_strings pass 5/5 (--repeat until-fail:5) on both, with no warnings in Math.cpp or StringExtensions.cpp.

Porpoise (PPSA99764) gets past asinh on both and stops at dirname:

  • Linux: app.elf: symbol lookup error: app.elf: undefined symbol: E4wZaG1zSFc
  • Windows: FAIL: unresolved ELF import E4wZaG1zSFc (dirname) from libSceLibcInternal.prx
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6104257140 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3190#issuecomment-6104257140). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-11T01:36:58Z. --- Checked with #3190, #3191 and #3192 stacked on `main` d31b57a4 (all merge cleanly), catalog builds with `sce_module/libc.prx` unwrapped. Linux (Ubuntu 24.04, GCC 13) and Windows 11 (WinLibs GCC 15.2), Release: `guest_math` and `guest_strings` pass 5/5 (`--repeat until-fail:5`) on both, with no warnings in `Math.cpp` or `StringExtensions.cpp`. Porpoise (PPSA99764) gets past `asinh` on both and stops at `dirname`: - Linux: `app.elf: symbol lookup error: app.elf: undefined symbol: E4wZaG1zSFc` - Windows: `FAIL: unresolved ELF import E4wZaG1zSFc (dirname) from libSceLibcInternal.prx`
babyhuey commented 2026-10-11 03:31:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-11T03:31:46Z.


@AchrafReyani this is now the next stop for a second title. With malloc_usable_size (#3225) merged, OpenRCT2 (PPSA99728) on main 961b25fe stops at cosh on Linux:

app.elf: symbol lookup error: app.elf: undefined symbol: m7iLTaO9RMs

With this head (1191ed3e) merged onto 961b25fe (clean), OpenRCT2 goes on to expm1 (gqKfOiJaCOo), which your #2173 had, and Porpoise still goes on to dirname.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6105046281 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3190#issuecomment-6105046281). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-11T03:31:46Z. --- @AchrafReyani this is now the next stop for a second title. With `malloc_usable_size` (#3225) merged, OpenRCT2 (PPSA99728) on `main` 961b25fe stops at `cosh` on Linux: `app.elf: symbol lookup error: app.elf: undefined symbol: m7iLTaO9RMs` With this head (1191ed3e) merged onto 961b25fe (clean), OpenRCT2 goes on to `expm1` (`gqKfOiJaCOo`), which your #2173 had, and Porpoise still goes on to `dirname`.
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!3190
No description provided.