Skip to content

fix(libc): quiet signalling NaNs in trunc, ceil, floor and nearbyint as titles' libc.prx does - #10370

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
JJenkx:windows/libc-rounding-quiet-snan
Oct 26, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
JJenkx:windows/libc-rounding-quiet-snan

Conversation

@JJenkx

@JJenkx JJenkx commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

What

trunc, ceil, floor and nearbyint, and their float forms, returned the host's result. On Windows (UCRT) that passes a signalling NaN through unchanged. The libc.prx that titles ship follows FreeBSD msun (s_trunc.c, s_floor.c and the others), which returns x + x for a NaN. So the NaN comes back quieted, with its payload and sign. For example, floor(0x7ff0000000000001) is 0x7ff8000000000001 there and 0x7ff0000000000001 here, and floorf(0xffa00123) is 0xffe00123 there.

Each of the eight functions now returns x + x for a NaN argument and calls the host otherwise. Every other result already matched the titles' copies, including infinities, zeros and quiet NaNs.

Tested

Current Linux validation: 2641b6fe919881a71c0a850252ecddf1e59ca59b is one commit on main 52a8bed576e5c54a7f443728cdf663a080f8f9ed, without the old merge commit. Original production added/removed lines are unchanged; current main's expm1 fixtures and this topic's NaN fixtures/calls are both retained, with obsolete manual declarations left removed in favor of the API headers.

Linux x86-64 / GCC 16.2.1 / Release: independent libc/math build and guest_math plus guest_dinkumware_internals each pass three runs. With only production Math.cpp replaced by this tested main and the NaN cases retained, guest_math aborts. Restoring the change gives six passing invocations and the original libc library SHA-256 2b21e99d369eb2bea7f9fdddb508cdab905bf69a56c49a14e6baf97abd1c9573. No named assertion is emitted by the Release negative control. Conventions and whitespace pass. The first build process was terminated after successful configuration; its incomplete receipt is preserved/excluded, and the resumed build completed successfully before all tests.

Read-only merge-tree against fetched main 25c1aa1e79329e0e2957b4fdd731144dad8be724 is clean; that merge tree was not rebuilt. Exact-head Linux logs/JUnit, rebase proof and negative/restoration controls, SHA-256 6c0a1a6c064a35cb55d5e985686657faee26e925c92ff1c38fc2e8a2d480c3cd. Windows remains user-paused and was not rerun on this head.

Historical original Windows/bundled-module evidence (not rerun on the current head):
Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release, BUILD_TESTING=ON, main d7948b0.

  • Comparison: a scratch loader runs the decrypted libc.prx of eleven titles natively and supplies __error: PPSA04158, PPSA05916, PPSA07923, PPSA09614, PPSA13934, PPSA20423, PPSA25636, PPSA26528, PPSA33655, PPSA34008 and PPSA35169.
    • Edge probe: for two signalling NaNs of opposite signs, a quiet NaN and both infinities, all eleven give identical results for the eight functions, and none sets errno.
    • Before: loading main's -O3 libc.prx DLL next to PPSA07923's copy, the eight functions differ on 48 (double) and 390 (float) of 400,012 sampled inputs each, all signalling NaNs.
    • After: this PR's -O3 libc.prx DLL matches the copies bundled with PPSA07923 and PPSA13934 on all 400,012 inputs of each of the eight functions.
  • guest_math: the new CheckRoundingNaNConsoleBits checks those five inputs against the bundled-module results for all eight functions. main's existing rounding checks still pass.
  • guest_math and guest_dinkumware_internals pass in three runs out of three on the exact head.
  • Negative control: with main's Math.cpp and these tests, guest_math aborts in a Require, while guest_dinkumware_internals still passes.
  • python tools/check_conventions.py --base origin/main and git diff --check pass.
  • Order: One commit directly on main 52a8bed576e5c54a7f443728cdf663a080f8f9ed; retains current main’s expm1 tests alongside this topic’s signalling-NaN cases.
  • Not tested: Linux and macOS (the NaN path no longer depends on the host), a console, the floating-point exception flags, and the long double forms.

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 (attach them to this PR)
  • New third-party code is a submodule built from source: none
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

AI-assisted (Claude Code).

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed current head 58833d2. The eight wrappers now quiet NaNs by evaluating x + x only for NaN inputs and leave finite/infinite paths unchanged. The added bit-pattern vectors cover positive/negative signalling NaNs, payload/sign preservation, quiet NaNs and infinities across all eight functions. The author reports exact-head guest_math and guest_dinkumware_internals passing three times and comparison against bundled libc.prx copies; hosted eligibility, conventions, intake, labels and report checks pass. Product Linux/Windows checks are skipped by policy; relinker and memory checks were still running when reviewed. I did not run guest_math locally. git diff --check upstream/main...upstream/pr/10370 passes. No blocking issue found.

@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 6295 core/libs/prx/libc/src/Math.cpp
core/libs/tests/GuestMath.cpp
PR 7201 core/libs/prx/libc/src/Math.cpp
PR 7544 core/libs/prx/libc/src/Math.cpp
core/libs/tests/GuestMath.cpp
PR 8417 core/libs/prx/libc/src/Math.cpp
core/libs/tests/GuestMath.cpp
PR 10007 core/libs/prx/libc/src/Math.cpp
core/libs/tests/GuestMath.cpp
PR 10467 core/libs/prx/libc/src/Math.cpp
core/libs/tests/GuestMath.cpp
PR 10742 core/libs/prx/libc/src/Math.cpp
core/libs/tests/GuestMath.cpp

@oneandonlydean oneandonlydean self-assigned this Oct 23, 2026
@github-actions github-actions Bot added the libc label Oct 23, 2026
@JJenkx

JJenkx commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

Linux run at this PR's exact head 58833d2f62 (58833d2f62674cc2d8a84d93a83e72ed6c2e91d3), not merged onto anything else; its base on main is d7948b09f9.

Arch Linux, kernel 7.2.9, Ryzen 9 7950X, g++ (GCC) 16.2.1 20260810, glibc 2.44, x86-64. Release, BUILD_TESTING=ON.

  • guest_math: passed in each of 3 runs, exit code 0 each time, with no failed, skipped or not-run tests.

This is the focused test only; no title, console or floating-point exception flags were checked.

AI-assisted: yes (Claude Code).

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 24, 2026
JJenkx pushed a commit to JJenkx/AnyPS5 that referenced this pull request Oct 24, 2026
Additive conflicts with main's newer libc changes: the debt list keeps both
sides' entries (per entry) and GuestMath.cpp keeps both sides' test
functions and calls.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@JJenkx

JJenkx commented Oct 24, 2026

Copy link
Copy Markdown
Contributor Author

Merged current main fe204e1a8d into this branch as e2a9217ddd (was 58833d2f62), a merge commit rather than a rebase. Done on Linux while the Windows session is paused.

  • The conflicts were additive: the docs/dev/debt/libc.md list keeps both sides' entries (checked per entry), and GuestMath.cpp keeps both sides' test functions and calls.
  • New head, Linux only: guest_math and guest_math_exact pass (Arch Linux, kernel 7.2.9, GCC 16.2.1, glibc 2.44, Release, BUILD_TESTING=ON). tools/check_conventions.py --base origin/main reports no errors.
  • Earlier Windows and comparison evidence in this thread stays pinned to the heads it was measured on.

AI-assisted: yes (Claude Code)

@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed and removed needs rebase Conflicts with main, rebase needed labels Oct 24, 2026
@JJenkx
JJenkx force-pushed the windows/libc-rounding-quiet-snan branch from e2a9217 to 2641b6f Compare October 25, 2026 03:15
@JJenkx

JJenkx commented Oct 25, 2026

Copy link
Copy Markdown
Contributor Author

Refreshed as one commit 2641b6fe919881a71c0a850252ecddf1e59ca59b on main 52a8bed576e5c54a7f443728cdf663a080f8f9ed, without the former merge commit. Production changes are identical to the reviewed implementation; main's expm1 tests and this PR's signalling-NaN tests/calls are retained. The obsolete manual prototype block remains removed.

Fresh Linux libc/math build passes, guest_math and guest_dinkumware_internals each pass three runs, and the production-only main control aborts guest_math. Restoration reproduces the original library bytes and passing tests. Conventions/whitespace pass; merge-tree against fetched main 25c1aa1e79329e0e2957b4fdd731144dad8be724 is clean. Description distinguishes current Linux checks from historical Windows/bundled-module comparisons; no fresh Windows claim.

Exact-head validation/rebase/control receipts, SHA-256 6c0a1a6c064a35cb55d5e985686657faee26e925c92ff1c38fc2e8a2d480c3cd. AI-assisted: Codex.

@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed and removed needs rebase Conflicts with main, rebase needed labels Oct 25, 2026
…as titles' libc.prx does

trunc, ceil, floor and nearbyint and their float forms returned the
host's result, which on Windows passes a signalling NaN through
unchanged. The titles' copies follow FreeBSD msun, which returns x + x
for a NaN, so the NaN comes back quieted with its payload and sign; these
functions now do the same before calling the host for other arguments.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@JJenkx
JJenkx force-pushed the windows/libc-rounding-quiet-snan branch from a990a75 to f91f045 Compare October 26, 2026 02:29
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 26, 2026
@oneandonlydean
oneandonlydean merged commit 442c43a into boykopovar:main Oct 26, 2026
17 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.

3 participants