feat(libc): implement sqrt and sqrtf #3233

Merged
adriadam10 merged 1 commit from upstream-pr/3233 into main 2026-10-11 02:53:48 +00:00
adriadam10 commented 2026-10-11 02:45:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T02:45:00Z.


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 aac0f1b81
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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4816097880 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3233). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T02:45:00Z. --- ### 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` aac0f1b81 | |---|---| | 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 - [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
github-actions[bot] commented 2026-10-11 02:45:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T02:45:21Z.


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
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6104731097 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3233#issuecomment-6104731097). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-11T02:45:21Z. --- <!-- progress-report --> ### Progress report (aac0f1b → 660abec) 📈 **System libraries**: 86.0% (+0.01%, +2 implemented functions) <details> <summary>✅ 2 implemented</summary> | Library | Name | | - | - | | libc | `sqrt_nid_postfix` | | libc | `sqrtf_nid_postfix` | </details>
adriadam10 commented 2026-10-11 02:53:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T02:53:57Z.


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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6104789447 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3233#issuecomment-6104789447). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T02:53:57Z. --- 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 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!3233
No description provided.