From f1810c89ea6391c775d9cdf5c612e53dcb870d57 Mon Sep 17 00:00:00 2001 From: Nixitov Date: Mon, 12 Oct 2026 17:29:41 +0200 Subject: [PATCH] feat(libc): implement nearbyintl OutRun2006 (PPSA99106) imports nearbyintl and stops at start-up on main. Add the long double round-to-nearest-integer export next to nearbyintf; std::nearbyint rounds under the current direction and raises no inexact exception. --- core/libs/prx/libc/src/Math.cpp | 1 + core/libs/tests/GuestMath.cpp | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/core/libs/prx/libc/src/Math.cpp b/core/libs/prx/libc/src/Math.cpp index 9ecf79e14..619b6429d 100644 --- a/core/libs/prx/libc/src/Math.cpp +++ b/core/libs/prx/libc/src/Math.cpp @@ -181,6 +181,7 @@ int APS5_VABI __isnormal_nid_postfix(double x) { return std::isnormal(x) ? 1 : 0 int APS5_VABI __isnormalf_nid_postfix(float x) { return std::isnormal(x) ? 1 : 0; } int APS5_VABI __isinff_nid_postfix(float x) { return std::isinf(x) ? 1 : 0; } float APS5_VABI nearbyintf_nid_postfix(float x) { return std::nearbyintf(x); } +long double APS5_VABI nearbyintl_nid_postfix(long double x) { return std::nearbyint(x); } double APS5_VABI cbrt_nid_postfix(double x) { return std::cbrt(x); } double APS5_VABI asin_nid_postfix(double x) { diff --git a/core/libs/tests/GuestMath.cpp b/core/libs/tests/GuestMath.cpp index 5a8e85f5f..883c63507 100644 --- a/core/libs/tests/GuestMath.cpp +++ b/core/libs/tests/GuestMath.cpp @@ -106,6 +106,7 @@ long double APS5_VABI log10l_nid_postfix(long double); long double APS5_VABI powl_nid_postfix(long double, long double); long double APS5_VABI ldexpl_nid_postfix(long double, int); long double APS5_VABI truncl_nid_postfix(long double); +long double APS5_VABI nearbyintl_nid_postfix(long double); double APS5_VABI logb_nid_postfix(double); double APS5_VABI remainder_nid_postfix(double, double); } @@ -192,6 +193,19 @@ static void CheckLongDouble() { Require(std::isnan(frexpl_nid_postfix(NAN, &exponent)) && exponent == 77); } +static void CheckNearbyintl() { + std::feclearexcept(FE_ALL_EXCEPT); + const long double zero = nearbyintl_nid_postfix(0.5L); + Require(zero == 0.0L && !std::signbit(zero)); + Require(nearbyintl_nid_postfix(1.5L) == 2.0L && nearbyintl_nid_postfix(2.5L) == 2.0L); + Require(nearbyintl_nid_postfix(2.7L) == 3.0L && nearbyintl_nid_postfix(-2.7L) == -3.0L); + Require(ExtendedBits(nearbyintl_nid_postfix(-0.5L), 0, 0x8000)); + Require(nearbyintl_nid_postfix(0x1p200L) == 0x1p200L); + Require(nearbyintl_nid_postfix(INFINITY) == INFINITY && nearbyintl_nid_postfix(-INFINITY) == -INFINITY); + Require(std::isnan(nearbyintl_nid_postfix(NAN))); + Require(std::fetestexcept(FE_INEXACT) == 0); +} + static void CheckFmodErrno() { errno = 0; (void)fmod_nid_postfix(1.0, 0.0); @@ -674,6 +688,7 @@ int main() { CheckExp2Errno(); CheckExactOperations(); CheckLongDouble(); + CheckNearbyintl(); CheckAsinl(); Require(scalbn_nid_postfix(0.75, -2) == 0.1875); Require(scalbnf_nid_postfix(0.75f, 4) == 12.f);