Module malachite_base::num::arithmetic::saturating_square
source · Expand description
SaturatingSquare
and
SaturatingSquareAssign
, traits for squaring a number and
saturating at numeric bounds instead of overflowing.
§saturating_square
use malachite_base::num::arithmetic::traits::SaturatingSquare;
assert_eq!(3u8.saturating_square(), 9);
assert_eq!((-1000i32).saturating_square(), 1000000);
assert_eq!(1000u16.saturating_square(), u16::MAX);
§saturating_square_assign
use malachite_base::num::arithmetic::traits::SaturatingSquareAssign;
let mut x = 3u8;
x.saturating_square_assign();
assert_eq!(x, 9);
let mut x = -1000i32;
x.saturating_square_assign();
assert_eq!(x, 1000000);
let mut x = 1000u16;
x.saturating_square_assign();
assert_eq!(x, u16::MAX);