Module malachite_base::num::arithmetic::overflowing_add_mul
source · Expand description
OverflowingAddMul
and
OverflowingAddMulAssign
, traits for adding the product of
two other numbers to a number and returning a boolean indicating whether an overflow occurred.
§overflowing_add_mul
use malachite_base::num::arithmetic::traits::OverflowingAddMul;
assert_eq!(2u8.overflowing_add_mul(3, 7), (23, false));
assert_eq!(2u8.overflowing_add_mul(20, 20), (146, true));
assert_eq!(127i8.overflowing_add_mul(-2, 100), (-73, false));
assert_eq!((-127i8).overflowing_add_mul(-2, 100), (-71, true));
§overflowing_add_mul_assign
use malachite_base::num::arithmetic::traits::OverflowingAddMulAssign;
let mut x = 2u8;
assert_eq!(x.overflowing_add_mul_assign(3, 7), false);
assert_eq!(x, 23);
let mut x = 2u8;
assert_eq!(x.overflowing_add_mul_assign(20, 20), true);
assert_eq!(x, 146);
let mut x = 127i8;
assert_eq!(x.overflowing_add_mul_assign(-2, 100), false);
assert_eq!(x, -73);
let mut x = -127i8;
assert_eq!(x.overflowing_add_mul_assign(-2, 100), true);
assert_eq!(x, -71);