pub trait NumDigits {
// Required methods
fn cross_sum(&self) -> Self;
fn digits(&self) -> Vec<u8>;
}
Expand description
Trait for the Digits of a given number.
Calculates the cross sum of a number.
A Self
.
use lib_rapid::math::general::NumDigits;
assert_eq!(3u8, 12.cross_sum());
assert_eq!(9u16, 342.cross_sum());
assert_eq!(52u64, 4928947234u64.cross_sum());
Gets the digits as a number with the 1s place at index 0.
A Vec<u8>
.
use lib_rapid::math::general::NumDigits;
assert_eq!(vec![4,3,2,1], 1234u16.digits());
assert_eq!(vec![0], 0u8.digits());