|
76 | 76 | Self(Self::sign_extend(bits)) |
77 | 77 | } |
78 | 78 |
|
79 | | - /// As [`Self::from_bits`], but if `bits` is not a result of a [`Self::to_bits`] call, then |
80 | | - /// calling this function is undefined behaviour. |
| 79 | + /// As [`Self::from_bits`], but does not check that `bits` is a valid bit pattern for `Self`. |
| 80 | + /// |
| 81 | + /// # Safety |
| 82 | + /// |
| 83 | + /// `bits` has to be a result of a [`Self::to_bits`] call, i.e. it has to be in the range |
| 84 | + /// `-1 << (N-1) .. 1 << (N-1) - 1`, or calling this function is *undefined behaviour*. Note |
| 85 | + /// that if `Int::BITS == Self::BITS` this always holds. |
81 | 86 | pub const unsafe fn from_bits_unchecked(bits: Int) -> Self { |
82 | 87 | Self(bits) |
83 | 88 | } |
@@ -114,16 +119,19 @@ impl< |
114 | 119 | /// and so on. |
115 | 120 | pub(crate) const FRAC_DENOM: Int = const_as(1i128 << Self::FRAC_WIDTH); |
116 | 121 |
|
117 | | - /// The size of this Posit type in bits. |
118 | | - /// |
119 | | - /// Note: this is the logical size, not necessarily the size of the underlying type. |
| 122 | + /// As [`Posit::BITS`]. |
120 | 123 | pub const BITS: u32 = Posit::<N, ES, Int>::BITS; |
121 | 124 |
|
122 | | - /// The number of exponent bits. |
| 125 | + /// As [`Posit::ES`]. |
123 | 126 | pub const ES: u32 = Posit::<N, ES, Int>::ES; |
124 | 127 |
|
125 | | - /// Checks whether `self` is normalised, i.e. whether `self.frac` starts with `0b01` or `0b10`, |
126 | | - /// and `self.exp >> ES` starts with `0b00` or `0b11` (which is guaranteed if `ES > 0`). |
| 128 | + /// As [`Posit::JUNK_BITS`]. |
| 129 | + pub(crate) const JUNK_BITS: u32 = Posit::<N, ES, Int>::ES; |
| 130 | + |
| 131 | + /// Checks whether `self` is "normalised", i.e. whether |
| 132 | + /// |
| 133 | + /// - `self.frac` starts with `0b01` or `0b10`, and |
| 134 | + /// - `self.exp >> ES` starts with `0b00` or `0b11` (which is guaranteed if `ES > 0`). |
127 | 135 | pub(crate) fn is_normalised(self) -> bool { |
128 | 136 | let frac = self.frac >> Self::FRAC_WIDTH; |
129 | 137 | let exp = self.exp >> Self::FRAC_WIDTH; |
|
0 commit comments