count-digits
A no_std trait to count the digits of integer types in various number bases.
Compatible with all primitive integer types and all non-zero integer types.
Examples
use CountDigits;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
[!NOTE] The base-10 functions count_digits() and count_digits_radix(10) do not include the negative sign in their counts.
assert_eq!;
assert_eq!;
[!NOTE] Negative numbers counted in base-10 are counted differently than negative numbers counted in other number bases.
Since negative numbers represented in base-10 are displayed with a negative sign, the base-10 digit count of a positive number will be equal to the base-10 digit count of the number's negated value, assuming no wrapping occurred.
assert_eq!;
However, the digit counts of negative numbers represented in other bases reflect the twos-complement representation, and the digit count of a positive number will not be the same as the count of its negated value.
assert_ne!;
assert_ne!;
assert_ne!;
for radix in 2..=16
This behavior is consistent with Rust's display format.
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
Benchmarks
License: MIT