1 //! Bit-shift helpers.
2 
3 use super::float::ExtendedFloat;
4 use crate::lib::mem;
5 
6 // Shift extended-precision float right `shift` bytes.
7 #[inline]
shr(fp: &mut ExtendedFloat, shift: i32)8 pub(crate) fn shr(fp: &mut ExtendedFloat, shift: i32) {
9     let bits: u64 = mem::size_of::<u64>() as u64 * 8;
10     debug_assert!((shift as u64) < bits, "shr() overflow in shift right.");
11 
12     fp.mant >>= shift;
13     fp.exp += shift;
14 }
15 
16 // Shift extended-precision float right `shift` bytes.
17 //
18 // Accepts when the shift is the same as the type size, and
19 // sets the value to 0.
20 #[inline]
overflowing_shr(fp: &mut ExtendedFloat, shift: i32)21 pub(crate) fn overflowing_shr(fp: &mut ExtendedFloat, shift: i32) {
22     let bits: u64 = mem::size_of::<u64>() as u64 * 8;
23     debug_assert!((shift as u64) <= bits, "overflowing_shr() overflow in shift right.");
24 
25     fp.mant = match shift as u64 == bits {
26         true => 0,
27         false => fp.mant >> shift,
28     };
29     fp.exp += shift;
30 }
31 
32 // Shift extended-precision float left `shift` bytes.
33 #[inline]
shl(fp: &mut ExtendedFloat, shift: i32)34 pub(crate) fn shl(fp: &mut ExtendedFloat, shift: i32) {
35     let bits: u64 = mem::size_of::<u64>() as u64 * 8;
36     debug_assert!((shift as u64) < bits, "shl() overflow in shift left.");
37 
38     fp.mant <<= shift;
39     fp.exp -= shift;
40 }
41