deduplicate calculation
This commit is contained in:
parent
fa547050e2
commit
2045d8047a
@ -238,11 +238,10 @@ macro_rules! impl_from_float {
|
||||
//extract exponent, add fractional offset
|
||||
//usize is used to calculate digit_index. exp_cycle must be at least 8 bits so 32 bits is fine
|
||||
let exp=((bits>>($mantissa_bits-1)) as usize&((1<<$exponent_bits)-1))+F;
|
||||
//digit_index is where the hi digit should end up in a fixed point number
|
||||
//if it's less than zero, that's a conversion underflow.
|
||||
let digit_index=exp.checked_sub($exp_bias)?>>DIGIT_SHIFT;
|
||||
let exp_bias=exp.checked_sub($exp_bias)?;
|
||||
//cycle the exponent to keep the top bit of the mantissa within the hi digit
|
||||
let exp_cycle=exp.overflowing_sub($exp_bias+64).0.rem_euclid(64).overflowing_add($exp_bias+64).0;
|
||||
let exp_cycle=exp_bias.rem_euclid(64).overflowing_add($exp_bias+64).0;
|
||||
let out_bits=
|
||||
bits
|
||||
//remove (mask) sign bit and exponent
|
||||
@ -253,7 +252,8 @@ macro_rules! impl_from_float {
|
||||
let _128=<$input>::from_bits(out_bits) as u128;
|
||||
Some(FloatInfo{
|
||||
sign:f.is_sign_negative(),
|
||||
digit_index,
|
||||
//digit_index is where the hi digit should end up in a fixed point number
|
||||
digit_index:exp_bias>>DIGIT_SHIFT,
|
||||
bits:[_128 as u64,(_128>>64) as u64],
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user