Skip to content

feat(libc): implement erf, erfc, and erfcf - #6157

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
freshstart2066-create:feat/libc-erf-erfc
Oct 18, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
freshstart2066-create:feat/libc-erf-erfc

Conversation

@freshstart2066-create

Copy link
Copy Markdown

What

Statistical, probability, and physics shaders/guest runtimes utilize the Gauss error function and its complementary variant. While erff was previously available, erf, erfc, and erfcf were missing from libc, resulting in unresolved dynamic symbol link failures during guest initialization.

This PR implements:

  • erf (erf_nid_postfix)
  • erfc (erfc_nid_postfix)
  • erfcf (erfcf_nid_postfix)

Implementation Details

  • Backed by std::erf and std::erfc according to C99 and IEEE 754 specifications.
  • Adds comprehensive unit test assertions to core/libs/tests/GuestMath.cpp validating zero signs (+0.0 vs -0.0), asymptotic limits (x -> +/-inf), standard values (x = 0.5), and quiet NaN propagation for both single and double precision variants.

Tested

  • Unit tests in core/libs/tests/GuestMath.cpp (guest_math).
  • Clean 3-way merge against current upstream/main with 0 conflicts (tree: d0201eff0530cb008cea33aad4de87110dc9fa58).
  • python tools/check_conventions.py --base 584cc4c57: All conventions checks passed.

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 under Silent stubs in their library's technical debt file
  • 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
  • Unblocks: PPSA01438
  • GPUs tested: n/a (libc math)
  • AI-assisted: yes

Co-authored-by: Nawasfadili nawasfadili@users.noreply.github.com

@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Progress report (889cee5 → 5509b6c)

📈 System libraries: 90.25% (+0.01%, +3 implemented functions)

✅ 3 implemented
Library Name
libc erf_nid_postfix
libc erfc_nid_postfix
libc erfcf_nid_postfix

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 6044 core/libs/tests/GuestMath.cpp
PR 6414 core/libs/prx/libc/src/Math.cpp
PR 6879 core/libs/prx/libc/src/Math.cpp
PR 7201 core/libs/prx/libc/src/Math.cpp

@milescoviello

Copy link
Copy Markdown
Contributor

A title that needs this: Media Player Classic PS5 1.1 (PPSA99015), new in the homebrew catalog. On main 5d9dcc4 it exits at launch:

./app.elf: symbol lookup error: ./app.elf: undefined symbol: oXgaqGVnW5o

tools/nid_names.py --nid oXgaqGVnW5o names it erf. Of the app's 329 imports, it's the only one main's libraries don't define.

The branch now conflicts with main in Math.cpp, because #5775 changed lgamma next to these lines. I resolved it by keeping main's lgamma and adding your three functions. With that, c20228eb2 merged onto 5d9dcc4 builds, and the app runs to the 120 s limit in 2 of 2 runs with pad input. In a third run with screenshots it renders its window at about 60 FPS, and its Open dialog responds to the pad.

Linux (Ubuntu 24.04, GCC 13.3, Release), RTX 4070 Ti, NVIDIA 595.99. Not checked on Windows.

AI-assisted: yes

@wachi35676

Copy link
Copy Markdown
Contributor

Media Player Classic PS5 (PPSA99015, v1.1) imports erf (oXgaqGVnW5o). Setup: Windows 11, RTX 5070 Ti (NVIDIA 617.42), WinLibs GCC 15.2.0, Release. Titles are the authors' GitHub releases, unwrapped with tools/unwrap_self.py and converted with --windows. "main" is 922dc8999. For "this PR", the PR was cherry-picked onto 11acfdd84 and only the PR's own .prx was swapped into the 922dc8999 library set.

  • main: fails at load in 3 of 3 runs with FAIL: unresolved ELF import oXgaqGVnW5o from libSceLibcInternal.prx.
  • With this PR: 3 of 3 runs show the MPC-HC main window for 45–55 s and respond to pad input (the volume overlay shows "Volume 90%"), and guest_math passes.

Note: the branch now conflicts with main in core/libs/prx/libc/src/Math.cpp, where lgamma/signgam changed since. I tested it with main's lgamma kept and the three new functions added.

AI-assisted: yes (Claude Code); results above were run on this machine.

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 18, 2026
@adriadam10
adriadam10 merged commit c73787f into boykopovar:main Oct 18, 2026
16 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.

5 participants