fix: bits_float quiets signalling NaNs on every Python version (3.14 keeps them) #238

Manually merged
github merged 1 commit from gh-pr/238/head into gh-pr/238/base 2026-11-26 05:39:24 +00:00
Owner

@⁠lcg007xd-c on GitHub · 2026-11-25 20:46 UTC · original
lcg007xd-c:fix/f32-nan-quiet-python314 → main · +24 −1 · 2 files · 1 commits · merged 2026-11-25 21:08 UTC

Change

The reference interpreter relies on CPython quieting a signalling f32 NaN when struct.unpack("<f") widens it to a double (_first_nan in emu/rdna2_exec_ops.py: "déjà rendu silencieux par la conversion en double"). CPython 3.14 no longer does: it keeps the signalling bit through struct. Measured with the same one-liner (struct.unpack("<f", struct.pack("<I", 0x7F800001)), then struct.pack("<f", …)):

3.12.13 → 0x7fc00001
3.13.13 → 0x7fc00001
3.14.10 → 0x7f800001

So on Python 3.14, main (4f2cf5c) fails 4 FMA tests: the FMA returns the signalling NaN instead of the quiet one.

FAILED tests/test_rdna2_exec_fma.py::test_interpreter_rounds_once_in_every_encoding[NaN signalant en a, rendu silencieux]
FAILED tests/test_rdna2_exec_fma.py::test_interpreter_rounds_once_in_every_encoding[NaN en b avant NaN en c]
FAILED tests/test_rdna2_exec_fma.py::test_interpreter_rounds_once_in_every_encoding[NaN signalant en c]
FAILED tests/test_rdna2_exec_fma.py::test_interpreter_matches_the_exact_rounding_on_a_seeded_sweep
  7F800001 × 3F800000 + 00000000 : (2139095041, …) au lieu de (2143289345, …)

Now bits_float sets bit 22 itself when the pattern is a NaN, so every Python version follows the rule that the 3.12 CI already checks against the GPU. Infinities, quiet NaNs and ordinary values are unchanged. Nothing changes on 3.12 or 3.13.

Linked issue: none.

Verification

Linux (Arch), no C++ runtime, no GPU (the runtime and GPU tests skip):

Python 3.14.10: python -m pytest → 2 failed, 1019 passed, 315 skipped
Python 3.12.13: python -m pytest → 2 failed, 1019 passed, 315 skipped
python -m ruff check --select W605,F,E9 PrototypeScarlett tests tools → All checks passed!

The 2 remaining failures are tests/test_jour_j.py (manifest name case on Linux, fixed separately in #237), the same on both versions.

Not run: the Windows CI job and the GPU/WARP parity tests (no HLSL change).

Oracle and test data

  • New test_signalling_nan_operands_come_back_quiet_on_every_python (tests/test_rdna2_exec_fma.py): signalling NaNs of both signs and the largest payload come back with bit 22 set; a quiet NaN, ±infinity and 1.0 are unchanged.
  • Failure case: on Python 3.14 without the change, tests/test_rdna2_exec_fma.py has 7 failures (the 4 above and 3 of the new cases). On 3.12 the new test also passes without the change, because 3.12 already quiets.
  • Test data is built in the tests.

Checklist

  • The PR covers a single reviewable behaviour.
  • A test fails without this change and passes with it. (On Python 3.14.)
  • The commands and results of each check are given above.
  • An unimplemented function returns an error (E_NOTIMPL), never a fake success.
  • README: the same change in all 9 languages (test_readme_sync.py checks it). (No README change; still 1300+.)
  • No game, console or SDK file, no key, no dump, no download link.
  • Findings drawn from a title: none.
  • Code taken from another project: none.

Made with AI assistance (Claude Code).

🤖 Generated with Claude Code

**@⁠lcg007xd-c** on GitHub · 2026-11-25 20:46 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/238) `lcg007xd-c:fix/f32-nan-quiet-python314` → `main` · +24 −1 · 2 files · 1 commits · merged 2026-11-25 21:08 UTC ## Change The reference interpreter relies on CPython quieting a signalling f32 NaN when `struct.unpack("<f")` widens it to a double (`_first_nan` in `emu/rdna2_exec_ops.py`: "déjà rendu silencieux par la conversion en double"). **CPython 3.14 no longer does**: it keeps the signalling bit through `struct`. Measured with the same one-liner (`struct.unpack("<f", struct.pack("<I", 0x7F800001))`, then `struct.pack("<f", …)`): ``` 3.12.13 → 0x7fc00001 3.13.13 → 0x7fc00001 3.14.10 → 0x7f800001 ``` So on Python 3.14, `main` (`4f2cf5c`) fails 4 FMA tests: the FMA returns the signalling NaN instead of the quiet one. ``` FAILED tests/test_rdna2_exec_fma.py::test_interpreter_rounds_once_in_every_encoding[NaN signalant en a, rendu silencieux] FAILED tests/test_rdna2_exec_fma.py::test_interpreter_rounds_once_in_every_encoding[NaN en b avant NaN en c] FAILED tests/test_rdna2_exec_fma.py::test_interpreter_rounds_once_in_every_encoding[NaN signalant en c] FAILED tests/test_rdna2_exec_fma.py::test_interpreter_matches_the_exact_rounding_on_a_seeded_sweep 7F800001 × 3F800000 + 00000000 : (2139095041, …) au lieu de (2143289345, …) ``` Now `bits_float` sets bit 22 itself when the pattern is a NaN, so every Python version follows the rule that the 3.12 CI already checks against the GPU. Infinities, quiet NaNs and ordinary values are unchanged. Nothing changes on 3.12 or 3.13. Linked issue: none. ## Verification Linux (Arch), no C++ runtime, no GPU (the runtime and GPU tests skip): ``` Python 3.14.10: python -m pytest → 2 failed, 1019 passed, 315 skipped Python 3.12.13: python -m pytest → 2 failed, 1019 passed, 315 skipped python -m ruff check --select W605,F,E9 PrototypeScarlett tests tools → All checks passed! ``` The 2 remaining failures are `tests/test_jour_j.py` (manifest name case on Linux, fixed separately in #237), the same on both versions. Not run: the Windows CI job and the GPU/WARP parity tests (no HLSL change). ## Oracle and test data - New `test_signalling_nan_operands_come_back_quiet_on_every_python` (`tests/test_rdna2_exec_fma.py`): signalling NaNs of both signs and the largest payload come back with bit 22 set; a quiet NaN, ±infinity and 1.0 are unchanged. - Failure case: on Python 3.14 without the change, `tests/test_rdna2_exec_fma.py` has 7 failures (the 4 above and 3 of the new cases). On 3.12 the new test also passes without the change, because 3.12 already quiets. - Test data is built in the tests. ## Checklist - [x] The PR covers a single reviewable behaviour. - [x] A test fails without this change and passes with it. (On Python 3.14.) - [x] The commands and results of each check are given above. - [x] An unimplemented function returns an error (`E_NOTIMPL`), never a fake success. - [x] README: the same change in all 9 languages (`test_readme_sync.py` checks it). (No README change; still `1300+`.) - [x] No game, console or SDK file, no key, no dump, no download link. - [x] Findings drawn from a title: none. - [x] Code taken from another project: none. Made with AI assistance (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The interpreter relied on CPython turning a signalling f32 NaN quiet when
struct.unpack("<f") widens it to a double (_first_nan says so). CPython
3.14 keeps the signalling bit: unpack then pack of 0x7F800001 gives
0x7F800001 on 3.14.10 and 0x7FC00001 on 3.12.13 and 3.13.13. On 3.14 the
FMA NaN cases of tests/test_rdna2_exec_fma.py returned the signalling NaN
(4 failures on main).

bits_float now sets bit 22 of a NaN pattern itself, so every version
follows the rule the 3.12 CI already checks.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:39:22 +00:00
github manually merged commit a8e9703328 into gh-pr/238/base 2026-11-26 05:39:24 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.