Skip to content

feat(libc): implement sqrt and sqrtf - #3233

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
adriadam10:feat/libc-sqrt
Oct 11, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
adriadam10:feat/libc-sqrt

Conversation

@adriadam10

Copy link
Copy Markdown
Collaborator

What

sqrt (MXRNWnosNlM) and sqrtf (Q+xU11-h0xQ), imported from libSceLibcInternal, aren't exported. Since #1529 binds those imports to the system libraries on Linux, and with frexpl in since #3221, PokeMMO Prospero now stops on sqrt at load on main:

Title Stop on main aac0f1b
PokeMMO Prospero (PPSA98001) ./app.elf: symbol lookup error: ./app.elf: undefined symbol: MXRNWnosNlM (sqrt)

It imports sqrtf too, so both go in here.

Both use the host's std::sqrt. IEEE 754 requires square root to be correctly rounded, so the result is the exact one on every conforming host, the console included. That includes -0, infinity and NaN for negative arguments.

Tested

Linux (CachyOS), GCC 16, Release.

  • guest_math passes. The new cases are compared bit for bit with values computed independently in Python decimal:
    • sqrt(2) = 0x3ff6a09e667f3bcd and sqrtf(2) = 0x3fb504f3;
    • sqrt of the smallest subnormal = 0x1e60000000000000 (2^-537);
    • exact squares (4, 6.25);
    • -0 keeps its sign, infinity maps to infinity, -1 gives NaN.
  • On main the test doesn't link.
  • Negative checks, each one makes the test fail: sqrt through float, and sqrtf dropping the sign of -0.
  • Title stop: catalog release (sha256-checked) relinked for Linux with main's relinker and launched. It stops at load with the line above.
  • tools/check_conventions.py passes.

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

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

Copy link
Copy Markdown

Progress report (aac0f1b → 660abec)

📈 System libraries: 86.0% (+0.01%, +2 implemented functions)

✅ 2 implemented
Library Name
libc sqrt_nid_postfix
libc sqrtf_nid_postfix

@adriadam10
adriadam10 merged commit 961b25f into boykopovar:main Oct 11, 2026
15 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator Author

Merged: Linux CI is red only on agc_unit_shadow, which main has failed since #2864 (reported in #3215). Windows passed, and guest_math passed on both.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant