[libcxx-commits] [libcxx] [libc++] Fix numeric_limits::digits and digits10 for _BitInt(N) (PR #193002)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Apr 20 12:58:02 PDT 2026
================
@@ -184,9 +185,17 @@ protected:
static _LIBCPP_CONSTEXPR const bool is_specialized = true;
- static _LIBCPP_CONSTEXPR const bool is_signed = type(-1) < type(0);
- static _LIBCPP_CONSTEXPR const int digits = static_cast<int>(sizeof(type) * __CHAR_BIT__ - is_signed);
- static _LIBCPP_CONSTEXPR const int digits10 = digits * 3 / 10;
+ static _LIBCPP_CONSTEXPR const bool is_signed = type(-1) < type(0);
+ // For _BitInt(N), sizeof(type) * CHAR_BIT may exceed N due to padding
+ // bits. Count the actual value bits: ~make_unsigned_t<type>(0) leaves
+ // padding zero, so popcount yields the value-bit width. Standard
+ // integer types have no padding, so the result matches sizeof * CHAR_BIT.
----------------
philnik777 wrote:
I'm not sure how helpful this comment is. It's useful to understand this PR, but it's not necessarily helpful to mention the old implementation when just looking at new code.
Maybe just say that the current implementation works for `_BitInt` types as well?
https://github.com/llvm/llvm-project/pull/193002
More information about the libcxx-commits
mailing list