[libc-commits] [libc] [libc][math] Refactor sqrti to header-only (PR #177960)
via libc-commits
libc-commits at lists.llvm.org
Sat Jan 31 12:23:04 PST 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 -- libc/shared/math/sqrti.h libc/src/__support/math/sqrti.h libc/shared/math.h --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/sqrti.h b/libc/src/__support/math/sqrti.h
index e8534febe..f98dcd58a 100644
--- a/libc/src/__support/math/sqrti.h
+++ b/libc/src/__support/math/sqrti.h
@@ -19,7 +19,8 @@ namespace LIBC_NAMESPACE_DECL {
namespace math {
template <typename T>
-LIBC_INLINE static constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, T> sqrti(T n) {
+LIBC_INLINE static constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, T>
+sqrti(T n) {
if (n == 0)
return 0;
@@ -30,7 +31,7 @@ LIBC_INLINE static constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, T> sqrti(T
int lz = cpp::countl_zero(n);
int log2_n = bits - 1 - lz;
int shift = (log2_n / 2) + 1;
-
+
// 'x' is guaranteed to be >= sqrt(n).
// This satisfies the condition for Newton-Raphson to converge monotonically.
T x = T(1) << shift;
``````````
</details>
https://github.com/llvm/llvm-project/pull/177960
More information about the libc-commits
mailing list