[libc-commits] [libc] [libc][math] Qualify floor functions to constexpr (PR #192791)
via libc-commits
libc-commits at lists.llvm.org
Sat Apr 18 09:19:52 PDT 2026
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff origin/main HEAD --extensions h,cpp -- libc/src/__support/math/floor.h libc/src/__support/math/floorbf16.h libc/src/__support/math/floorf.h libc/src/__support/math/floorf128.h libc/src/__support/math/floorf16.h libc/test/shared/shared_math_constexpr_test.cpp --diff_from_common_commit
``````````
:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/libc/src/__support/math/floor.h b/libc/src/__support/math/floor.h
index 52603f6e0..01177b070 100644
--- a/libc/src/__support/math/floor.h
+++ b/libc/src/__support/math/floor.h
@@ -16,7 +16,7 @@ namespace LIBC_NAMESPACE_DECL {
namespace math {
LIBC_INLINE LIBC_CONSTEXPR double floor(double x) {
-#if defined(__LIBC_USE_BUILTIN_CEIL_FLOOR_RINT_TRUNC) && \
+#if defined(__LIBC_USE_BUILTIN_CEIL_FLOOR_RINT_TRUNC) && \
!defined(LIBC_HAS_CONSTANT_EVALUATION)
return __builtin_floor(x);
#else
diff --git a/libc/src/__support/math/floorbf16.h b/libc/src/__support/math/floorbf16.h
index a69389722..7e4373c2c 100644
--- a/libc/src/__support/math/floorbf16.h
+++ b/libc/src/__support/math/floorbf16.h
@@ -16,7 +16,9 @@
namespace LIBC_NAMESPACE_DECL {
namespace math {
-LIBC_INLINE constexpr bfloat16 floorbf16(bfloat16 x) { return fputil::floor(x); }
+LIBC_INLINE constexpr bfloat16 floorbf16(bfloat16 x) {
+ return fputil::floor(x);
+}
} // namespace math
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/__support/math/floorf.h b/libc/src/__support/math/floorf.h
index 82ff9ad51..10e298b8c 100644
--- a/libc/src/__support/math/floorf.h
+++ b/libc/src/__support/math/floorf.h
@@ -16,7 +16,7 @@ namespace LIBC_NAMESPACE_DECL {
namespace math {
LIBC_INLINE LIBC_CONSTEXPR float floorf(float x) {
-#if defined(__LIBC_USE_BUILTIN_CEIL_FLOOR_RINT_TRUNC) && \
+#if defined(__LIBC_USE_BUILTIN_CEIL_FLOOR_RINT_TRUNC) && \
!defined(LIBC_HAS_CONSTANT_EVALUATION)
return __builtin_floorf(x);
#else
diff --git a/libc/src/__support/math/floorf128.h b/libc/src/__support/math/floorf128.h
index 06b264d93..85f92ee77 100644
--- a/libc/src/__support/math/floorf128.h
+++ b/libc/src/__support/math/floorf128.h
@@ -19,7 +19,9 @@
namespace LIBC_NAMESPACE_DECL {
namespace math {
-LIBC_INLINE constexpr float128 floorf128(float128 x) { return fputil::floor(x); }
+LIBC_INLINE constexpr float128 floorf128(float128 x) {
+ return fputil::floor(x);
+}
} // namespace math
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/shared_math_constexpr_test.cpp b/libc/test/shared/shared_math_constexpr_test.cpp
index c59b2fee0..f2f0ce82c 100644
--- a/libc/test/shared/shared_math_constexpr_test.cpp
+++ b/libc/test/shared/shared_math_constexpr_test.cpp
@@ -40,7 +40,6 @@ static_assert(2.0f == LIBC_NAMESPACE::shared::floorf(2.9f));
static_assert(0.0f16 == LIBC_NAMESPACE::shared::ceilf16(0.0f16));
static_assert(0.0f16 == LIBC_NAMESPACE::shared::copysignf16(0.0f16, 0.0f16));
-
static_assert(3.0f16 == LIBC_NAMESPACE::shared::floorf16(3.7f16));
#endif // LIBC_TYPES_HAS_FLOAT16
``````````
</details>
https://github.com/llvm/llvm-project/pull/192791
More information about the libc-commits
mailing list