| 88 | |
| 89 | #ifdef FLATBUFFERS_PREFER_PRINTF |
| 90 | template<typename T> size_t IntToDigitCount(T t) { |
| 91 | size_t digit_count = 0; |
| 92 | // Count the sign for negative numbers |
| 93 | if (t < 0) digit_count++; |
| 94 | // Count a single 0 left of the dot for fractional numbers |
| 95 | if (-1 < t && t < 1) digit_count++; |
| 96 | // Count digits until fractional part |
| 97 | T eps = std::numeric_limits<float>::epsilon(); |
| 98 | while (t <= (-1 + eps) || (1 - eps) <= t) { |
| 99 | t /= 10; |
| 100 | digit_count++; |
| 101 | } |
| 102 | return digit_count; |
| 103 | } |
| 104 | |
| 105 | template<typename T> size_t NumToStringWidth(T t, int precision = 0) { |
| 106 | size_t string_width = IntToDigitCount(t); |