fix(libc): raise round's inexact for large values and pass signaling NaNs through fdim #23410
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/23410"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by DerKarussellbremser on 2026-11-19T00:47:01Z.
What
The
doubleandfloatsiblings of #23401. Measured against thelibc.prxbundled with PPSA10122 01.101.000 (SDK 5.00),round,roundf,fdimandfdimfgave the module's value everywhere but not always its exception flags:round,roundf(0x4eec0, 0x4ef50). The module takest = floor(|x|)without raising anything, always formst + 1, and then returnstort + 1. From 2^53 (2^24 forfloat) upwardst + 1is inexact, soFE_INEXACTis raised although the result isx. This libc used the hostround, which raises nothing there. They now follow the module's sequence: the fraction is cleared by a bit mask, so nothing is raised for a non-integer, andt + 1is computed whether it is used or not.fdim,fdimf(0x47c00, 0x47c60). A signaling NaN is returned unchanged with no flag by the module;std::isnanraisedFE_INVALIDon it. NaNs are now recognized from the bits and returned as they are. The selection also comparesy < x, as the module does, instead of comparing the difference with zero, which set the denormal-operand bit on 2 of 500,000floatpairs.The value that is not selected is held in a
volatileso the compiler keeps the operation; GCC otherwise moves it into the branch that uses it (I saw exactly that forfdimduring this work: 198,722 of 500,000 pairs lost the flag).No constant or table from the module is involved.
Tested
Windows 11 Home 10.0.26200, WinLibs GCC 15.2.0 r7 UCRT, Release, on
main9ffa95e7d9.guest_mathaborts (exit code 0xc0000409) on the baseMath.cppand passes with the change.ctest -R "^guest_(math|dinkumware|bessel|sce_v2|floating|complex|icu)": 124 of 124 pass, with the 90 test targets behind them brought up to date at this source.errno.round23,891 flag differences,roundf20,383,fdim22,fdimf195; no difference in bits.tools/check_conventions.py --base origin/mainpasses.tools/pr_overlap.py --branch fix/round-fdim-flags: one report, #19434, which addslibSceLibcInternalforwarders that call thisroundandroundf; it does not implement them. It could not compare #6295, #7544 and #17026 because they conflict withmain; none of their diffs touches these four functions.volatilehas to do the same job for GCC 13 and Clang; a console; other SDK versions; MXCSR rounding modes other than to-nearest.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
https://claude.ai/code/session_011TXsSW8zeAgKgHLCFsYwM3
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-19T00:48:55Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
053c0ff7da:tools/check_conventions.pypassed.guest_math_testsbuilt cleanly.guest_math):core/libs/prx/libc/src/Math.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me