[libc-commits] [libc] 0d7ad3d - [libc][math] Qualify nextafter functions to constexpr (#195596)

via libc-commits libc-commits at lists.llvm.org
Mon May 4 00:00:05 PDT 2026


Author: Kiriti Ponduri
Date: 2026-05-04T10:00:01+03:00
New Revision: 0d7ad3d4aff4696f1830a765ca59463a760f2d23

URL: https://github.com/llvm/llvm-project/commit/0d7ad3d4aff4696f1830a765ca59463a760f2d23
DIFF: https://github.com/llvm/llvm-project/commit/0d7ad3d4aff4696f1830a765ca59463a760f2d23.diff

LOG: [libc][math] Qualify nextafter functions to constexpr (#195596)

Signed-off-by: udaykiriti <udaykiriti624 at gmail.com>

Added: 
    

Modified: 
    libc/src/__support/FPUtil/ManipulationFunctions.h
    libc/src/__support/math/nextafter.h
    libc/src/__support/math/nextafterbf16.h
    libc/src/__support/math/nextafterf.h
    libc/src/__support/math/nextafterf128.h
    libc/src/__support/math/nextafterf16.h
    libc/src/__support/math/nextafterl.h
    libc/test/shared/CMakeLists.txt
    libc/test/shared/shared_math_constexpr_test.cpp

Removed: 
    


################################################################################
diff  --git a/libc/src/__support/FPUtil/ManipulationFunctions.h b/libc/src/__support/FPUtil/ManipulationFunctions.h
index 1b8ee27273e5b..16dc094deda47 100644
--- a/libc/src/__support/FPUtil/ManipulationFunctions.h
+++ b/libc/src/__support/FPUtil/ManipulationFunctions.h
@@ -210,7 +210,7 @@ template <typename T, typename U,
                                cpp::is_floating_point_v<U> &&
                                (sizeof(T) <= sizeof(U)),
                            int> = 0>
-LIBC_INLINE T nextafter(T from, U to) {
+LIBC_INLINE constexpr T nextafter(T from, U to) {
   FPBits<T> from_bits(from);
   if (from_bits.is_nan())
     return from;

diff  --git a/libc/src/__support/math/nextafter.h b/libc/src/__support/math/nextafter.h
index beb2fc9da057c..625d5a7c68f61 100644
--- a/libc/src/__support/math/nextafter.h
+++ b/libc/src/__support/math/nextafter.h
@@ -16,7 +16,7 @@ namespace LIBC_NAMESPACE_DECL {
 
 namespace math {
 
-LIBC_INLINE double nextafter(double x, double y) {
+LIBC_INLINE constexpr double nextafter(double x, double y) {
   return fputil::nextafter(x, y);
 }
 

diff  --git a/libc/src/__support/math/nextafterbf16.h b/libc/src/__support/math/nextafterbf16.h
index 26679e2079045..b13a194d56fd8 100644
--- a/libc/src/__support/math/nextafterbf16.h
+++ b/libc/src/__support/math/nextafterbf16.h
@@ -17,7 +17,7 @@ namespace LIBC_NAMESPACE_DECL {
 
 namespace math {
 
-LIBC_INLINE bfloat16 nextafterbf16(bfloat16 x, bfloat16 y) {
+LIBC_INLINE constexpr bfloat16 nextafterbf16(bfloat16 x, bfloat16 y) {
   return fputil::nextafter(x, y);
 }
 

diff  --git a/libc/src/__support/math/nextafterf.h b/libc/src/__support/math/nextafterf.h
index 7d8a0f203879b..c6baa8a2012ab 100644
--- a/libc/src/__support/math/nextafterf.h
+++ b/libc/src/__support/math/nextafterf.h
@@ -16,7 +16,7 @@ namespace LIBC_NAMESPACE_DECL {
 
 namespace math {
 
-LIBC_INLINE float nextafterf(float x, float y) {
+LIBC_INLINE constexpr float nextafterf(float x, float y) {
   return fputil::nextafter(x, y);
 }
 

diff  --git a/libc/src/__support/math/nextafterf128.h b/libc/src/__support/math/nextafterf128.h
index b13b913c506fe..2f15bd41c0476 100644
--- a/libc/src/__support/math/nextafterf128.h
+++ b/libc/src/__support/math/nextafterf128.h
@@ -20,7 +20,7 @@ namespace LIBC_NAMESPACE_DECL {
 
 namespace math {
 
-LIBC_INLINE float128 nextafterf128(float128 x, float128 y) {
+LIBC_INLINE constexpr float128 nextafterf128(float128 x, float128 y) {
   return fputil::nextafter(x, y);
 }
 

diff  --git a/libc/src/__support/math/nextafterf16.h b/libc/src/__support/math/nextafterf16.h
index 631790b44cb73..edb91c3e3cbdb 100644
--- a/libc/src/__support/math/nextafterf16.h
+++ b/libc/src/__support/math/nextafterf16.h
@@ -20,7 +20,7 @@ namespace LIBC_NAMESPACE_DECL {
 
 namespace math {
 
-LIBC_INLINE float16 nextafterf16(float16 x, float16 y) {
+LIBC_INLINE constexpr float16 nextafterf16(float16 x, float16 y) {
   return fputil::nextafter(x, y);
 }
 

diff  --git a/libc/src/__support/math/nextafterl.h b/libc/src/__support/math/nextafterl.h
index cf2c2e6da5fb4..a173ccfaa4c73 100644
--- a/libc/src/__support/math/nextafterl.h
+++ b/libc/src/__support/math/nextafterl.h
@@ -16,7 +16,7 @@ namespace LIBC_NAMESPACE_DECL {
 
 namespace math {
 
-LIBC_INLINE long double nextafterl(long double x, long double y) {
+LIBC_INLINE constexpr long double nextafterl(long double x, long double y) {
   return fputil::nextafter(x, y);
 }
 

diff  --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 158918d9454c6..11135db2a92b9 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -684,6 +684,12 @@ add_fp_unittest(
     libc.src.__support.math.nearbyintf128
     libc.src.__support.math.nearbyintf16
     libc.src.__support.math.nearbyintl
+    libc.src.__support.math.nextafter
+    libc.src.__support.math.nextafterbf16
+    libc.src.__support.math.nextafterf
+    libc.src.__support.math.nextafterf16
+    libc.src.__support.math.nextafterl
+    libc.src.__support.math.nextafterf128
     libc.src.__support.math.remainder
     libc.src.__support.math.remainderbf16
     libc.src.__support.math.remainderf

diff  --git a/libc/test/shared/shared_math_constexpr_test.cpp b/libc/test/shared/shared_math_constexpr_test.cpp
index e99f8691451a3..9e24927b8ac22 100644
--- a/libc/test/shared/shared_math_constexpr_test.cpp
+++ b/libc/test/shared/shared_math_constexpr_test.cpp
@@ -75,6 +75,7 @@ static_assert(0LL == LIBC_NAMESPACE::shared::llround(0.0));
 static_assert(0L == LIBC_NAMESPACE::shared::lrint(0.0));
 static_assert(0L == LIBC_NAMESPACE::shared::lround(0.0));
 static_assert(0.0 == LIBC_NAMESPACE::shared::nearbyint(0.0));
+static_assert(0.0 == LIBC_NAMESPACE::shared::nextafter(0.0, 0.0));
 static_assert(0.0 == LIBC_NAMESPACE::shared::rint(0.0));
 static_assert(1 == LIBC_NAMESPACE::shared::iscanonical(0.0));
 static_assert(0.0 == LIBC_NAMESPACE::shared::issignaling(0.0));
@@ -145,6 +146,7 @@ static_assert(0LL == LIBC_NAMESPACE::shared::llroundf(0.0f));
 static_assert(0L == LIBC_NAMESPACE::shared::lrintf(0.0f));
 static_assert(0L == LIBC_NAMESPACE::shared::lroundf(0.0f));
 static_assert(0.0f == LIBC_NAMESPACE::shared::nearbyintf(0.0f));
+static_assert(0.0f == LIBC_NAMESPACE::shared::nextafterf(0.0f, 0.0f));
 static_assert(0.0f == LIBC_NAMESPACE::shared::rintf(0.0f));
 static_assert(1 == LIBC_NAMESPACE::shared::iscanonicalf(0.0f));
 static_assert(0.0 == LIBC_NAMESPACE::shared::issignalingf(0.0f));
@@ -233,6 +235,7 @@ static_assert(0LL == LIBC_NAMESPACE::shared::llroundf16(0.0f16));
 static_assert(0L == LIBC_NAMESPACE::shared::lrintf16(0.0f16));
 static_assert(0L == LIBC_NAMESPACE::shared::lroundf16(0.0f16));
 static_assert(0.0f16 == LIBC_NAMESPACE::shared::nearbyintf16(0.0f16));
+static_assert(0.0f16 == LIBC_NAMESPACE::shared::nextafterf16(0.0f16, 0.0f16));
 static_assert(0.0f16 == LIBC_NAMESPACE::shared::rintf16(0.0f16));
 static_assert(1 == LIBC_NAMESPACE::shared::iscanonicalf16(0.0f16));
 static_assert(0.0 == LIBC_NAMESPACE::shared::issignalingf16(0.0f16));
@@ -318,6 +321,7 @@ static_assert(0LL == LIBC_NAMESPACE::shared::llroundl(0.0L));
 static_assert(0L == LIBC_NAMESPACE::shared::lrintl(0.0L));
 static_assert(0L == LIBC_NAMESPACE::shared::lroundl(0.0L));
 static_assert(0.0L == LIBC_NAMESPACE::shared::nearbyintl(0.0L));
+static_assert(0.0L == LIBC_NAMESPACE::shared::nextafterl(0.0L, 0.0L));
 static_assert(0.0L == LIBC_NAMESPACE::shared::rintl(0.0L));
 static_assert(1 == LIBC_NAMESPACE::shared::iscanonicall(0.0L));
 static_assert(0.0 == LIBC_NAMESPACE::shared::issignalingl(0.0L));
@@ -436,6 +440,9 @@ static_assert(0L == LIBC_NAMESPACE::shared::lrintf128(float128(0.0)));
 static_assert(0L == LIBC_NAMESPACE::shared::lroundf128(float128(0.0)));
 static_assert(float128(0.0) ==
               LIBC_NAMESPACE::shared::nearbyintf128(float128(0.0)));
+static_assert(float128(0.0) ==
+              LIBC_NAMESPACE::shared::nextafterf128(float128(0.0),
+                                                    float128(0.0)));
 static_assert(float128(0.0) == LIBC_NAMESPACE::shared::rintf128(float128(0.0)));
 static_assert(1 == LIBC_NAMESPACE::shared::iscanonicalf128(float128(0.0)));
 static_assert(0.0 == LIBC_NAMESPACE::shared::issignalingf128(float128(0.0)));
@@ -552,6 +559,9 @@ static_assert(0L == LIBC_NAMESPACE::shared::lrintbf16(bfloat16(0.0)));
 static_assert(0L == LIBC_NAMESPACE::shared::lroundbf16(bfloat16(0.0)));
 static_assert(bfloat16(0.0) ==
               LIBC_NAMESPACE::shared::nearbyintbf16(bfloat16(0.0)));
+static_assert(bfloat16(0.0) ==
+              LIBC_NAMESPACE::shared::nextafterbf16(bfloat16(0.0),
+                                                    bfloat16(0.0)));
 static_assert(bfloat16(0.0) == LIBC_NAMESPACE::shared::rintbf16(bfloat16(0.0)));
 static_assert(1 == LIBC_NAMESPACE::shared::iscanonicalbf16(bfloat16(0.0)));
 static_assert(0 == LIBC_NAMESPACE::shared::issignalingbf16(bfloat16(0.0)));


        


More information about the libc-commits mailing list