@@ -48,11 +48,14 @@ pub trait Float:
4848 /// The bitwidth of the exponent
4949 const EXP_BITS : u32 = Self :: BITS - Self :: SIG_BITS - 1 ;
5050
51- /// The saturated value of the exponent (infinite representation), in the rightmost postiion.
52- const EXP_MAX : u32 = ( 1 << Self :: EXP_BITS ) - 1 ;
51+ /// The saturated (maximum bitpattern) value of the exponent, i.e. the infinite
52+ /// representation.
53+ ///
54+ /// This shifted fully right, use `EXP_MASK` for the shifted value.
55+ const EXP_SAT : u32 = ( 1 << Self :: EXP_BITS ) - 1 ;
5356
5457 /// The exponent bias value
55- const EXP_BIAS : u32 = Self :: EXP_MAX >> 1 ;
58+ const EXP_BIAS : u32 = Self :: EXP_SAT >> 1 ;
5659
5760 /// A mask for the sign bit
5861 const SIGN_MASK : Self :: Int ;
@@ -109,7 +112,7 @@ pub trait Float:
109112
110113 /// Returns the exponent, not adjusting for bias, not accounting for subnormals or zero.
111114 fn exp ( self ) -> u32 {
112- u32:: cast_from ( self . to_bits ( ) >> Self :: SIG_BITS ) & Self :: EXP_MAX
115+ u32:: cast_from ( self . to_bits ( ) >> Self :: SIG_BITS ) & Self :: EXP_SAT
113116 }
114117
115118 /// Extract the exponent and adjust it for bias, not accounting for subnormals or zero.
@@ -135,7 +138,7 @@ pub trait Float:
135138 let sign = if negative { Self :: Int :: ONE } else { Self :: Int :: ZERO } ;
136139 Self :: from_bits (
137140 ( sign << ( Self :: BITS - 1 ) )
138- | ( Self :: Int :: cast_from ( exponent & Self :: EXP_MAX ) << Self :: SIG_BITS )
141+ | ( Self :: Int :: cast_from ( exponent & Self :: EXP_SAT ) << Self :: SIG_BITS )
139142 | ( significand & Self :: SIG_MASK ) ,
140143 )
141144 }
@@ -267,7 +270,7 @@ mod tests {
267270 #[ cfg( f16_enabled) ]
268271 fn check_f16 ( ) {
269272 // Constants
270- assert_eq ! ( f16:: EXP_MAX , 0b11111 ) ;
273+ assert_eq ! ( f16:: EXP_SAT , 0b11111 ) ;
271274 assert_eq ! ( f16:: EXP_BIAS , 15 ) ;
272275
273276 // `exp_unbiased`
@@ -289,7 +292,7 @@ mod tests {
289292 #[ test]
290293 fn check_f32 ( ) {
291294 // Constants
292- assert_eq ! ( f32 :: EXP_MAX , 0b11111111 ) ;
295+ assert_eq ! ( f32 :: EXP_SAT , 0b11111111 ) ;
293296 assert_eq ! ( f32 :: EXP_BIAS , 127 ) ;
294297
295298 // `exp_unbiased`
@@ -312,7 +315,7 @@ mod tests {
312315 #[ test]
313316 fn check_f64 ( ) {
314317 // Constants
315- assert_eq ! ( f64 :: EXP_MAX , 0b11111111111 ) ;
318+ assert_eq ! ( f64 :: EXP_SAT , 0b11111111111 ) ;
316319 assert_eq ! ( f64 :: EXP_BIAS , 1023 ) ;
317320
318321 // `exp_unbiased`
@@ -336,7 +339,7 @@ mod tests {
336339 #[ cfg( f128_enabled) ]
337340 fn check_f128 ( ) {
338341 // Constants
339- assert_eq ! ( f128:: EXP_MAX , 0b111111111111111 ) ;
342+ assert_eq ! ( f128:: EXP_SAT , 0b111111111111111 ) ;
340343 assert_eq ! ( f128:: EXP_BIAS , 16383 ) ;
341344
342345 // `exp_unbiased`
0 commit comments