From ce4bdbf2eb8e2fc45b2c2099b78b45807418df5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Franch?= Date: Mon, 5 Oct 2026 19:22:12 +0200 Subject: [PATCH] feat(libc): strtoimax and logbf Co-Authored-By: Claude --- core/libs/prx/libc/src/Math.cpp | 1 + core/libs/prx/libc/src/RuntimeSupport.cpp | 4 ++++ core/libs/tests/GuestMath.cpp | 13 +++++++++++++ 3 files changed, 18 insertions(+) diff --git a/core/libs/prx/libc/src/Math.cpp b/core/libs/prx/libc/src/Math.cpp index 40eda10b4..ee249e03b 100644 --- a/core/libs/prx/libc/src/Math.cpp +++ b/core/libs/prx/libc/src/Math.cpp @@ -13,6 +13,7 @@ float APS5_VABI acosf_nid_postfix(float x) { return std::acos(x); } float APS5_VABI atan2f_nid_postfix(float y, float x) { return std::atan2(y, x); } float APS5_VABI tanf_nid_postfix(float x) { return std::tan(x); } float APS5_VABI log10f_nid_postfix(float x) { return std::log10(x); } +float APS5_VABI logbf_nid_postfix(float x) { return std::logb(x); } double APS5_VABI exp2_nid_postfix(double x) { return std::exp2(x); } double APS5_VABI ldexp_nid_postfix(double x, int exponent) { return std::ldexp(x, exponent); } double APS5_VABI scalbn_nid_postfix(double x, int exponent) { return std::scalbn(x, exponent); } diff --git a/core/libs/prx/libc/src/RuntimeSupport.cpp b/core/libs/prx/libc/src/RuntimeSupport.cpp index ef00dd455..e6bf99f61 100644 --- a/core/libs/prx/libc/src/RuntimeSupport.cpp +++ b/core/libs/prx/libc/src/RuntimeSupport.cpp @@ -93,6 +93,10 @@ unsigned int APS5_VABI _Atomic_load_4_nid_postfix(volatile unsigned int* target, return GccAtomicLoad(target); } +std::intmax_t APS5_VABI strtoimax_nid_postfix(const char* str, char** endptr, int base) { + return std::strtoimax(str, endptr, base); +} + std::uintmax_t APS5_VABI strtoumax_nid_postfix(const char* str, char** endptr, int base) { return std::strtoumax(str, endptr, base); } diff --git a/core/libs/tests/GuestMath.cpp b/core/libs/tests/GuestMath.cpp index 7ef93b7ec..ab9241755 100644 --- a/core/libs/tests/GuestMath.cpp +++ b/core/libs/tests/GuestMath.cpp @@ -10,6 +10,7 @@ float APS5_VABI strtof_nid_postfix(const char*, char**); long double APS5_VABI strtold_nid_postfix(const char*, char**); std::int64_t APS5_VABI strtol_nid_postfix(const char*, char**, int); std::uint64_t APS5_VABI strtoul_nid_postfix(const char*, char**, int); +std::intmax_t APS5_VABI strtoimax_nid_postfix(const char*, char**, int); int* APS5_VABI __error_nid_postfix(); float APS5_VABI fmodf_nid_postfix(float, float); float APS5_VABI asinf_nid_postfix(float); @@ -17,6 +18,7 @@ float APS5_VABI acosf_nid_postfix(float); float APS5_VABI atan2f_nid_postfix(float, float); float APS5_VABI tanf_nid_postfix(float); float APS5_VABI log10f_nid_postfix(float); +float APS5_VABI logbf_nid_postfix(float); double APS5_VABI exp2_nid_postfix(double); double APS5_VABI ldexp_nid_postfix(double, int); double APS5_VABI scalbn_nid_postfix(double, int); @@ -69,6 +71,12 @@ static void CheckIntegerConversions() { std::fprintf(stderr, "Guest strtol failed for '%s' in base %d\n", test.text, test.base); std::abort(); } + *__error_nid_postfix() = 0; + const auto maxValue = strtoimax_nid_postfix(test.text, &end, test.base); + if (maxValue != test.value || end != test.text + test.consumed || *__error_nid_postfix() != test.error) { + std::fprintf(stderr, "Guest strtoimax failed for '%s' in base %d\n", test.text, test.base); + std::abort(); + } } struct UnsignedCase { const char* text; @@ -134,6 +142,11 @@ int main() { Require(std::abs(atan2f_nid_postfix(1.f, -1.f) - 2.3561945f) < 0.000001f); Require(tanf_nid_postfix(0.f) == 0.f); Require(log10f_nid_postfix(100.f) == 2.f); + Require(logbf_nid_postfix(8.f) == 3.f && logbf_nid_postfix(-0.75f) == -1.f); + Require(logbf_nid_postfix(std::numeric_limits::denorm_min()) == -149.f); + Require(logbf_nid_postfix(0.f) == -std::numeric_limits::infinity()); + Require(logbf_nid_postfix(-std::numeric_limits::infinity()) == std::numeric_limits::infinity()); + Require(std::isnan(logbf_nid_postfix(std::numeric_limits::quiet_NaN()))); Require(exp2_nid_postfix(-3.) == 0.125); Require(ldexp_nid_postfix(0.75, 4) == 12.); Require(scalbn_nid_postfix(0.75, -2) == 0.1875);