diff --git a/core/libs/prx/libc/src/Math.cpp b/core/libs/prx/libc/src/Math.cpp index 90c19cb5f..f127140ab 100644 --- a/core/libs/prx/libc/src/Math.cpp +++ b/core/libs/prx/libc/src/Math.cpp @@ -182,7 +182,12 @@ float APS5_VABI asinf_nid_postfix(float x) { errno = saved_errno; return result; } -float APS5_VABI acosf_nid_postfix(float x) { return std::acos(x); } +float APS5_VABI acosf_nid_postfix(float 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))); } double APS5_VABI hypot_nid_postfix(double x, double y) { diff --git a/core/libs/tests/GuestMath.cpp b/core/libs/tests/GuestMath.cpp index 2f09ac820..cc1760c60 100644 --- a/core/libs/tests/GuestMath.cpp +++ b/core/libs/tests/GuestMath.cpp @@ -214,6 +214,16 @@ static void CheckPowfSpecialValue() { Require(std::bit_cast(powf_nid_postfix(1.0f, std::bit_cast(0x7f800001u))) == 0x3f800000u); } +static void CheckAcosfErrno() { + errno = 0; + Require(std::bit_cast(acosf_nid_postfix(2.0f)) == 0xffc00000u); + Require(errno == 0); + Require(std::bit_cast(acosf_nid_postfix(-2.0f)) == 0xffc00000u); + Require(errno == 0); + Require(std::bit_cast(acosf_nid_postfix(0.5f)) == 0x3f860a92u); + Require(errno == 0); +} + static void CheckLongDouble() { Require(ExtendedBits(acosl_nid_postfix(-1.0L), 0xc90fdaa22168c235ull, 0x4000)); Require(ExtendedBits(acosl_nid_postfix(0.0L), 0xc90fdaa22168c235ull, 0x3fff)); @@ -839,6 +849,7 @@ int main() { Require(minimum.quot == -214748364 && minimum.rem == -8); CheckPowfSpecialValue(); Require(abs_nid_postfix(0) == 0); + CheckAcosfErrno(); Require(abs_nid_postfix(42) == 42); Require(abs_nid_postfix(-42) == 42); Require(abs_nid_postfix(std::numeric_limits::max()) == std::numeric_limits::max());