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 && (sizeof(T) <= sizeof(U)), int> = 0> -LIBC_INLINE T nextafter(T from, U to) { +LIBC_INLINE constexpr T nextafter(T from, U to) { FPBits 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 f632843d31284..71e732a156e77 100644 --- a/libc/test/shared/CMakeLists.txt +++ b/libc/test/shared/CMakeLists.txt @@ -648,6 +648,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 964c1f9e97f3a..aa1bdd954d321 100644 --- a/libc/test/shared/shared_math_constexpr_test.cpp +++ b/libc/test/shared/shared_math_constexpr_test.cpp @@ -71,6 +71,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)); //===----------------------------------------------------------------------===// @@ -129,6 +130,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)); //===----------------------------------------------------------------------===// @@ -205,6 +207,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)); #endif // LIBC_TYPES_HAS_FLOAT16 @@ -278,6 +281,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)); #endif @@ -386,6 +390,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))); #endif // LIBC_TYPES_HAS_FLOAT128 @@ -490,6 +497,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))); TEST(LlvmLibcSharedMathTest, ConstantEvaluation) {}