Skip to content

feat(libc): implement extended-precision math exports - #2271

Closed
obojeoboje wants to merge 2 commits into
boykopovar:mainfrom
obojeoboje:feat/libc-extended-math
Closed

obojeoboje wants to merge 2 commits into
boykopovar:mainfrom
obojeoboje:feat/libc-extended-math

Conversation

@obojeoboje

@obojeoboje obojeoboje commented Oct 9, 2026 •

Copy link
Copy Markdown

What

Add 43 missing libc long double math exports in a dedicated translation unit, preserving the guest x87 extended format rather than narrowing inputs, outputs or pointer results to double.

  • Trigonometric and hyperbolic: acosl, asinl, atanl, atan2l, tanl, acoshl, asinhl, atanhl, coshl, sinhl, tanhl.

  • Exponentials, logarithms and roots: expl, exp2l, expm1l, log10l, log1pl, log2l, logbl, sqrtl, cbrtl, hypotl.

  • Arithmetic and rounding: fabsl, copysignl, fdiml, fmaxl, fminl, fmal, ceill, floorl, roundl, lroundl, llroundl, nearbyintl.

  • Remainders, neighbors and decomposition: fmodl, remainderl, remquol, nextafterl, nexttowardl, frexpl, ldexpl, modfl, scalbnl, scalblnl.

Guest lroundl returns 64 bits on Windows through the host llround overload. scalblnl accepts a 64-bit guest exponent and bounds it before using the native int-exponent operation, avoiding Windows long truncation. Bounds exceed the entire representable x87 exponent range.

Normalize native runtime differences found by the tests: signed-zero fractional results for infinite modfl inputs; domain/pole exception flags and errno for acoshl, atanhl and sqrtl; and missing overflow/zero-underflow flags for finite exponential/hyperbolic inputs. Preserve FreeBSD signed-zero ordering for fmaxl/fminl, and normalize neighbor-operation underflow/overflow flags and ERANGE. Use -frounding-math only for the new implementation and test translation units.

Contracts and signatures follow FreeBSD fmax(3), math(3), modf(3), and ldexp(3). All 43 export names are present in the shadPS4 aerolib table. Transcendental results use native extended-precision math; bit-identical results across host runtimes are not claimed.

Checked open PR descriptions and the relevant libc patches in #2193, #2213, #2166, #2167, #2173, #2192 and #2037. This branch excludes their functions and the rounding exports in #2235. Shared CMake insertion points may need both independent source/test additions preserved when rebasing.

The progress scanner changes from 2578/3044 (84.69%) to 2621/3087 (84.90%). Both counts grow because these are newly declared exports.

Tested

  • Windows, WinLibs GCC 15.2, Release with testing enabled: full default build and libs target passed.

  • Full CTest run, four workers, 30-second per-test limit: 507 passed, one skipped (guest_video_out_wqhd_detection_no_vulkan), zero failures; 39.68 seconds total on the final head 91f4371b.

  • New runtime fixture exercises all 43 exports using fixed numerical expectations, extended precision beyond double, exponents beyond the double range, subnormal decomposition/scaling, all four rounding modes, signed zero, NaNs/infinities, exception flags, fused rounding, quotient bits and 64-bit integer boundaries/exponents.

  • Linux, Ubuntu 24.04 under WSL, GCC 13.3: built ExtendedMath.cpp as a separate optimized shared library and linked/ran the same complete fixture with UndefinedBehaviorSanitizer successfully on the final head 91f4371b. This was a focused runtime check, not a full Linux project build or NID-patched library run.

  • Test registration, conventions and whitespace checks passed. No game tested.

  • Full Linux/Windows Build and the relinker matrix still require a collaborator to dispatch the workflow for this PR head.

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: none added

  • Generic behaviour, not specific to one title

  • Depends on: none

  • AI-assisted: yes

@obojeoboje obojeoboje mentioned this pull request Oct 9, 2026
9 tasks done
@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#2170 core/libs/prx/libc/CMakeLists.txt L48

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Closing: none of these 43 functions is shown to be reached by a title on main; the list comes from the aerolib table, and library functions go in when a title needs them. Reopen with the title ID and the log line where it stops if you find one.

ycbuzi pushed a commit to ycbuzi/AnyPS5 that referenced this pull request Oct 10, 2026
…and neighbor exceptions

Harvested from upstream (closed unmerged); library completion 2733/3151 -> 2776/3194.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011krDVCnnMQPaEFEqCDnKmA
@babyhuey

Copy link
Copy Markdown
Contributor

@obojeoboje PokeMMO (PPSA98001) now stops at frexpl on main f38a036 (catalog build, sce_module/libc.prx unwrapped, with #1529 in): app.elf: symbol lookup error: app.elf: undefined symbol: YZk9sHO0yNg. The intake check needs 10 merged PRs; if you can't open PRs yet, would you like me to open the frexpl part of this from my fork with your commits and authorship kept, after a Linux and Windows run? The rest of the long double set has no title stopping on it yet, so it would likely need to wait.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants