@@ -48,11 +48,14 @@ pub trait Float:
48
48
/// The bitwidth of the exponent
49
49
const EXP_BITS : u32 = Self :: BITS - Self :: SIG_BITS - 1 ;
50
50
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 ;
53
56
54
57
/// The exponent bias value
55
- const EXP_BIAS : u32 = Self :: EXP_MAX >> 1 ;
58
+ const EXP_BIAS : u32 = Self :: EXP_SAT >> 1 ;
56
59
57
60
/// A mask for the sign bit
58
61
const SIGN_MASK : Self :: Int ;
@@ -109,7 +112,7 @@ pub trait Float:
109
112
110
113
/// Returns the exponent, not adjusting for bias, not accounting for subnormals or zero.
111
114
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
113
116
}
114
117
115
118
/// Extract the exponent and adjust it for bias, not accounting for subnormals or zero.
@@ -135,7 +138,7 @@ pub trait Float:
135
138
let sign = if negative { Self :: Int :: ONE } else { Self :: Int :: ZERO } ;
136
139
Self :: from_bits (
137
140
( 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 )
139
142
| ( significand & Self :: SIG_MASK ) ,
140
143
)
141
144
}
@@ -267,7 +270,7 @@ mod tests {
267
270
#[ cfg( f16_enabled) ]
268
271
fn check_f16 ( ) {
269
272
// Constants
270
- assert_eq ! ( f16:: EXP_MAX , 0b11111 ) ;
273
+ assert_eq ! ( f16:: EXP_SAT , 0b11111 ) ;
271
274
assert_eq ! ( f16:: EXP_BIAS , 15 ) ;
272
275
273
276
// `exp_unbiased`
@@ -289,7 +292,7 @@ mod tests {
289
292
#[ test]
290
293
fn check_f32 ( ) {
291
294
// Constants
292
- assert_eq ! ( f32 :: EXP_MAX , 0b11111111 ) ;
295
+ assert_eq ! ( f32 :: EXP_SAT , 0b11111111 ) ;
293
296
assert_eq ! ( f32 :: EXP_BIAS , 127 ) ;
294
297
295
298
// `exp_unbiased`
@@ -312,7 +315,7 @@ mod tests {
312
315
#[ test]
313
316
fn check_f64 ( ) {
314
317
// Constants
315
- assert_eq ! ( f64 :: EXP_MAX , 0b11111111111 ) ;
318
+ assert_eq ! ( f64 :: EXP_SAT , 0b11111111111 ) ;
316
319
assert_eq ! ( f64 :: EXP_BIAS , 1023 ) ;
317
320
318
321
// `exp_unbiased`
@@ -336,7 +339,7 @@ mod tests {
336
339
#[ cfg( f128_enabled) ]
337
340
fn check_f128 ( ) {
338
341
// Constants
339
- assert_eq ! ( f128:: EXP_MAX , 0b111111111111111 ) ;
342
+ assert_eq ! ( f128:: EXP_SAT , 0b111111111111111 ) ;
340
343
assert_eq ! ( f128:: EXP_BIAS , 16383 ) ;
341
344
342
345
// `exp_unbiased`
0 commit comments