Module malachite_base::num::arithmetic::saturating_sub_mul
source · Expand description
SaturatingSubMul
and
SaturatingSubMulAssign
, traits for subtracting a number by
the product of two numbers and saturating at numeric bounds instead of overflowing.
§saturating_sub_mul
use malachite_base::num::arithmetic::traits::SaturatingSubMul;
assert_eq!(60u8.saturating_sub_mul(5, 10), 10);
assert_eq!(2u8.saturating_sub_mul(10, 5), 0);
assert_eq!(127i8.saturating_sub_mul(2, 100), -73);
assert_eq!((-127i8).saturating_sub_mul(2, 100), -128);
§saturating_sub_mul_assign
use malachite_base::num::arithmetic::traits::SaturatingSubMulAssign;
let mut x = 60u8;
x.saturating_sub_mul_assign(5, 10);
assert_eq!(x, 10);
let mut x = 2u8;
x.saturating_sub_mul_assign(10, 5);
assert_eq!(x, 0);
let mut x = 127i8;
x.saturating_sub_mul_assign(2, 100);
assert_eq!(x, -73);
let mut x = -127i8;
x.saturating_sub_mul_assign(2, 100);
assert_eq!(x, -128);