feat(libc): implement log1p, log1pf and expm1 #2173

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

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


What

Exports log1p, log1pf and expm1. Each one forwards to the C++ standard library, like log and exp. 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):

  • log1p: PPSA68091 Ruffle, PPSA99169 RetroArch
  • log1pf: PPSA68091 Ruffle
  • expm1: PPSA99169 RetroArch, PPSA99764 Porpoise

I haven't run any of these titles.

Tested

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

  • New checks in guest_math_tests, next to log10f:
    • signed zero (log1p(-0) and expm1(-0) are -0);
    • limits: log1p(-1) == -inf, log1p(inf) == inf, expm1(-inf) == expm1(-1000) == -1;
    • NaN below the domain: log1p(-2), log1pf(-2);
    • reference values at 1;
    • small arguments that need the dedicated functions: log1p(1e-300), log1pf(1e-30f) and expm1(1e-300) return their argument, and log1p(1e-10)/expm1(1e-10) are within 1e-25 of the exact values. log(1 + x) and exp(x) - 1 give 0 or lose most digits there.
  • Mutation check: replacing any of the three with log(1 + x) or exp(x) - 1 makes guest_math fail.
  • cmake --build build --target libs: the patched libc.prx exports all 3 NIDs.
  • tools/check_conventions.py passes, and tools/pr_overlap.py --branch reports no overlap. This branch also merges cleanly with my #2158, #2166 and #2167.

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:4799291037 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2173). Originally posted by [reyani-dev](https://github.com/reyani-dev) on 2026-10-09T10:39:08Z. --- ### What Exports `log1p`, `log1pf` and `expm1`. Each one forwards to the C++ standard library, like `log` and `exp`. 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`): - `log1p`: PPSA68091 Ruffle, PPSA99169 RetroArch - `log1pf`: PPSA68091 Ruffle - `expm1`: PPSA99169 RetroArch, PPSA99764 Porpoise I haven't run any of these titles. ### Tested Windows 11, WinLibs GCC 15.2.0 r7, Release, `-DBUILD_TESTING=ON`: - New checks in `guest_math_tests`, next to `log10f`: - signed zero (`log1p(-0)` and `expm1(-0)` are `-0`); - limits: `log1p(-1) == -inf`, `log1p(inf) == inf`, `expm1(-inf) == expm1(-1000) == -1`; - NaN below the domain: `log1p(-2)`, `log1pf(-2)`; - reference values at 1; - small arguments that need the dedicated functions: `log1p(1e-300)`, `log1pf(1e-30f)` and `expm1(1e-300)` return their argument, and `log1p(1e-10)`/`expm1(1e-10)` are within 1e-25 of the exact values. `log(1 + x)` and `exp(x) - 1` give 0 or lose most digits there. - Mutation check: replacing any of the three with `log(1 + x)` or `exp(x) - 1` makes `guest_math` fail. - `cmake --build build --target libs`: the patched `libc.prx` exports all 3 NIDs. - `tools/check_conventions.py` passes, and `tools/pr_overlap.py --branch` reports no overlap. This branch also merges cleanly with my #2158, #2166 and #2167. ### 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:39:31 +00:00 (Migrated from github.com)

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


Progress report (51f69aa → f5dc794)

📈 System libraries: 84.71% (+0.02%, +3 implemented functions)

✅ 3 implemented
Library Name
libc expm1_nid_postfix
libc log1p_nid_postfix
libc log1pf_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6079241697 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2173#issuecomment-6079241697). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-09T10:39:31Z. --- <!-- progress-report --> ### Progress report (51f69aa → f5dc794) 📈 **System libraries**: 84.71% (+0.02%, +3 implemented functions) <details> <summary>✅ 3 implemented</summary> | Library | Name | | - | - | | libc | `expm1_nid_postfix` | | libc | `log1p_nid_postfix` | | libc | `log1pf_nid_postfix` | </details>
reyani-dev commented 2026-10-09 11:24:39 +00:00 (Migrated from github.com)

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


Full Linux and Windows builds and tests for this head (f5dc794c), 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/37920413262

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

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


Same as #2167, for log1p, log1pf and expm1.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6088435559 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2173#issuecomment-6088435559). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-09T20:09:34Z. --- Same as #2167, for `log1p`, `log1pf` and `expm1`.
reyani-dev commented 2026-10-11 03:43:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-11T03:43:48Z.


Resubmitted as #3259: per @babyhuey's run on #3190, OpenRCT2 stops at expm1 once #3190 lands.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6105128253 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2173#issuecomment-6105128253). Originally posted by [reyani-dev](https://github.com/reyani-dev) on 2026-10-11T03:43:48Z. --- Resubmitted as #3259: per @babyhuey's run on #3190, OpenRCT2 stops at `expm1` once #3190 lands.

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