std::numeric_limits<T>::digits10
is the guaranteed number of digits in a sense that a number with that many digits can be represented in type T
without causing overflow or loss of information.
E.g. std::numeric_limits<int64_t>::digits10
cannot be 19 becuase 9'223'372'036'854'775'808
has 19 digits but is not representable in int64_t
.
In general case such guaranteed value of digits<N>
will always suffer from this "one less" discrepancy on platforms where digits<N>
is not a power of radix
used for internal representation. In non-exotic cases radix
is 2. Since 10 is not a power of 2, digits10
is smaller by 1 than the length of the max value.
If std::numeric_limits<T>
included digits16
or digits8
these values would've been "precise" for radix 2 platforms.