diff --git a/src/lib.rs b/src/lib.rs index 0f76f9e..f860a9b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -43,6 +43,7 @@ macro_rules! define_unsigned { impl $name { pub const MAX: Self = $name(((1 as $type) << $bits) -1 ); pub const MIN: Self = $name(0); + pub const BITS: u32 = $bits; fn mask(self) -> Self { $name(self.0 & ( ((1 as $type) << $bits).overflowing_sub(1).0)) @@ -67,6 +68,7 @@ macro_rules! define_signed { impl $name { pub const MAX: Self = $name(((1 as $type) << ($bits - 1)) - 1); pub const MIN: Self = $name(-((1 as $type) << ($bits - 1))); + pub const BITS: u32 = $bits; fn mask(self) -> Self { if ( self.0 & (1<<($bits-1)) ) == 0 { @@ -735,6 +737,13 @@ mod tests { assert_eq!(i9::MIN, i9(-256)); } + #[test] + fn test_bits_values() { + assert_eq!(u1::BITS, 1); + assert_eq!(i7::BITS, 7); + assert_eq!(u127::BITS, 127); + } + #[test] fn test_wrapping_add() { assert_eq!(u1::MAX.wrapping_add(u1(1)), u1(0));