Module malachite_base::num::arithmetic::saturating_add_mul
source · Expand description
SaturatingAddMul
and
SaturatingAddMulAssign
, traits for adding the product of two
numbers to a number and saturating at numeric bounds instead of overflowing.
§saturating_add_mul
use malachite_base::num::arithmetic::traits::SaturatingAddMul;
assert_eq!(2u8.saturating_add_mul(3, 7), 23);
assert_eq!(2u8.saturating_add_mul(20, 20), 255);
assert_eq!(127i8.saturating_add_mul(-2, 100), -73);
assert_eq!((-127i8).saturating_add_mul(-2, 100), -128);
§saturating_add_mul_assign
use malachite_base::num::arithmetic::traits::SaturatingAddMulAssign;
let mut x = 2u8;
x.saturating_add_mul_assign(3, 7);
assert_eq!(x, 23);
let mut x = 2u8;
x.saturating_add_mul_assign(20, 20);
assert_eq!(x, 255);
let mut x = 127i8;
x.saturating_add_mul_assign(-2, 100);
assert_eq!(x, -73);
let mut x = -127i8;
x.saturating_add_mul_assign(-2, 100);
assert_eq!(x, -128);