Fix some shifting issues.

This commit is contained in:
2018-04-04 17:26:49 -07:00
parent 3cd37a881d
commit ceb1e9eb58
2 changed files with 16 additions and 5 deletions

View File

@@ -78,7 +78,7 @@ macro_rules! derive_shifts_from_shift_assign
fn $fn(self, rhs: $base) -> $type { fn $fn(self, rhs: $base) -> $type {
let mut copy = self.clone(); let mut copy = self.clone();
copy.$asnfn(rhs); copy.$asnfn(rhs as u64);
copy copy
} }
} }
@@ -88,7 +88,7 @@ macro_rules! derive_shifts_from_shift_assign
fn $fn(self, rhs: $base) -> $type { fn $fn(self, rhs: $base) -> $type {
let mut copy = self.clone(); let mut copy = self.clone();
copy.$asnfn(rhs); copy.$asnfn(rhs as u64);
copy copy
} }
} }
@@ -113,7 +113,7 @@ macro_rules! derive_signed_shift_operators
if rhs < 0 { if rhs < 0 {
self.shl_assign(-rhs); self.shl_assign(-rhs);
} else { } else {
self.shr_assign(rhs); self.shr_assign(rhs as $base);
} }
} }
} }

View File

@@ -890,7 +890,7 @@ mod test {
(&a << 0) == a (&a << 0) == a
} }
fn shr_identity(a: UCN) -> bool { fn shr_identity(a: UCN) -> bool {
(&a << 0) == a (&a >> 0) == a
} }
fn add_identity(a: UCN) -> bool { fn add_identity(a: UCN) -> bool {
(&a + &UCN{ contents: vec![] }) == a (&a + &UCN{ contents: vec![] }) == a
@@ -1049,6 +1049,17 @@ mod test {
let pow2 = one << b; let pow2 = one << b;
(&a << b) == (&a * pow2) (&a << b) == (&a * pow2)
} }
fn shl_mul_equiv(a: UCN) -> bool {
(&a << 1) == (&a * UCN::from(2 as u64)) &&
(&a << 3) == (&a * UCN::from(8 as u64)) &&
(&a << 4) == (&a * UCN::from(16 as u64)) &&
(&a << 43) == (&a * UCN::from(8796093022208 as u64))
}
fn shr_div_equiv(a: UCN) -> bool {
(&a >> 1) == (&a / UCN::from(2 as u64)) &&
(&a >> 3) == (&a / UCN::from(8 as u64)) &&
(&a >> 4) == (&a / UCN::from(16 as u64)) &&
(&a >> 43) == (&a / UCN::from(8796093022208 as u64))
}
} }
} }