Module malachite_base::num::arithmetic::overflowing_sub_mul
source · Expand description
OverflowingSubMul
and
OverflowingSubMulAssign
, traits for subtracting the product
of two other numbers from a number and returning a boolean indicating whether an overflow
occurred.
§overflowing_sub_mul
use malachite_base::num::arithmetic::traits::OverflowingSubMul;
assert_eq!(60u8.overflowing_sub_mul(5, 10), (10, false));
assert_eq!(2u8.overflowing_sub_mul(10, 5), (208, true));
assert_eq!(127i8.overflowing_sub_mul(2, 100), (-73, false));
assert_eq!((-127i8).overflowing_sub_mul(2, 100), (-71, true));
§overflowing_sub_mul_assign
use malachite_base::num::arithmetic::traits::OverflowingSubMulAssign;
let mut x = 60u8;
assert_eq!(x.overflowing_sub_mul_assign(5, 10), false);
assert_eq!(x, 10);
let mut x = 2u8;
assert_eq!(x.overflowing_sub_mul_assign(10, 5), true);
assert_eq!(x, 208);
let mut x = 127i8;
assert_eq!(x.overflowing_sub_mul_assign(2, 100), false);
assert_eq!(x, -73);
let mut x = -127i8;
assert_eq!(x.overflowing_sub_mul_assign(2, 100), true);
assert_eq!(x, -71);