MCPcopy Create free account
hub / github.com/OpenFodder/openfodder / count_digits

Method count_digits

Source/Utils/json.hpp:16072–16096  ·  view source on GitHub ↗

! @brief count digits Count the number of decimal (base 10) digits for an input unsigned integer. @param[in] x unsigned integer number to count its digits @return number of decimal digits */

Source from the content-addressed store, hash-verified

16070 @return number of decimal digits
16071 */
16072 inline unsigned int count_digits(number_unsigned_t x) noexcept
16073 {
16074 unsigned int n_digits = 1;
16075 for (;;)
16076 {
16077 if (x < 10)
16078 {
16079 return n_digits;
16080 }
16081 if (x < 100)
16082 {
16083 return n_digits + 1;
16084 }
16085 if (x < 1000)
16086 {
16087 return n_digits + 2;
16088 }
16089 if (x < 10000)
16090 {
16091 return n_digits + 3;
16092 }
16093 x = x / 10000u;
16094 n_digits += 4;
16095 }
16096 }
16097
16098 /*!
16099 @brief dump an integer

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected