Module malachite_base::num::arithmetic::saturating_neg
source · Expand description
SaturatingNeg
and
SaturatingNegAssign
, traits for negating a number and
saturating at numeric bounds instead of overflowing.
§saturating_neg_assign
use malachite_base::num::arithmetic::traits::SaturatingNegAssign;
let mut x = 0i8;
x.saturating_neg_assign();
assert_eq!(x, 0);
let mut x = 100i64;
x.saturating_neg_assign();
assert_eq!(x, -100);
let mut x = -100i64;
x.saturating_neg_assign();
assert_eq!(x, 100);
let mut x = -128i8;
x.saturating_neg_assign();
assert_eq!(x, 127);