Expand description

ArithmeticCheckedShl, a trait for left-shifting a number and checking whether the result is representable.

arithmetic_checked_shl

use malachite_base::num::arithmetic::traits::ArithmeticCheckedShl;

assert_eq!(3u8.arithmetic_checked_shl(6), Some(192u8));
assert_eq!(3u8.arithmetic_checked_shl(7), None);
assert_eq!(3u8.arithmetic_checked_shl(100), None);
assert_eq!(0u8.arithmetic_checked_shl(100), Some(0u8));

assert_eq!(3u8.arithmetic_checked_shl(6), Some(192u8));
assert_eq!(3u8.arithmetic_checked_shl(7), None);
assert_eq!(3u8.arithmetic_checked_shl(100), None);
assert_eq!(0u8.arithmetic_checked_shl(100), Some(0u8));
assert_eq!(100u8.arithmetic_checked_shl(-3), Some(12u8));
assert_eq!(100u8.arithmetic_checked_shl(-100), Some(0u8));

assert_eq!(3i8.arithmetic_checked_shl(5), Some(96i8));
assert_eq!(3i8.arithmetic_checked_shl(6), None);
assert_eq!((-3i8).arithmetic_checked_shl(5), Some(-96i8));
assert_eq!((-3i8).arithmetic_checked_shl(6), None);
assert_eq!(3i8.arithmetic_checked_shl(100), None);
assert_eq!((-3i8).arithmetic_checked_shl(100), None);
assert_eq!(0i8.arithmetic_checked_shl(100), Some(0i8));

assert_eq!(3i8.arithmetic_checked_shl(5), Some(96i8));
assert_eq!(3i8.arithmetic_checked_shl(6), None);
assert_eq!((-3i8).arithmetic_checked_shl(5), Some(-96i8));
assert_eq!((-3i8).arithmetic_checked_shl(6), None);
assert_eq!(3i8.arithmetic_checked_shl(100), None);
assert_eq!((-3i8).arithmetic_checked_shl(100), None);
assert_eq!(0i8.arithmetic_checked_shl(100), Some(0i8));
assert_eq!(100i8.arithmetic_checked_shl(-3), Some(12i8));
assert_eq!((-100i8).arithmetic_checked_shl(-3), Some(-13i8));
assert_eq!(100i8.arithmetic_checked_shl(-100), Some(0i8));
assert_eq!((-100i8).arithmetic_checked_shl(-100), Some(-1i8));