[−][src]Trait maths_traits::algebra::integer::IntegerSubset
A subset of the Integers that has all of the major integer operations
This includes:
- Basic ring operations
- Euclidean division any everything implied by having it
- Algebraic ordering properties and archimedian division
- Additional operations conventionally implemented on integer types
In practice, this means that a type implementing this trait must be either a representation of the natural numbers or the integers as a whole.
Furthermore, this trait contains associated types referring to an unsigned and signed type of similar precision to make it easier to manage the broader system of types used in integer algorithms
Associated Types
type Signed: Integer + IntegerSubset<Signed = Self::Signed, Unsigned = Self::Unsigned>
This type's corresponding signed Integer representation
Implementors should guarantee that this type has the same theoretical bit precision as the Unsigned type
type Unsigned: Natural + IntegerSubset<Signed = Self::Signed, Unsigned = Self::Unsigned>
This type's corresponding unsigned Integer representation
Implementors should guarantee that this type has the same theoretical bit precision as the Signed type
Required methods
fn as_signed(self) -> Self::Signed
Converts self
to a signed integer representation
Note that this has the same guarantees as the primitive as
operation
and can thus panic on overflow
fn as_unsigned(self) -> Self::Unsigned
Converts self
into an unsigned integer representation
Note that this has the same guarantees as the primitive as
operation
and can thus panic on underflow
Provided methods
fn abs_unsigned(self) -> Self::Unsigned
Takes the absolute value and converts into an unsigned integer representation
Implementors should guarantee that this conversion never fails or panics since the unsigned and signed types are assumed to be of the same theoretical bit precision
fn two() -> Self
A shorthand for 1+1
fn mul_two(self) -> Self
Multiplies by two
This is meant both as convenience and to expose the <<
operator for representations that
support it. As such, this method has the potential to be faster than normal multiplication
fn div_two(self) -> Self
Divides by two
This is meant both as convenience and to expose the >>
operator for representations that
support it. As such, this method has the potential to be faster than normal division
fn even(&self) -> bool
Determines if a number is divisible by two
fn odd(&self) -> bool
Determines if a number is not divisible by two