Commit 3764ca2b authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Format digits10

Summary: [Folly] Format `digits10`.

Reviewed By: Orvid

Differential Revision: D6636190

fbshipit-source-id: 6e6b834f6c9070d58f8e2b085b09df8b857fe878
parent 078d29f7
...@@ -326,7 +326,7 @@ inline uint32_t digits10(uint64_t v) { ...@@ -326,7 +326,7 @@ inline uint32_t digits10(uint64_t v) {
}; };
// "count leading zeroes" operation not valid; for 0; special case this. // "count leading zeroes" operation not valid; for 0; special case this.
if UNLIKELY (! v) { if (UNLIKELY(!v)) {
return 1; return 1;
} }
...@@ -341,16 +341,24 @@ inline uint32_t digits10(uint64_t v) { ...@@ -341,16 +341,24 @@ inline uint32_t digits10(uint64_t v) {
// return that log_10 lower bound, plus adjust if input >= 10^(that bound) // return that log_10 lower bound, plus adjust if input >= 10^(that bound)
// in case there's a small error and we misjudged length. // in case there's a small error and we misjudged length.
return minLength + (uint32_t) (UNLIKELY (v >= powersOf10[minLength])); return minLength + uint32_t(v >= powersOf10[minLength]);
#else #else
uint32_t result = 1; uint32_t result = 1;
for (;;) { while (true) {
if (LIKELY(v < 10)) return result; if (LIKELY(v < 10)) {
if (LIKELY(v < 100)) return result + 1; return result;
if (LIKELY(v < 1000)) return result + 2; }
if (LIKELY(v < 10000)) return result + 3; if (LIKELY(v < 100)) {
return result + 1;
}
if (LIKELY(v < 1000)) {
return result + 2;
}
if (LIKELY(v < 10000)) {
return result + 3;
}
// Skip ahead by 4 orders of magnitude // Skip ahead by 4 orders of magnitude
v /= 10000U; v /= 10000U;
result += 4; result += 4;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment