fix(libc): keep the acosf result and leave errno unchanged #3688
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3688"
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 CouchRiv on 2026-10-11T15:22:43Z.
What
acosfon an out-of-range input sets the host errno where FreeBSD does not:The export forwards to the host
std::acos, and glibc sets errno for the domain error. FreeBSDmsunnever does:math_errhandlingisMATH_ERREXCEPT(github.com/freebsd/freebsd-src@8c639945a4/lib/msun/src/math.h (L67-L69)).The result (
0xffc00000, whate_acosf.cgives with(x-x)/(x-x)on x86) already matches.acosfnow callsstd::acosand writes the caller's errno back, the same way asasinfin #3693. The result bits andthe floating point exception flags are the same as on
main. The other libm functions are covered by #3690(
acoshf,sin,log, ... in one place), #3693 (asinf), #3599 (exp2) and #3600 (fmod).Tested
Linux (CachyOS), GCC 16; RTX 4070 Ti (NVIDIA), Radeon 610M (RADV) and lavapipe (Mesa 26.2.4).
guest_mathchecksacosf(2.0f)andacosf(-2.0f)return0xffc00000with errno unchanged, andacosf(0.5f)returns
0x3f860a92.scripts/verify-branch.shwithguest_math: build, ctest on the three drivers, conventions,diff check, publication gate, 8 of 8 pass.
main'sMath.cppthe same test aborts at the first errno check (errno 33).mainon 648 inputs (special values, random bit patterns): result bits and exception flags identical,0 differences; errno 0 on all (389 inputs set errno 33 on
main). OpenLibm 0.8.8 gives the same bits and errno 0 onthe inputs the test uses.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repositoryAI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T15:26:40Z.
Review: CHANGES_REQUESTED
Thanks for the fix. A few things to address:
core/libs/prx/libc/src/Math.cpp:44returnsstd::numeric_limits<float>::quiet_NaN()=0x7fc00000, but the description says the expected result is0xffc00000(whatmainreturns and what FreeBSDe_acosf.cgives with(x-x)/(x-x)on x86; I measured0xffc00000for0/0). The patch removes errno but also changes the value. Return0xffc00000explicitly, or compute(x - x) / (x - x), so only errno differs.core/libs/tests/GuestMath.cpp:131only checkserrno. Pin the result bits for2.0fand-2.0ftoo (std::bit_cast<std::uint32_t>(...) == 0xffc00000), and keep the in-range case (acosf(0.5f)).[x]if it doesn't apply.asinf, ...); say in the description that they are left out on purpose, or open a follow-up.Checked: build + ctest of core/libs (74/74), and
guest_mathfails without the change.Imported from boykopovar/AnyPS5. Originally posted by CouchRiv on 2026-10-11T15:57:13Z.
quiet_NaN()are gone;acosfcallsstd::acosand restores errno, so only errno differs frommain. Measured:acosf(2.0f)andacosf(-2.0f)give0xffc00000onmain, on this branch and on OpenLibm 0.8.8.CheckAcosfErrnonow pinsstd::bit_cast<std::uint32_t>(...) == 0xffc00000ufor2.0fand
-2.0f, and keepsacosf(0.5f)(now also pinned:0x3f860a92, equal onmainand OpenLibm).tools/check_conventions.py --base origin/main: "All conventionschecks passed."
asinfis #3693; the rest of the libm family (acosh, acoshf, sin,cos, tan, sinh, cosh, asinh, atanh, exp, expm1, log, log2, log10, log1p, sqrt, pow, atan2, hypot, ldexp, scalbn,
sincos and their float versions) is #3690, widened in this round to cover them in one place;
exp2is #3599 andfmodis #3600.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T09:56:01Z.
Review: APPROVED
Rebased onto current
main(only a test-adjacency conflict inGuestMath.cpp;CheckPowfSpecialValueandCheckAcosfErrnoboth kept). Checked:guest_mathpasses with the change and fails withMath.cppreverted;acosf(±2.0f)returns0xffc00000with errno unchanged. Merging once the full Build is green.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T10:27:34Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/libs/tests/GuestMath.cppL216, L840-841