From 1e8336638609f1f75416d138877df6bf62ff22f4 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Fri, 27 Sep 2024 12:27:31 -0700 Subject: [PATCH] assert range on truncation --- fixed_wide/src/fixed.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fixed_wide/src/fixed.rs b/fixed_wide/src/fixed.rs index 14c8245..635b2e2 100644 --- a/fixed_wide/src/fixed.rs +++ b/fixed_wide/src/fixed.rs @@ -585,6 +585,9 @@ macro_rules! impl_fix_rhs_lt_lhs_not_const_generic{ paste::item!{ #[inline] pub fn [](self)->Fixed<$rhs,{$rhs*32}>{ + let max=bnum::cast::As::as_::>(BInt::<$rhs>::MAX).shl(($lhs-$rhs)*32); + let min=bnum::cast::As::as_::>(BInt::<$rhs>::MIN).shl(($lhs-$rhs)*32); + assert!(min>(self.bits.shr(($lhs-$rhs)*32))) } }