MCPcopy Create free account
hub / github.com/fmtlib/fmt / count_digits_fallback

Function count_digits_fallback

include/fmt/format.h:1050–1063  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1048}
1049
1050template <typename T> FMT_CONSTEXPR auto count_digits_fallback(T n) -> int {
1051 int count = 1;
1052 for (;;) {
1053 // Integer division is slow so do it for a group of four digits instead
1054 // of for every digit. The idea comes from the talk by Alexandrescu
1055 // "Three Optimization Tips for C++". See speed-test for a comparison.
1056 if (n < 10) return count;
1057 if (n < 100) return count + 1;
1058 if (n < 1000) return count + 2;
1059 if (n < 10000) return count + 3;
1060 n /= 10000u;
1061 count += 4;
1062 }
1063}
1064#if FMT_USE_INT128
1065FMT_CONSTEXPR inline auto count_digits(native_uint128 n) -> int {
1066 return count_digits_fallback(n);

Callers 1

count_digitsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected