pub fn cmp_int<T: Integer>(lhs: T, rhs: T, radix: u32) -> Ordering
Expand description
Lexicographically compares the digits of two integers.
While being able to compare numbers in arbitrary radix, this is not optimized very well.
You should use cmp_dec
for comparing in decimal representation or
fmt_cmp::cmp
for comparing in hexadecimal representation ((&format_args!("{:X}", lhs), &format_args!("{:X}", rhs))
"{:o}"
for octal) instead.
When radix == 1
, this will compare digits in the unary system, i.e., will return the same
result as lhs.cmp(&rhs)
.
When radix > 36
, this will compare digits in a theoretical base-radix
system, in which
the radix
-th digit compares greater than the (radix-1)
-th digit.
§Panics
Panics if radix == 0
.
§Example
assert!(fmt_cmp::cmp_int::<u32>(42, 3, 10).is_gt());
assert!(fmt_cmp::cmp_int::<u32>(24, 3, 10).is_lt());
assert!(fmt_cmp::cmp_int::<u32>(0x2a, 0x9, 16).is_lt());
assert!(fmt_cmp::cmp_int::<u32>(0xa2, 0x9, 16).is_gt());