Skip to content

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

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
reyani-dev:feat/libc-log1p-expm1
Oct 11, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
reyani-dev:feat/libc-log1p-expm1

Conversation

@reyani-dev

Copy link
Copy Markdown
Contributor

Resubmission of #2173, which was closed because no title was shown stopping on these functions.

OpenRCT2 (PPSA99728) stops at cosh on main 961b25f (implemented by #3190). With #3190 applied, it stops next at expm1 (gqKfOiJaCOo), per @babyhuey's run on #3190 (comment). So this becomes OpenRCT2's next stop as soon as #3190 lands, the same stacking as #2933 (llroundf) before #2932 (atol).

log1p, log1pf and expm1 are still absent on current main, and no open PR implements them. There is no code dependency on #3190: the branch is rebased onto current main and merges cleanly with #3190. 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 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 feat(libc): implement __powidf2 #2158, feat(libc): implement the hyperbolic functions #2166 and feat(libc): implement fabs, sqrt, trunc and fma #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

Export them forwarding to the C++ standard library, like log and exp.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Progress report (961b25f → 1f94d93)

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

✅ 3 implemented
Library Name
libc expm1_nid_postfix
libc log1p_nid_postfix
libc log1pf_nid_postfix

@github-actions github-actions Bot added the libc label Oct 11, 2026
@reyani-dev

Copy link
Copy Markdown
Contributor Author

Full Linux and Windows builds and tests for this head (1f94d93d), 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 (e28fbc27):

Job Result
linux failure; full build, ctest: 760/761 passed
windows success; full build, ctest: 765/765 passed
relinker (Linux, Windows, macOS) success

The one Linux failure, agc_unit_shadow, also fails on main itself (push run 38098335801); this PR only touches libc math and its tests.

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

@babyhuey

Copy link
Copy Markdown
Contributor

Checked with #3190 under this head (1f94d93) on main 961b25f, both merge cleanly. Linux (Ubuntu 24.04, GCC 13) and Windows 11 (WinLibs GCC 15.2), Release: guest_math passes 5/5 (--repeat until-fail:5) on both, with no warnings in Math.cpp or GuestMath.cpp.

OpenRCT2 (PPSA99728), Linux, catalog build with sce_module/libc.prx unwrapped:

On Windows the loader reports FAIL: unresolved ELF import oxMp8uPqa+U (pthread_set_name_np) from libkernel.prx (#3031) first for OpenRCT2, with and without these PRs, so the expm1 step only shows on Linux.

@adriadam10

Copy link
Copy Markdown
Collaborator

Checked log1p, log1pf and expm1 forward to std:: with the right float/double overloads, and guest_math passes on Linux. Without the change the new checks fail to link, so they exercise the new exports. OpenRCT2 stopping at expm1 after #3190 is confirmed in @babyhuey's run; merging.

@adriadam10
adriadam10 merged commit d508b44 into boykopovar:main Oct 11, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants