Returns the number of decimal digits in n. Leading zeros are not counted except for n == 0 in which case count_digits returns 1.
| 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. |
| 517 | inline 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. |
| 525 | inline unsigned count_digits(uint32_t n) { |
no outgoing calls
no test coverage detected