Module malachite_base::num::arithmetic::saturating_abs
source · Expand description
SaturatingAbs
and
SaturatingAbsAssign
, traits for taking the absolute value of a
number and saturating at numeric bounds instead of overflowing.
§saturating_abs_assign
use malachite_base::num::arithmetic::traits::SaturatingAbsAssign;
let mut x = 0i8;
x.saturating_abs_assign();
assert_eq!(x, 0);
let mut x = 100i64;
x.saturating_abs_assign();
assert_eq!(x, 100);
let mut x = -100i64;
x.saturating_abs_assign();
assert_eq!(x, 100);
let mut x = -128i8;
x.saturating_abs_assign();
assert_eq!(x, 127);