add an example to the new number function

This commit is contained in:
Corwin 2022-08-06 19:04:40 +01:00
parent 7ad160e30f
commit ff5a1fbbba

View file

@ -301,6 +301,16 @@ impl<I: FixedWidthUnsignedInteger, const N: usize> Num<I, N> {
/// Attempts to perform the conversion between two integer types and between /// Attempts to perform the conversion between two integer types and between
/// two different fractional precisions /// two different fractional precisions
/// ```
/// # use agb_fixnum::*;
/// let a: Num<i32, 8> = 1.into();
/// let b: Option<Num<u8, 4>> = a.try_change_base();
/// assert_eq!(b, Some(1.into()));
///
/// let a: Num<i32, 8> = 18.into();
/// let b: Option<Num<u8, 4>> = a.try_change_base();
/// assert_eq!(b, None);
/// ```
pub fn try_change_base<J: FixedWidthUnsignedInteger + TryFrom<I>, const M: usize>( pub fn try_change_base<J: FixedWidthUnsignedInteger + TryFrom<I>, const M: usize>(
self, self,
) -> Option<Num<J, M>> { ) -> Option<Num<J, M>> {