Compare commits

...

1 Commits

Author SHA1 Message Date
1e83366386 assert range on truncation 2024-09-27 12:27:31 -07:00

View File

@ -585,6 +585,9 @@ macro_rules! impl_fix_rhs_lt_lhs_not_const_generic{
paste::item!{
#[inline]
pub fn [<fix_ $rhs>](self)->Fixed<$rhs,{$rhs*32}>{
let max=bnum::cast::As::as_::<BInt::<$lhs>>(BInt::<$rhs>::MAX).shl(($lhs-$rhs)*32);
let min=bnum::cast::As::as_::<BInt::<$lhs>>(BInt::<$rhs>::MIN).shl(($lhs-$rhs)*32);
assert!(min<self.bits&&self.bits<max,"Truncation detected");
Fixed::from_bits(bnum::cast::As::as_::<BInt::<$rhs>>(self.bits.shr(($lhs-$rhs)*32)))
}
}