Module malachite_base::num::conversion::digits::general_digits
source · Expand description
Digits
, a trait for extracting digits from numbers and constructing
numbers from digits.
§to_digits_asc
use malachite_base::num::conversion::traits::Digits;
assert_eq!(0u8.to_digits_asc(&6u64), &[]);
assert_eq!(2u16.to_digits_asc(&6u32), &[2]);
assert_eq!(
123456u32.to_digits_asc(&3u16),
&[0, 1, 1, 0, 0, 1, 1, 2, 0, 0, 2]
);
§to_digits_desc
use malachite_base::num::conversion::traits::Digits;
assert_eq!(0u8.to_digits_asc(&6u64), &[]);
assert_eq!(2u16.to_digits_asc(&6u32), &[2]);
assert_eq!(
123456u32.to_digits_desc(&3u16),
&[2, 0, 0, 2, 1, 1, 0, 0, 1, 1, 0]
);
§from_digits_asc
use malachite_base::num::conversion::traits::Digits;
assert_eq!(
u8::from_digits_asc(&64, [0u64, 0, 0].iter().cloned()),
Some(0)
);
assert_eq!(
u32::from_digits_asc(&3, [0u64, 1, 1, 0, 0, 1, 1, 2, 0, 0, 2].iter().cloned()),
Some(123456)
);
assert_eq!(
u32::from_digits_asc(&8, [3u16, 7, 1].iter().cloned()),
Some(123)
);
assert!(u64::from_digits_asc(&64, [1u8; 1000].iter().cloned()).is_none());
assert!(u64::from_digits_asc(&2, [2u8].iter().cloned()).is_none());
assert!(u8::from_digits_asc(&1000, [1u16, 2, 3].iter().cloned()).is_none());
§from_digits_desc
use malachite_base::num::conversion::traits::Digits;
assert_eq!(
u8::from_digits_desc(&64, [0u64, 0, 0].iter().cloned()),
Some(0)
);
assert_eq!(
u32::from_digits_desc(&3, [2u64, 0, 0, 2, 1, 1, 0, 0, 1, 1, 0].iter().cloned()),
Some(123456)
);
assert_eq!(
u32::from_digits_desc(&8, [1u16, 7, 3].iter().cloned()),
Some(123)
);
assert!(u64::from_digits_desc(&64, [1u8; 1000].iter().cloned()).is_none());
assert!(u64::from_digits_desc(&2, [2u8].iter().cloned()).is_none());
assert!(u8::from_digits_desc(&1000, [1u16, 2, 3].iter().cloned()).is_none());