fix(libc): store EDOM and raise FE_INVALID from acosf and asinf domain errors #12319
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12319"
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 JJenkx on 2026-10-28T09:19:52Z.
What
For |x| > 1, the infinities and NaN, titles'
libc.prxstoresEDOMand raisesFE_INVALIDfromacosf, for a quiet NaN input too. For a quiet NaN,asinfalso raisesFE_INVALID. Hereacosfreturned the same NaN bits without either.asinfstoredEDOMbut raised nothing for a quiet NaN, because(x - x) / (x - x)only raises for a signalling one.Both now call
_Feraise_nid_postfix(0x01), the helpernextafteralready uses. It storesEDOMand raises the invalid flag in the x87 and SSE units. Every result is unchanged.The
acosftest from #3688 asserted thaterrnostays unchanged, following FreeBSD'sMATH_ERREXCEPT. The titles' library doesn't do that, and the debt entry already recorded "the console storesEDOMand raisesFE_INVALID".CheckAcosfErrnonow checksEDOMandFE_INVALID, along with the result bits, for ±2, ±inf,1 + ulpand quiet NaNs, and thatacosf(0.5)still sets neither.CheckAsinfErrnoalso checks the flag. Theacosfdebt entry is updated.Tested
Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release,
BUILD_TESTING=ON, onmainab168194d4.guest_mathandguest_math_exactpass in each of 3 runs.main'sMath.cppand this test,guest_mathfails.libc.prx: I loaded the bundledlibc.prxnatively and calledacosfandasinfby NID, side by side with this build.errnoand raisedFE_INVALID/FE_INEXACT/FE_DIVBYZERO: ±1.5, ±2.5,±(1 + ulp), ±inf, ±quiet NaN, a signalling NaN, ±1, 0.5, the smallest subnormal, -0 andFLT_MAX.maindiffers in all 10 domain-erroracosfcases and in the two quiet-NaNasinfcases. With this change none of those differ.errno, on PPSA07923 and PPSA05916:mainacosferrnodifferencesasinfOne difference remains, and this PR leaves it alone. For the smallest subnormal, the titles'
asinfraisesFE_INEXACT(on both titles), while the debt entry says tiny arguments don't. I didn't change that or its entry here.Not tested on Linux or macOS.
Overlap:
tools/pr_overlap.pyreports #11849 editing the neighbouringasinldebt entry (lines 147–148). It's a textual adjacency only, so either can land first.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)Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-10-28T13:38:48Z.
Review: APPROVED
Approving head
8b5c02ca61. I read the whole diff and ran firmware 13.42'sacosfandasinf: the decrypted systemlibSceLibcInternal.sprx's exports, natively on a PC (not a console), on 19 inputs: every value the new tests use plus ±1.5, ±2.5,-(1 + ulp), a signalling NaN, ±1, the smallest subnormal, -0 andFLT_MAX. Three identical runs.±(1 + ulp), ±inf,FLT_MAXand the NaNs, both functions storeEDOMand raiseFE_INVALID, the quiet NaN0x7fc00000included. They return0xffc00000for the non-NaN inputs and the quieted input for a NaN (0x7fc00000,0xffc00000, and0x7fa00000→0x7fe00000).acosf(0.5)returns0x3f860a92without touchingerrnoor raisingFE_INVALID; ±1, -0 and the smallest subnormal leaveerrnoalone too.This matches the new
CheckAcosfErrnoandCheckAsinfErrnoexpectations and the titles' measurements in the description. #3688's "errno unchanged" came from FreeBSD's source rather than a measurement; the module disagrees with it the same way the titles' copies do.