[libcxx-commits] [libcxx] [libc++] Fix numeric_limits::digits and digits10 for _BitInt(N) (PR #193002)

via libcxx-commits libcxx-commits at lists.llvm.org
Mon Apr 20 08:36:17 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 ,cpp -- libcxx/include/limits libcxx/test/std/language.support/support.limits/limits/numeric.limits.members/digits.pass.cpp libcxx/test/std/language.support/support.limits/limits/numeric.limits.members/digits10.pass.cpp libcxx/test/std/language.support/support.limits/limits/numeric.limits.members/max.pass.cpp libcxx/test/std/language.support/support.limits/limits/numeric.limits.members/min.pass.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/libcxx/include/limits b/libcxx/include/limits
index 923f8a986..b2b850eda 100644
--- a/libcxx/include/limits
+++ b/libcxx/include/limits
@@ -182,7 +182,7 @@ protected:
 // due to padding bits; __builtin_popcountg of ~unsigned_type(0) returns the
 // actual value width (padding bits stay zero on bitwise NOT). Standard types
 // have no padding, so the result matches sizeof * CHAR_BIT.
-#if __has_builtin(__builtin_popcountg) && __has_builtin(__make_unsigned)
+#  if __has_builtin(__builtin_popcountg) && __has_builtin(__make_unsigned)
 template <class _Tp, bool _IsSigned = (_Tp(-1) < _Tp(0))>
 struct __numeric_limits_unsigned_type {
   using type = _Tp;
@@ -191,7 +191,7 @@ template <class _Tp>
 struct __numeric_limits_unsigned_type<_Tp, true> {
   using type = __make_unsigned(_Tp);
 };
-#endif
+#  endif
 
 template <class _Tp>
 class __libcpp_numeric_limits<_Tp, true> {
@@ -201,12 +201,13 @@ protected:
   static _LIBCPP_CONSTEXPR const bool is_specialized = true;
 
   static _LIBCPP_CONSTEXPR const bool is_signed = type(-1) < type(0);
-#if __has_builtin(__builtin_popcountg) && __has_builtin(__make_unsigned)
-  using __unsigned_type                     = typename __numeric_limits_unsigned_type<type>::type;
-  static _LIBCPP_CONSTEXPR const int digits = __builtin_popcountg(static_cast<__unsigned_type>(~__unsigned_type(0))) - is_signed;
-#else
+#  if __has_builtin(__builtin_popcountg) && __has_builtin(__make_unsigned)
+  using __unsigned_type = typename __numeric_limits_unsigned_type<type>::type;
+  static _LIBCPP_CONSTEXPR const int digits =
+      __builtin_popcountg(static_cast<__unsigned_type>(~__unsigned_type(0))) - is_signed;
+#  else
   static _LIBCPP_CONSTEXPR const int digits = static_cast<int>(sizeof(type) * __CHAR_BIT__ - is_signed);
-#endif
+#  endif
   // digits10 = floor(digits * log10(2)); 643/2136 is exact for digits up to
   // __BITINT_MAXWIDTH__ (8388608 on x86). The old digits*3/10 was wrong for
   // digits >= 256 (gave 76 instead of 77).

``````````

</details>


https://github.com/llvm/llvm-project/pull/193002


More information about the libcxx-commits mailing list