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

Merged
QRMOE merged 2 commits from upstream-pr/4942 into main 2026-10-14 01:29:14 +00:00
QRMOE commented 2026-10-13 05:49:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by QRMOE on 2026-10-13T05:49:09Z.


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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4838968573 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4942). Originally posted by [QRMOE](https://github.com/QRMOE) on 2026-10-13T05:49:09Z. --- ### 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`](https://github.com/freebsd/freebsd-src/blob/releng/11.4/lib/msun/src/s_llroundl.c) and its [`s_lround.c`](https://github.com/freebsd/freebsd-src/blob/releng/11.4/lib/msun/src/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](https://github.com/boykopovar/AnyPS5/pull/4942#issuecomment-6140229260): 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](https://github.com/boykopovar/AnyPS5/pull/4942#issuecomment-6140476658): 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 - [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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's technical debt file - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none - [x] AI-assisted: yes
xXPBSXx commented 2026-10-13 07:05:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T07:05:51Z.


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).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6140229260 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4942#issuecomment-6140229260). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-13T07:05:51Z. --- 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 commented 2026-10-13 07:22:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by nicolasfalesy on 2026-10-13T07:22:31Z.


Linux test (Arch, GCC 16.2.1, glibc, Release), this PR merged onto main 7e181fcc3 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6140476658 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4942#issuecomment-6140476658). Originally posted by [nicolasfalesy](https://github.com/nicolasfalesy) on 2026-10-13T07:22:31Z. --- Linux test (Arch, GCC 16.2.1, glibc, Release), this PR merged onto `main` 7e181fcc3 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.
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!4942
No description provided.