Skip to content

feat(libc): implement rint and lrint families - #2235

Closed
obojeoboje wants to merge 1 commit into
boykopovar:mainfrom
obojeoboje:feat/libc-rint-family
Closed

obojeoboje wants to merge 1 commit into
boykopovar:mainfrom
obojeoboje:feat/libc-rint-family

Conversation

@obojeoboje

@obojeoboje obojeoboje commented Oct 9, 2026 •

Copy link
Copy Markdown

What

Implement nine libc exports: rint, rintf, rintl, lrint, lrintf, lrintl, llrint, llrintf, and llrintl.

The functions honor the active floating-point rounding mode and preserve floating-point exception behavior. Guest long results use the host llrint overloads to retain 64-bit values on Windows. Extended-precision overloads retain the guest x87 long double representation. Compile only this translation unit with -frounding-math; without it GCC's optimized rint gives incorrect negative results under directed rounding.

Behavior references: FreeBSD rint(3) and lrint(3). Export names are present in the shadPS4 aerolib table.

The progress scanner changes from 2578/3044 (84.69%) to 2587/3053 (84.74%). These are newly declared exports, so both counts grow.

Tested

Windows, WinLibs GCC 15.2, Release build with testing enabled. No game tested.

  • Full default build and libs target passed.
  • Full CTest run with four workers and a 30-second per-test limit: 507 passed, one skipped (guest_video_out_wqhd_detection_no_vulkan), zero failures; 37.64 seconds total.
  • New runtime tests cover all nine exports under all four rounding modes, ties, signed zero, infinities, NaN, FE_INEXACT, invalid integer conversions (FE_INVALID), results beyond 32 bits, integer boundaries, and extended precision beyond double. Invalid-conversion return values are deliberately not asserted because they are unspecified.
  • Test registration and conventions checks passed.
  • Full Linux/Windows CI and the relinker matrix still require a collaborator to dispatch the Build 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
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

@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

Same as #2217, for the rint/lrint family.

ycbuzi pushed a commit to ycbuzi/AnyPS5 that referenced this pull request Oct 10, 2026
Harvested from upstream (closed unmerged); library completion 2904/3278 -> 2913/3287. Additive conflicts resolved by keeping both sides: core/libs/prx/libc/CMakeLists.txt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011krDVCnnMQPaEFEqCDnKmA
oneandonlydean pushed a commit that referenced this pull request Oct 20, 2026
MathExact.cpp was built without -frounding-math, so GCC compiled
std::rint as an add and subtract of 2^52 on the magnitude, which is exact
only when rounding to nearest: under FE_DOWNWARD rint(-1.5) returned -1
and rintf(-1.5f) -1, where C and FreeBSD's libm give -2. lrint and llrint
were right: they call the host libm's llrint, which honours the mode.

MathExact.cpp now builds with -frounding-math. GuestMathExact checks
rint, rintf, rintl, lrint and llrint of -1.5 and 1.5 in all four rounding
modes and that the mode is unchanged.

The failure was first caught by the rounding test of
#2235 (Привалов Александр Владимирович).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

2 participants