From 0f34160a49a9f44951cd7d5a4f966e8782ae4fb7 Mon Sep 17 00:00:00 2001 From: Nithishvelan M Date: Mon, 19 Oct 2026 17:27:50 +0530 Subject: [PATCH 1/2] feat(libc): export tgammaf float math function PPSA26578 (issue #7624) imports tgammaf (NID B2ZbqV9geCM) from libc, and its bundled libc.prx does not export it, causing the process to exit with 0xC0000139 (GetLastError: 127). Export tgammaf_nid_postfix in core/libs/prx/libc/src/Math.cpp delegating to std::tgamma(float), and add unit test coverage in GuestMath verifying factorials, half-integers, poles, and negative values. --- core/libs/prx/libc/src/Math.cpp | 1 + core/libs/tests/GuestMath.cpp | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/core/libs/prx/libc/src/Math.cpp b/core/libs/prx/libc/src/Math.cpp index 8d21db8f88..8391b613f2 100644 --- a/core/libs/prx/libc/src/Math.cpp +++ b/core/libs/prx/libc/src/Math.cpp @@ -344,6 +344,7 @@ long double APS5_VABI log1pl_nid_postfix(long double x) { return std::log1p(x); long double APS5_VABI log2l_nid_postfix(long double x) { return std::log2(x); } long double APS5_VABI lgammal_nid_postfix(long double x) { return std::lgamma(x); } long double APS5_VABI tgammal_nid_postfix(long double x) { return std::tgamma(x); } +float APS5_VABI tgammaf_nid_postfix(float x) { return std::tgamma(x); } long double APS5_VABI hypotl_nid_postfix(long double x, long double y) { if (std::isinf(x) || std::isinf(y)) return std::numeric_limits::infinity(); return std::hypot(x, y); diff --git a/core/libs/tests/GuestMath.cpp b/core/libs/tests/GuestMath.cpp index 176ac81a25..952710ffec 100644 --- a/core/libs/tests/GuestMath.cpp +++ b/core/libs/tests/GuestMath.cpp @@ -152,6 +152,7 @@ long double APS5_VABI log1pl_nid_postfix(long double); long double APS5_VABI log2l_nid_postfix(long double); long double APS5_VABI lgammal_nid_postfix(long double); long double APS5_VABI tgammal_nid_postfix(long double); +float APS5_VABI tgammaf_nid_postfix(float); long double APS5_VABI hypotl_nid_postfix(long double, long double); float APS5_VABI hypot3f_nid_postfix(float, float, float); double APS5_VABI hypot3_nid_postfix(double, double, double); @@ -861,6 +862,9 @@ static void CheckLongDoubleFunctions() { Require(log2l_nid_postfix(8.0L) == 3.0L && log2l_nid_postfix(0x1p-16445L) == -16445.0L); Require(lgammal_nid_postfix(1.0L) == 0.0L && lgammal_nid_postfix(2.0L) == 0.0L && lgammal_nid_postfix(0.0L) == infinity); Require(tgammal_nid_postfix(5.0L) == 24.0L && Near(tgammal_nid_postfix(0.5L), 1.7724538509055160272981675L)); + Require(tgammaf_nid_postfix(5.0f) == 24.0f && std::abs(tgammaf_nid_postfix(0.5f) - 1.77245385f) < 1e-6f); + Require(tgammaf_nid_postfix(1.0f) == 1.0f && tgammaf_nid_postfix(2.0f) == 1.0f && tgammaf_nid_postfix(3.0f) == 2.0f); + Require(std::isinf(tgammaf_nid_postfix(0.0f)) && std::isnan(tgammaf_nid_postfix(-1.0f))); Require(hypotl_nid_postfix(3.0L, -4.0L) == 5.0L && hypotl_nid_postfix(nan, -infinity) == infinity); Require(hypot3f_nid_postfix(3.0f, -4.0f, 12.0f) == 13.0f && hypot3f_nid_postfix(0.0f, 3.0f, -4.0f) == 5.0f); From 64fa4c277d48ae659f8731c6e35f7dbf23b34395 Mon Sep 17 00:00:00 2001 From: Nithishvelan M Date: Mon, 19 Oct 2026 23:05:15 +0530 Subject: [PATCH 2/2] fix(libc): compute tgammaf in double to match FreeBSD msun and avoid host float rounding --- core/libs/prx/libc/src/Math.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/libs/prx/libc/src/Math.cpp b/core/libs/prx/libc/src/Math.cpp index 8391b613f2..008700f589 100644 --- a/core/libs/prx/libc/src/Math.cpp +++ b/core/libs/prx/libc/src/Math.cpp @@ -344,7 +344,7 @@ long double APS5_VABI log1pl_nid_postfix(long double x) { return std::log1p(x); long double APS5_VABI log2l_nid_postfix(long double x) { return std::log2(x); } long double APS5_VABI lgammal_nid_postfix(long double x) { return std::lgamma(x); } long double APS5_VABI tgammal_nid_postfix(long double x) { return std::tgamma(x); } -float APS5_VABI tgammaf_nid_postfix(float x) { return std::tgamma(x); } +float APS5_VABI tgammaf_nid_postfix(float x) { return static_cast(std::tgamma(static_cast(x))); } long double APS5_VABI hypotl_nid_postfix(long double x, long double y) { if (std::isinf(x) || std::isinf(y)) return std::numeric_limits::infinity(); return std::hypot(x, y);