mirror of
https://github.com/italicsjenga/agb.git
synced 2025-01-11 17:41:33 +11:00
Change base can change between convertable integer types too
This commit is contained in:
parent
cc70e5ba8b
commit
026dad0773
|
@ -75,13 +75,18 @@ pub struct Num<I: FixedWidthUnsignedInteger, const N: usize>(I);
|
||||||
|
|
||||||
pub type Number<const N: usize> = Num<i32, N>;
|
pub type Number<const N: usize> = Num<i32, N>;
|
||||||
|
|
||||||
pub fn change_base<I: FixedWidthUnsignedInteger, const N: usize, const M: usize>(
|
pub fn change_base<
|
||||||
num: Num<I, N>,
|
I: FixedWidthUnsignedInteger,
|
||||||
|
J: FixedWidthUnsignedInteger + Into<I>,
|
||||||
|
const N: usize,
|
||||||
|
const M: usize,
|
||||||
|
>(
|
||||||
|
num: Num<J, N>,
|
||||||
) -> Num<I, M> {
|
) -> Num<I, M> {
|
||||||
if N < M {
|
if N < M {
|
||||||
Num(num.0 << (M - N))
|
Num(num.0.into() << (M - N))
|
||||||
} else {
|
} else {
|
||||||
Num(num.0 >> (N - M))
|
Num(num.0.into() >> (N - M))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue