10 #if !defined(CNL_NUMERIC_H)
15 #include "_impl/num_traits/unwrap.h"
16 #include "_impl/used_digits.h"
25 namespace _numeric_impl {
26 template<
class Integer,
bool IsSigned>
27 struct trailing_bits {
28 [[nodiscard]] constexpr
auto operator()(Integer
const& n)
const noexcept
30 return countr_zero(n);
34 template<
class Integer>
35 struct trailing_bits<Integer, true> {
36 [[nodiscard]] constexpr
auto operator()(Integer
const& n)
const noexcept
38 using unsigned_type = numbers::set_signedness_t<Integer, false>;
39 return countr_zero(
static_cast<unsigned_type
>(n));
45 template<
class Integer>
46 [[nodiscard]] constexpr
auto trailing_bits(Integer
const& value)
48 return value ? _numeric_impl::trailing_bits<Integer, numbers::signedness_v<Integer>>()(value)
55 template<
typename Integer>
56 [[nodiscard]] constexpr
auto used_digits(
59 return _impl::used_digits_signed<numbers::signedness_v<Integer>>{}(unwrap(value), radix);
65 template<
class Integer>
66 [[nodiscard]] constexpr
auto leading_bits(Integer
const& value)
68 return digits_v<Integer> - cnl::used_digits(value);
72 #endif // CNL_NUMERIC_H