1 //! Type trait for the mantissa of an extended float. 2 3 use crate::util::*; 4 5 /// Type trait for the mantissa type. 6 pub trait Mantissa: UnsignedInteger { 7 /// Mask for the left-most bit, to check if the value is normalized. 8 const NORMALIZED_MASK: Self; 9 /// Mask to extract the high bits from the integer. 10 const HIMASK: Self; 11 /// Mask to extract the low bits from the integer. 12 const LOMASK: Self; 13 /// Full size of the integer, in bits. 14 const FULL: i32 = Self::BITS as i32; 15 /// Half size of the integer, in bits. 16 const HALF: i32 = Self::FULL / 2; 17 } 18 19 impl Mantissa for u8 { 20 const NORMALIZED_MASK: u8 = 0x80; 21 const HIMASK: u8 = 0xF0; 22 const LOMASK: u8 = 0x0F; 23 } 24 25 impl Mantissa for u16 { 26 const NORMALIZED_MASK: u16 = 0x8000; 27 const HIMASK: u16 = 0xFF00; 28 const LOMASK: u16 = 0x00FF; 29 } 30 31 impl Mantissa for u32 { 32 const NORMALIZED_MASK: u32 = 0x80000000; 33 const HIMASK: u32 = 0xFFFF0000; 34 const LOMASK: u32 = 0x0000FFFF; 35 } 36 37 impl Mantissa for u64 { 38 const NORMALIZED_MASK: u64 = 0x8000000000000000; 39 const HIMASK: u64 = 0xFFFFFFFF00000000; 40 const LOMASK: u64 = 0x00000000FFFFFFFF; 41 } 42 43 impl Mantissa for u128 { 44 const NORMALIZED_MASK: u128 = 0x80000000000000000000000000000000; 45 const HIMASK: u128 = 0xFFFFFFFFFFFFFFFF0000000000000000; 46 const LOMASK: u128 = 0x0000000000000000FFFFFFFFFFFFFFFF; 47 } 48