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