From 988d304c5ce1882b553503df6e8577b4856f7171 Mon Sep 17 00:00:00 2001 From: Alex <270190108+CouchRiv@users.noreply.github.com> Date: Sun, 11 Oct 2026 11:42:42 -0400 Subject: [PATCH] fix(libc): keep the acosf result and leave errno unchanged The previous commit replaced the out-of-range result with the default quiet NaN 0x7fc00000, but main and FreeBSD e_acosf.c return 0xffc00000. acosf now calls the host and restores errno, so only errno differs from main. The guest test pins the result bits for 2.0f and -2.0f and keeps the in-range case acosf(0.5f). Co-Authored-By: Claude Sonnet 5.5 --- core/libs/prx/libc/src/Math.cpp | 9 ++++----- core/libs/tests/GuestMath.cpp | 8 +++----- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/core/libs/prx/libc/src/Math.cpp b/core/libs/prx/libc/src/Math.cpp index f6ccc2b03..f127140ab 100644 --- a/core/libs/prx/libc/src/Math.cpp +++ b/core/libs/prx/libc/src/Math.cpp @@ -183,11 +183,10 @@ float APS5_VABI asinf_nid_postfix(float x) { return result; } float APS5_VABI acosf_nid_postfix(float x) { - if (x < -1.0f || x > 1.0f) { - std::feraiseexcept(FE_INVALID); - return std::numeric_limits::quiet_NaN(); - } - return std::acos(x); + const int saved_errno = errno; + const float result = std::acos(x); + errno = saved_errno; + return result; } float APS5_VABI atan2f_nid_postfix(float y, float x) { return std::atan2(y, x); } float APS5_VABI hypotf_nid_postfix(float x, float y) { return static_cast(std::hypot(static_cast(x), static_cast(y))); } diff --git a/core/libs/tests/GuestMath.cpp b/core/libs/tests/GuestMath.cpp index 64c693895..cc1760c60 100644 --- a/core/libs/tests/GuestMath.cpp +++ b/core/libs/tests/GuestMath.cpp @@ -216,13 +216,11 @@ static void CheckPowfSpecialValue() { static void CheckAcosfErrno() { errno = 0; - (void)acosf_nid_postfix(2.0f); + Require(std::bit_cast(acosf_nid_postfix(2.0f)) == 0xffc00000u); Require(errno == 0); - errno = 0; - (void)acosf_nid_postfix(-2.0f); + Require(std::bit_cast(acosf_nid_postfix(-2.0f)) == 0xffc00000u); Require(errno == 0); - errno = 0; - (void)acosf_nid_postfix(0.5f); + Require(std::bit_cast(acosf_nid_postfix(0.5f)) == 0x3f860a92u); Require(errno == 0); }