MCPcopy Create free account
hub / github.com/ablab/spades / count_digits

Function count_digits

ext/include/cppformat/format.h:517–522  ·  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

515// Returns the number of decimal digits in n. Leading zeros are not counted
516// except for n == 0 in which case count_digits returns 1.
517inline unsigned count_digits(uint64_t n) {
518 // Based on http://graphics.stanford.edu/~seander/bithacks.html#IntegerLog10
519 // and the benchmark https://github.com/localvoid/cxx-benchmark-count-digits.
520 unsigned t = (64 - __builtin_clzll(n | 1)) * 1233 >> 12;
521 return t - (n < POWERS_OF_10_64[t]) + 1;
522}
523# if FMT_GCC_VERSION >= 400 || FMT_HAS_BUILTIN(__builtin_clz)
524// Optional version of count_digits for better performance on 32-bit platforms.
525inline unsigned count_digits(uint32_t n) {

Callers 3

FMT_NOEXCEPTFunction · 0.85
write_intMethod · 0.85
format_decimalMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected