use super::*;
#[derive(Debug, Default, Clone, Copy)]
pub struct S<const N: usize>(U<N>);
impl<const N: usize> S<N> {
#[allow(clippy::identity_op)]
pub fn sext<const M: usize>(self) -> S<M>
where [(); N + M]: {
if M >= N {
let msb = self.0[N - 1];
let inner = self.0.append(msb.repeat::<M>());
S::from(inner.resize::<M>())
} else {
panic!("M should be larger than N")
}
}
pub fn resize<const M: usize>(self) -> S<M> {
S::from(U::from(self).resize())
}
pub fn signed_max() -> S<N>
where
[(); N - 1]:,
[(); (N - 1) + 1]:,
{
S::from(U::<N>::unsigned_max().clip_const::<{ N - 1 }>(0).append(U::<1>::from(0)).resize::<N>())
}
pub fn signed_min() -> S<N>
where
[(); N - 1]:,
[(); (N - 1) + 1]:,
{
S::from(U::<{ N - 1 }>::from(0).append(U::<1>::from(1)).resize::<N>())
}
}
impl<const N: usize> From<U<N>> for S<N> {
fn from(value: U<N>) -> S<N> {
S(value)
}
}
impl<const N: usize> From<S<N>> for U<N> {
fn from(value: S<N>) -> U<N> {
value.0
}
}