maths: prefer int for `digits' types
This commit is contained in:
parent
32f3240186
commit
a36991fc83
@ -60,7 +60,7 @@ namespace util::format::detail {
|
||||
//
|
||||
// other values are theoretically supportable, but do not form part of
|
||||
// the printf specification.
|
||||
unsigned base = 10;
|
||||
int base = 10;
|
||||
|
||||
enum class repr {
|
||||
FIXED,
|
||||
@ -81,7 +81,7 @@ namespace util::format::detail {
|
||||
OSTREAM
|
||||
} k;
|
||||
|
||||
unsigned width = 0; // field width, ie: how many characters
|
||||
int width = 0; // field width, ie: how many characters
|
||||
int precision = -1; // how many digits after the decimal
|
||||
|
||||
size_t length = 0; // bytesize of underlying type
|
||||
@ -619,7 +619,7 @@ namespace util::format::detail {
|
||||
|
||||
const auto len = spec.precision < 0 ? spec.precision :
|
||||
(size_t)spec.precision < strlen (t) ? spec.precision :
|
||||
strlen (t);
|
||||
(int)strlen (t);
|
||||
|
||||
// perform left padding
|
||||
if (spec.width > len && !spec.left_adjusted)
|
||||
|
@ -347,15 +347,17 @@ namespace util {
|
||||
template <typename ValueT, typename BaseT>
|
||||
constexpr
|
||||
std::enable_if_t<
|
||||
std::is_integral<ValueT>::value && std::is_unsigned<BaseT>::value,
|
||||
unsigned
|
||||
std::is_integral_v<ValueT> && std::is_integral_v<BaseT>,
|
||||
int
|
||||
>
|
||||
digits (ValueT value, BaseT base) noexcept
|
||||
{
|
||||
assert (base > 0);
|
||||
|
||||
if (value < 0)
|
||||
value *= -1;
|
||||
|
||||
unsigned tally = 1;
|
||||
int tally = 1;
|
||||
while (value /= base)
|
||||
++tally;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user