@@ -32,7 +32,7 @@ mod int_to_float {
32
32
/// Usually 1 is subtracted from this function's result, so that a mantissa with the implicit
33
33
/// bit set can be added back later.
34
34
fn exp < I : Int , F : Float < Int : CastFrom < u32 > > > ( n : u32 ) -> F :: Int {
35
- F :: Int :: cast_from ( F :: EXPONENT_BIAS - 1 + I :: BITS - n)
35
+ F :: Int :: cast_from ( F :: EXP_BIAS - 1 + I :: BITS - n)
36
36
}
37
37
38
38
/// Adjust a mantissa with dropped bits to perform correct rounding.
@@ -42,7 +42,7 @@ mod int_to_float {
42
42
fn m_adj < F : Float > ( m_base : F :: Int , dropped_bits : F :: Int ) -> F :: Int {
43
43
// Branchlessly extract a `1` if rounding up should happen, 0 otherwise
44
44
// This accounts for rounding to even.
45
- let adj = ( dropped_bits - ( dropped_bits >> ( F :: BITS - 1 ) & !m_base) ) >> ( F :: BITS - 1 ) ;
45
+ let adj = ( dropped_bits - ( ( dropped_bits >> ( F :: BITS - 1 ) ) & !m_base) ) >> ( F :: BITS - 1 ) ;
46
46
47
47
// Add one when we need to round up. Break ties to even.
48
48
m_base + adj
@@ -54,17 +54,17 @@ mod int_to_float {
54
54
/// value to cancel it out.
55
55
fn repr < F : Float > ( e : F :: Int , m : F :: Int ) -> F :: Int {
56
56
// + rather than | so the mantissa can overflow into the exponent
57
- ( e << F :: SIGNIFICAND_BITS ) + m
57
+ ( e << F :: SIG_BITS ) + m
58
58
}
59
59
60
60
/// Shift distance from a left-aligned integer to a smaller float.
61
61
fn shift_f_lt_i < I : Int , F : Float > ( ) -> u32 {
62
- ( I :: BITS - F :: BITS ) + F :: EXPONENT_BITS
62
+ ( I :: BITS - F :: BITS ) + F :: EXP_BITS
63
63
}
64
64
65
65
/// Shift distance from an integer with `n` leading zeros to a smaller float.
66
66
fn shift_f_gt_i < I : Int , F : Float > ( n : u32 ) -> u32 {
67
- F :: SIGNIFICAND_BITS - I :: BITS + 1 + n
67
+ F :: SIG_BITS - I :: BITS + 1 + n
68
68
}
69
69
70
70
/// Perform a signed operation as unsigned, then add the sign back.
@@ -85,9 +85,9 @@ mod int_to_float {
85
85
}
86
86
let n = i. leading_zeros ( ) ;
87
87
// Mantissa with implicit bit set (significant bits)
88
- let m_base = ( i << n) >> f32:: EXPONENT_BITS ;
88
+ let m_base = ( i << n) >> f32:: EXP_BITS ;
89
89
// Bits that will be dropped (insignificant bits)
90
- let adj = ( i << n) << ( f32:: SIGNIFICAND_BITS + 1 ) ;
90
+ let adj = ( i << n) << ( f32:: SIG_BITS + 1 ) ;
91
91
let m = m_adj :: < f32 > ( m_base, adj) ;
92
92
let e = exp :: < u32 , f32 > ( n) - 1 ;
93
93
repr :: < f32 > ( e, m)
@@ -116,7 +116,7 @@ mod int_to_float {
116
116
let m = ( i as u64 ) << ( shift_f_gt_i :: < u32 , f128 > ( n) - 64 ) ;
117
117
let e = exp :: < u32 , f128 > ( n) as u64 - 1 ;
118
118
// High 64 bits of f128 representation.
119
- let h = ( e << ( f128:: SIGNIFICAND_BITS - 64 ) ) + m;
119
+ let h = ( e << ( f128:: SIG_BITS - 64 ) ) + m;
120
120
121
121
// Shift back to the high bits, the rest of the mantissa will always be 0.
122
122
( h as u128 ) << 64
@@ -128,8 +128,8 @@ mod int_to_float {
128
128
// Mantissa with implicit bit set
129
129
let m_base: u32 = ( i_m >> shift_f_lt_i :: < u64 , f32 > ( ) ) as u32 ;
130
130
// The entire lower half of `i` will be truncated (masked portion), plus the
131
- // next `EXPONENT_BITS ` bits.
132
- let adj = ( i_m >> f32:: EXPONENT_BITS | i_m & 0xFFFF ) as u32 ;
131
+ // next `EXP_BITS ` bits.
132
+ let adj = ( ( i_m >> f32:: EXP_BITS ) | i_m & 0xFFFF ) as u32 ;
133
133
let m = m_adj :: < f32 > ( m_base, adj) ;
134
134
let e = if i == 0 { 0 } else { exp :: < u64 , f32 > ( n) - 1 } ;
135
135
repr :: < f32 > ( e, m)
@@ -141,8 +141,8 @@ mod int_to_float {
141
141
}
142
142
let n = i. leading_zeros ( ) ;
143
143
// Mantissa with implicit bit set
144
- let m_base = ( i << n) >> f64:: EXPONENT_BITS ;
145
- let adj = ( i << n) << ( f64:: SIGNIFICAND_BITS + 1 ) ;
144
+ let m_base = ( i << n) >> f64:: EXP_BITS ;
145
+ let adj = ( i << n) << ( f64:: SIG_BITS + 1 ) ;
146
146
let m = m_adj :: < f64 > ( m_base, adj) ;
147
147
let e = exp :: < u64 , f64 > ( n) - 1 ;
148
148
repr :: < f64 > ( e, m)
@@ -167,7 +167,7 @@ mod int_to_float {
167
167
168
168
// Within the upper `F::BITS`, everything except for the signifcand
169
169
// gets truncated
170
- let d1: u32 = ( i_m >> ( u128:: BITS - f32:: BITS - f32:: SIGNIFICAND_BITS - 1 ) ) . cast ( ) ;
170
+ let d1: u32 = ( i_m >> ( u128:: BITS - f32:: BITS - f32:: SIG_BITS - 1 ) ) . cast ( ) ;
171
171
172
172
// The entire rest of `i_m` gets truncated. Zero the upper `F::BITS` then just
173
173
// check if it is nonzero.
@@ -186,8 +186,8 @@ mod int_to_float {
186
186
// Mantissa with implicit bit set
187
187
let m_base: u64 = ( i_m >> shift_f_lt_i :: < u128 , f64 > ( ) ) as u64 ;
188
188
// The entire lower half of `i` will be truncated (masked portion), plus the
189
- // next `EXPONENT_BITS ` bits.
190
- let adj = ( i_m >> f64:: EXPONENT_BITS | i_m & 0xFFFF_FFFF ) as u64 ;
189
+ // next `EXP_BITS ` bits.
190
+ let adj = ( ( i_m >> f64:: EXP_BITS ) | i_m & 0xFFFF_FFFF ) as u64 ;
191
191
let m = m_adj :: < f64 > ( m_base, adj) ;
192
192
let e = if i == 0 { 0 } else { exp :: < u128 , f64 > ( n) - 1 } ;
193
193
repr :: < f64 > ( e, m)
@@ -200,8 +200,8 @@ mod int_to_float {
200
200
}
201
201
let n = i. leading_zeros ( ) ;
202
202
// Mantissa with implicit bit set
203
- let m_base = ( i << n) >> f128:: EXPONENT_BITS ;
204
- let adj = ( i << n) << ( f128:: SIGNIFICAND_BITS + 1 ) ;
203
+ let m_base = ( i << n) >> f128:: EXP_BITS ;
204
+ let adj = ( i << n) << ( f128:: SIG_BITS + 1 ) ;
205
205
let m = m_adj :: < f128 > ( m_base, adj) ;
206
206
let e = exp :: < u128 , f128 > ( n) - 1 ;
207
207
repr :: < f128 > ( e, m)
@@ -362,29 +362,29 @@ where
362
362
F :: Int : CastFrom < u32 > ,
363
363
u32 : CastFrom < F :: Int > ,
364
364
{
365
- let int_max_exp = F :: EXPONENT_BIAS + I :: MAX . ilog2 ( ) + 1 ;
366
- let foobar = F :: EXPONENT_BIAS + I :: UnsignedInt :: BITS - 1 ;
365
+ let int_max_exp = F :: EXP_BIAS + I :: MAX . ilog2 ( ) + 1 ;
366
+ let foobar = F :: EXP_BIAS + I :: UnsignedInt :: BITS - 1 ;
367
367
368
368
if fbits < F :: ONE . to_bits ( ) {
369
369
// < 0 gets rounded to 0
370
370
I :: ZERO
371
- } else if fbits < F :: Int :: cast_from ( int_max_exp) << F :: SIGNIFICAND_BITS {
371
+ } else if fbits < F :: Int :: cast_from ( int_max_exp) << F :: SIG_BITS {
372
372
// >= 1, < integer max
373
373
let m_base = if I :: UnsignedInt :: BITS >= F :: Int :: BITS {
374
- I :: UnsignedInt :: cast_from ( fbits) << ( I :: BITS - F :: SIGNIFICAND_BITS - 1 )
374
+ I :: UnsignedInt :: cast_from ( fbits) << ( I :: BITS - F :: SIG_BITS - 1 )
375
375
} else {
376
- I :: UnsignedInt :: cast_from ( fbits >> ( F :: SIGNIFICAND_BITS - I :: BITS + 1 ) )
376
+ I :: UnsignedInt :: cast_from ( fbits >> ( F :: SIG_BITS - I :: BITS + 1 ) )
377
377
} ;
378
378
379
379
// Set the implicit 1-bit.
380
- let m: I :: UnsignedInt = I :: UnsignedInt :: ONE << ( I :: BITS - 1 ) | m_base;
380
+ let m: I :: UnsignedInt = ( I :: UnsignedInt :: ONE << ( I :: BITS - 1 ) ) | m_base;
381
381
382
382
// Shift based on the exponent and bias.
383
- let s: u32 = ( foobar) - u32:: cast_from ( fbits >> F :: SIGNIFICAND_BITS ) ;
383
+ let s: u32 = ( foobar) - u32:: cast_from ( fbits >> F :: SIG_BITS ) ;
384
384
385
385
let unsigned = m >> s;
386
386
map_inbounds ( I :: from_unsigned ( unsigned) )
387
- } else if fbits <= F :: EXPONENT_MASK {
387
+ } else if fbits <= F :: EXP_MASK {
388
388
// >= max (incl. inf)
389
389
out_of_bounds ( )
390
390
} else {
0 commit comments