MCPcopy Create free account
hub / github.com/ObEngine/ObEngine / count_digits

Function count_digits

extlibs/fmt/include/fmt/format.h:787–792  ·  view source on GitHub ↗

Returns the number of decimal digits in n. Leading zeros are not counted except for n == 0 in which case count_digits returns 1.

Source from the content-addressed store, hash-verified

785// Returns the number of decimal digits in n. Leading zeros are not counted
786// except for n == 0 in which case count_digits returns 1.
787inline int count_digits(uint64_t n) {
788 // Based on http://graphics.stanford.edu/~seander/bithacks.html#IntegerLog10
789 // and the benchmark https://github.com/localvoid/cxx-benchmark-count-digits.
790 int t = (64 - FMT_BUILTIN_CLZLL(n | 1)) * 1233 >> 12;
791 return t - (n < data::zero_or_powers_of_10_64[t]) + 1;
792}
793#else
794// Fallback version of count_digits used when __builtin_clz is not available.
795inline int count_digits(uint64_t n) {

Callers 5

format-inl.hFile · 0.70
writeMethod · 0.70
write_decimalMethod · 0.70
on_decMethod · 0.70
on_numMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected