49template <
typename Number>
55 return std::numeric_limits<Number>::digits10;
66template <
typename Number>
68 -> enable_if_t<not std::is_floating_point<Number>::value
69 and std::is_signed<Number>::value,
71 if (val == 0 or val == 1) {
74 return static_cast<int>(std::ceil(
75 std::nextafter(std::log10(std::fabs(val)), INFINITY)))
86template <
typename Number>
88 -> enable_if_t<std::is_unsigned<Number>::value,
int> {
91 }
else if (val ==
static_cast<Number
>(-1)) {
92 return static_cast<int>(std::ceil(std::log10(val)));
94 return static_cast<int>(std::ceil(std::log10(val + 1)));
106template <
typename Number>
110 }
else if (std::is_floating_point<Number>::value) {
111 return static_cast<int>(
112 std::ceil(std::numeric_limits<Number>::digits * std::logb(base)));
114 return static_cast<int>(
115 std::ceil(std::log(std::abs(val) + 1) / std::log(base)))
129template <
typename ForwardIt>
147template <
typename ForwardIt>
This header provides some features of C++17 <type_traits> and other headers for C++14,...
The main namespace in which all entities from kblib are defined.
typename std::enable_if< B, T >::type enable_if_t
auto max_count_digits(ForwardIt first, ForwardIt last) -> int
Returns the necessary number of digits to represent the largest value in an input range.
constexpr auto max_element(ForwardIt first, EndIt last, Compare comp={}) -> ForwardIt
constexpr auto count_digits(Number val) -> enable_if_t< std::is_floating_point< Number >::value, int >
Calculates the number of decimal digits needed to represent a number, plus one for negative numbers.