@@ -12,7 +12,6 @@ use core::ops::Neg;
1212
1313/// IEEE-like minifloat taking at most 8 bits
1414///
15- /// * `E`: exponent bit-width
1615/// * `M`: explicit significand (mantissa) bit-width
1716///
1817/// Constraints:
@@ -22,11 +21,11 @@ use core::ops::Neg;
2221///
2322/// Types generated by [`minifloat!`][crate::minifloat] implement this
2423/// trait.
25- pub trait Most8 < const E : u32 , const M : u32 > :
24+ pub trait Most8 < const M : u32 > :
2625 Sized + Copy + PartialEq + PartialOrd + Neg < Output = Self >
2726{
2827 /// Exponent bit-width
29- const E : u32 = E ;
28+ const E : u32 ;
3029
3130 /// Significand (mantissa) precision
3231 const M : u32 = M ;
@@ -38,24 +37,24 @@ pub trait Most8<const E: u32, const M: u32>:
3837 const N : NanStyle ;
3938
4039 /// Total bitwidth
41- const BITWIDTH : u32 = 1 + E + M ;
40+ const BITWIDTH : u32 = 1 + Self :: E + Self :: M ;
4241
4342 /// The radix of the internal representation
4443 const RADIX : u32 = 2 ;
4544
4645 /// The number of digits in the significand, including the implicit leading bit
4746 ///
4847 /// Equal to `M` + 1
49- const MANTISSA_DIGITS : u32 = M + 1 ;
48+ const MANTISSA_DIGITS : u32 = Self :: M + 1 ;
5049
5150 /// The maximum exponent
5251 ///
5352 /// Normal numbers < 1 × 2<sup>`MAX_EXP`</sup>.
54- const MAX_EXP : i32 = ( 1 << E )
53+ const MAX_EXP : i32 = ( 1 << Self :: E )
5554 - Self :: B
5655 - match Self :: N {
5756 NanStyle :: IEEE => 1 ,
58- NanStyle :: FN => ( M == 0 ) as i32 ,
57+ NanStyle :: FN => ( Self :: M == 0 ) as i32 ,
5958 NanStyle :: FNUZ => 0 ,
6059 } ;
6160
@@ -73,14 +72,14 @@ pub trait Most8<const E: u32, const M: u32>:
7372 ///
7473 /// Equal to floor([`M`][Self::M] log<sub>10</sub>(2))
7574 #[ allow( clippy:: cast_possible_truncation, clippy:: cast_sign_loss) ]
76- const DIGITS : u32 = ( M as f64 * crate :: LOG10_2 ) as u32 ;
75+ const DIGITS : u32 = ( Self :: M as f64 * crate :: LOG10_2 ) as u32 ;
7776
7877 /// Maximum <var>x</var> such that 10<sup>`x`</sup> is normal
7978 ///
8079 /// Equal to floor(log<sub>10</sub>([`MAX`][Self::MAX]))
8180 #[ allow( clippy:: cast_possible_truncation) ]
8281 const MAX_10_EXP : i32 = {
83- let exponent = ( 1 << E ) - Self :: B - matches ! ( Self :: N , NanStyle :: IEEE ) as i32 ;
82+ let exponent = ( 1 << Self :: E ) - Self :: B - matches ! ( Self :: N , NanStyle :: IEEE ) as i32 ;
8483 let precision = M + !matches ! ( Self :: N , NanStyle :: FN ) as u32 ;
8584 let log2_max = exponent as f64 + crate :: LOG2_SIGNIFICAND [ precision as usize ] ;
8685 ( log2_max * crate :: LOG10_2 ) as i32
@@ -126,7 +125,7 @@ pub trait Most8<const E: u32, const M: u32>:
126125 const MIN : Self ;
127126
128127 /// Magnitude mask for internal usage
129- const ABS_MASK : u8 = ( 1 << ( E + M ) ) - 1 ;
128+ const ABS_MASK : u8 = ( 1 << ( Self :: E + Self :: M ) ) - 1 ;
130129
131130 /// Raw transmutation from `u8`
132131 #[ must_use]
@@ -198,8 +197,8 @@ pub trait Most8<const E: u32, const M: u32>:
198197 } else if self . is_infinite ( ) {
199198 core:: num:: FpCategory :: Infinite
200199 } else {
201- let exp_mask = ( ( 1 << E ) - 1 ) << M ;
202- let man_mask = ( 1 << M ) - 1 ;
200+ let exp_mask = ( ( 1 << Self :: E ) - 1 ) << Self :: M ;
201+ let man_mask = ( 1 << Self :: M ) - 1 ;
203202
204203 match ( self . to_bits ( ) & exp_mask, self . to_bits ( ) & man_mask) {
205204 ( 0 , 0 ) => core:: num:: FpCategory :: Zero ,
@@ -221,13 +220,13 @@ pub trait Most8<const E: u32, const M: u32>:
221220 /// Check if the sign bit is clear
222221 #[ must_use]
223222 fn is_sign_positive ( self ) -> bool {
224- self . to_bits ( ) >> ( E + M ) & 1 == 0
223+ self . to_bits ( ) >> ( Self :: E + Self :: M ) & 1 == 0
225224 }
226225
227226 /// Check if the sign bit is set
228227 #[ must_use]
229228 fn is_sign_negative ( self ) -> bool {
230- self . to_bits ( ) >> ( E + M ) & 1 == 1
229+ self . to_bits ( ) >> ( Self :: E + Self :: M ) & 1 == 1
231230 }
232231
233232 /// Probably lossy conversion from [`f32`]
@@ -238,17 +237,17 @@ pub trait Most8<const E: u32, const M: u32>:
238237 #[ allow( clippy:: cast_possible_wrap) ]
239238 fn from_f32 ( x : f32 ) -> Self {
240239 if x. is_nan ( ) {
241- let sign_bit = u8:: from ( x. is_sign_negative ( ) ) << ( E + M ) ;
240+ let sign_bit = u8:: from ( x. is_sign_negative ( ) ) << ( Self :: E + Self :: M ) ;
242241 return Self :: from_bits ( Self :: NAN . to_bits ( ) | sign_bit) ;
243242 }
244243
245244 let bits = crate :: round_f32_to_precision :: < M > ( x) . to_bits ( ) ;
246- let sign_bit = ( ( bits >> 31 ) as u8 ) << ( E + M ) ;
247- let diff = ( Self :: MIN_EXP - f32:: MIN_EXP ) << M ;
248- let magnitude = bits << 1 >> ( f32:: MANTISSA_DIGITS - M ) ;
245+ let sign_bit = ( ( bits >> 31 ) as u8 ) << ( Self :: E + Self :: M ) ;
246+ let diff = ( Self :: MIN_EXP - f32:: MIN_EXP ) << Self :: M ;
247+ let magnitude = bits << 1 >> ( f32:: MANTISSA_DIGITS - Self :: M ) ;
249248 let magnitude = magnitude as i32 - diff;
250249
251- if magnitude < 1 << M {
250+ if magnitude < 1 << Self :: M {
252251 let ticks =
253252 f64:: from ( x. abs ( ) ) * crate :: exp2i ( Self :: MANTISSA_DIGITS as i32 - Self :: MIN_EXP ) ;
254253 #[ allow( clippy:: cast_possible_truncation, clippy:: cast_sign_loss) ]
@@ -270,17 +269,17 @@ pub trait Most8<const E: u32, const M: u32>:
270269 #[ allow( clippy:: cast_possible_wrap) ]
271270 fn from_f64 ( x : f64 ) -> Self {
272271 if x. is_nan ( ) {
273- let sign_bit = u8:: from ( x. is_sign_negative ( ) ) << ( E + M ) ;
272+ let sign_bit = u8:: from ( x. is_sign_negative ( ) ) << ( Self :: E + Self :: M ) ;
274273 return Self :: from_bits ( Self :: NAN . to_bits ( ) | sign_bit) ;
275274 }
276275
277276 let bits = crate :: round_f64_to_precision :: < M > ( x) . to_bits ( ) ;
278- let sign_bit = ( ( bits >> 63 ) as u8 ) << ( E + M ) ;
279- let diff = i64:: from ( Self :: MIN_EXP - f64:: MIN_EXP ) << M ;
280- let magnitude = bits << 1 >> ( f64:: MANTISSA_DIGITS - M ) ;
277+ let sign_bit = ( ( bits >> 63 ) as u8 ) << ( Self :: E + Self :: M ) ;
278+ let diff = i64:: from ( Self :: MIN_EXP - f64:: MIN_EXP ) << Self :: M ;
279+ let magnitude = bits << 1 >> ( f64:: MANTISSA_DIGITS - Self :: M ) ;
281280 let magnitude = magnitude as i64 - diff;
282281
283- if magnitude < 1 << M {
282+ if magnitude < 1 << Self :: M {
284283 let ticks = x. abs ( ) * crate :: exp2i ( Self :: MANTISSA_DIGITS as i32 - Self :: MIN_EXP ) ;
285284 #[ allow( clippy:: cast_possible_truncation, clippy:: cast_sign_loss) ]
286285 let ticks = ticks. round_ties_even ( ) as u8 ;
@@ -304,7 +303,7 @@ pub trait Most8<const E: u32, const M: u32>:
304303 if self . is_infinite ( ) {
305304 return f32:: INFINITY * sign;
306305 }
307- if magnitude < 1 << M {
306+ if magnitude < 1 << Self :: M {
308307 #[ allow( clippy:: cast_possible_wrap) ]
309308 let shift = Self :: MIN_EXP - Self :: MANTISSA_DIGITS as i32 ;
310309 #[ allow( clippy:: cast_possible_truncation) ]
0 commit comments