Skip to content

fix(libc): accept the full llroundl integer range - #4942

Merged
oneandonlydean merged 2 commits into
boykopovar:mainfrom
QRMOE:fix-libc-llroundl-upper-bound
Oct 14, 2026
Merged

oneandonlydean merged 2 commits into
boykopovar:mainfrom
QRMOE:fix-libc-llroundl-upper-bound

Conversation

@QRMOE

@QRMOE QRMOE commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

What

Accept the complete signed 64-bit result range in llroundl. On main, llroundl(9223372036854775807.0L) returns INT64_MIN and raises FE_INVALID, although the input is exactly representable in the guest's x87 extended format and the correct rounded result is INT64_MAX.

The shared rounding helper uses an exclusive upper bound of static_cast<TFloat>(INT64_MAX). That bound becomes 2^63 for float and double but stays INT64_MAX for long double, excluding the largest valid integer. Use the exactly representable 2^63 bound in every specialization. The existing float/double range checks and invalid-input handling retain their behavior.

The valid result agrees with FreeBSD's s_llroundl.c and its s_lround.c, which includes the maximum integer within the long-double input range.

Tested

Windows, MinGW GCC 15.2, Release, BUILD_TESTING=ON; negative control on main 7e181fcc3, final branch rebased onto 88107b7de:

  • The new test fails on unchanged main: expected 9223372036854775807, got -9223372036854775808.
  • The fixed regression checks both integer limits, adjacent integral and half-integral inputs, overflow on either side, infinities and NaN under all four rounding modes. It checks FE_INVALID and preserves the caller's errno. Existing float/double boundary cases also pass.
  • Explicit libs build and ten libc/runtime/loading checks passed after the rebase. Conventions and whitespace checks passed.
  • A full Windows build was attempted on the previous base. All remaining components built, but Windows denied recreation of eight unrelated test outputs (guest_sce_net, guest_poll, guest_socket_read_write, guest_tcp, guest_socket_pair, guest_dup, guest_socket_events and guest_fstatfs). Avast's log records automatic sandboxing of the test programs. The local full-build limitation remains; local full-build success is not claimed.
  • No title playback or console measurement was performed.

Review validation

  • xXPBSXx's Windows report: Reports the relevant Windows test passing in a combined merge; the PR was not tested alone and no negative control was performed in that report.
  • nicolasfalesy's Linux report: Linux relevant runtime checks passed in a combined merge, and failed when this PR's source change was reverted while retaining the test.

Ready for maintainer review. Full Linux/Windows CI requires a maintainer's manual dispatch; marking this PR ready does not claim those jobs 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
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • AI-assisted: yes

@xXPBSXx

xXPBSXx commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Windows test of this PR.

Environment: Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, BUILD_TESTING=ON, -j2, libusb-cmake from a local checkout. Built from main ea2bbefb2 with this PR and six other open PRs (#4958, #4956, #4954, #4953, #4946, #4942, #4927) merged together; the merges had no conflict.

Result: guest_math (1 of 1; the test file is shared with #4946, both merged together) pass.

Not checked: whether the test fails without the change in the library code; the PR was not tested alone, only in the combined merge (the tests of the other PRs in the batch also pass); no title run; Linux not tested.

AI-assisted (Claude Code).

@nicolasfalesy

Copy link
Copy Markdown
Contributor

Linux test (Arch, GCC 16.2.1, glibc, Release), this PR merged onto main 7e181fc together with #4963, #4953, #4946 and #4942 (no conflicts): guest_math passes. With this PR's Math.cpp change reverted it fails on Linux too, so the check guards the change on both systems.

@QRMOE
QRMOE marked this pull request as ready for review October 13, 2026 10:53
@oneandonlydean
oneandonlydean merged commit 34355ee into boykopovar:main Oct 14, 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.

4 participants