[libc-commits] [libc] [libc][math] Qualify fadd functions to constexpr (PR #194322)
via libc-commits
libc-commits at lists.llvm.org
Mon Apr 27 02:34:32 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Kiriti Ponduri (udaykiriti)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/194322.diff
5 Files Affected:
- (modified) libc/src/__support/math/fadd.h (+1-1)
- (modified) libc/src/__support/math/faddf128.h (+1-1)
- (modified) libc/src/__support/math/faddl.h (+1-1)
- (modified) libc/test/shared/CMakeLists.txt (+3)
- (modified) libc/test/shared/shared_math_constexpr_test.cpp (+4)
``````````diff
diff --git a/libc/src/__support/math/fadd.h b/libc/src/__support/math/fadd.h
index 0cc6209d3ee73..619ef93648c08 100644
--- a/libc/src/__support/math/fadd.h
+++ b/libc/src/__support/math/fadd.h
@@ -15,7 +15,7 @@
namespace LIBC_NAMESPACE_DECL {
namespace math {
-LIBC_INLINE float fadd(double x, double y) {
+LIBC_INLINE constexpr float fadd(double x, double y) {
return fputil::generic::add<float>(x, y);
}
diff --git a/libc/src/__support/math/faddf128.h b/libc/src/__support/math/faddf128.h
index 6e6051599668d..301412e39d6af 100644
--- a/libc/src/__support/math/faddf128.h
+++ b/libc/src/__support/math/faddf128.h
@@ -19,7 +19,7 @@
namespace LIBC_NAMESPACE_DECL {
namespace math {
-LIBC_INLINE float faddf128(float128 x, float128 y) {
+LIBC_INLINE constexpr float faddf128(float128 x, float128 y) {
return fputil::generic::add<float>(x, y);
}
diff --git a/libc/src/__support/math/faddl.h b/libc/src/__support/math/faddl.h
index 870938ce36138..8a4aacbc07f98 100644
--- a/libc/src/__support/math/faddl.h
+++ b/libc/src/__support/math/faddl.h
@@ -15,7 +15,7 @@
namespace LIBC_NAMESPACE_DECL {
namespace math {
-LIBC_INLINE float faddl(long double x, long double y) {
+LIBC_INLINE constexpr float faddl(long double x, long double y) {
return fputil::generic::add<float>(x, y);
}
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 8f324ae814f71..8f284a430377b 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -312,6 +312,9 @@ add_fp_unittest(
libc.src.__support.math.ddivl
libc.src.__support.math.dmulf128
libc.src.__support.math.dmull
+ libc.src.__support.math.fadd
+ libc.src.__support.math.faddf128
+ libc.src.__support.math.faddl
libc.src.__support.math.fdim
libc.src.__support.math.fdimbf16
libc.src.__support.math.fdimf
diff --git a/libc/test/shared/shared_math_constexpr_test.cpp b/libc/test/shared/shared_math_constexpr_test.cpp
index 2e995474e19be..72f4b1ddec0d2 100644
--- a/libc/test/shared/shared_math_constexpr_test.cpp
+++ b/libc/test/shared/shared_math_constexpr_test.cpp
@@ -31,6 +31,7 @@ static_assert(0.0 == LIBC_NAMESPACE::shared::log(1.0));
static_assert(0.0f == LIBC_NAMESPACE::shared::ceilf(0.0f));
static_assert(0.0f == LIBC_NAMESPACE::shared::copysignf(0.0f, 0.0f));
static_assert(1.0f == LIBC_NAMESPACE::shared::fabsf(-1.0f));
+static_assert(0.0f == LIBC_NAMESPACE::shared::fadd(0.0, 0.0));
static_assert(1.0f == LIBC_NAMESPACE::shared::fdimf(1.0f, 0.0f));
static_assert(2.0f == LIBC_NAMESPACE::shared::fmaximum_mag_numf(1.0f, 2.0f));
static_assert(0.0f == LIBC_NAMESPACE::shared::floorf(0.0f));
@@ -61,6 +62,7 @@ static_assert(0.0L == LIBC_NAMESPACE::shared::copysignl(0.0L, 0.0L));
static_assert(0.0 == LIBC_NAMESPACE::shared::ddivl(0.0L, 1.0L));
static_assert(0.0 == LIBC_NAMESPACE::shared::dmull(0.0L, 1.0L));
static_assert(1.0L == LIBC_NAMESPACE::shared::fabsl(-1.0L));
+static_assert(0.0f == LIBC_NAMESPACE::shared::faddl(0.0L, 0.0L));
static_assert(1.0L == LIBC_NAMESPACE::shared::fdiml(1.0L, 0.0L));
static_assert(0.0f == LIBC_NAMESPACE::shared::fdivl(0.0L, 1.0L));
static_assert(0.0L == LIBC_NAMESPACE::shared::floorl(0.0L));
@@ -83,6 +85,8 @@ static_assert(0.0 ==
LIBC_NAMESPACE::shared::ddivf128(float128(0.0), float128(1.0)));
static_assert(0.0 ==
LIBC_NAMESPACE::shared::dmulf128(float128(0.0), float128(1.0)));
+static_assert(0.0f ==
+ LIBC_NAMESPACE::shared::faddf128(float128(0.0), float128(0.0)));
static_assert(float128(1.0) ==
LIBC_NAMESPACE::shared::fdimf128(float128(1.0), float128(0.0)));
static_assert(0.0f ==
``````````
</details>
https://github.com/llvm/llvm-project/pull/194322
More information about the libc-commits
mailing list