1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use crate::{False, IsNonZero, IsSigned, True};
use crate::{Integer, NonZero, UnsignedInt};
use core::ops::Neg;
/// Signed UnsignedInt common operations
pub trait SignedInt:
IsSigned<Signed = True> + IsNonZero<NonZero = False> + Neg<Output = Self> + Integer
{
type UnsignedInt: UnsignedInt<SignedInt = Self>;
/// The non-zero variant of the UnsignedInt
type NonZeroUnsignedInt: NonZero<BaseType = Self>;
/// Convert `self` into the unsigned variant of `Self`
fn to_unsigned(self) -> Self::UnsignedInt;
/// Computes the absolute value of self.
/// # Overflow behavior
/// The absolute value of Self::MIN cannot be represented as an Self, and
/// attempting to calculate it will cause an overflow. This means that code
/// in debug mode will trigger a panic on this case and optimized code will
/// return Self::MIN without a panic.
fn abs(self) -> Self;
/// Checked absolute value. Computes self.abs(), returning None if
/// self == MIN.
fn checked_abs(self) -> Option<Self>;
/// Checked negation. Computes -self, returning None if self == MIN.
fn checked_neg(self) -> Option<Self>;
/// Return a number representing the sign of `self`, i.e.
/// * `0` if the number is zero
/// * `1` if the number is positive
/// * `-1` if the number is negative
fn signum(self) -> Self;
/// Checked subtraction with an unsigned integer. Computes self - rhs,
/// returning None if overflow occurred.
fn checked_sub_unsigned(self, rhs: Self::UnsignedInt) -> Option<Self>;
/// Saturating addition with an unsigned integer. Computes self + rhs,
/// saturating at the numeric bounds instead of overflowing.
fn saturating_add_unsigned(self, rhs: Self::UnsignedInt) -> Self;
/// Saturating subtraction with an unsigned integer. Computes self - rhs,
/// saturating at the numeric bounds instead of overflowing.
fn saturating_sub_unsigned(self, rhs: Self::UnsignedInt) -> Self;
/// Wrapping (modular) addition with an unsigned integer. Computes
/// self + rhs, wrapping around at the boundary of the type.
fn wrapping_add_unsigned(self, rhs: Self::UnsignedInt) -> Self;
/// Wrapping (modular) subtraction with an unsigned integer. Computes
/// self - rhs, wrapping around at the boundary of the type.
fn wrapping_sub_unsigned(self, rhs: Self::UnsignedInt) -> Self;
}