[][src]Trait maths_traits::algebra::integer::IntegerSubset

pub trait IntegerSubset: Ord + Eq + Clone + CastPrimInt + ToPrimitive + FromPrimitive + EuclideanSemidomain + Primality + ArchSemiring + ArchimedeanDiv + Sign + Sub<Self, Output = Self> + Div<Self, Output = Self> + Rem<Self, Output = Self> + SubAssign<Self> + DivAssign<Self> + RemAssign<Self> {
    type Signed: Integer + IntegerSubset<Signed = Self::Signed, Unsigned = Self::Unsigned>;
    type Unsigned: Natural + IntegerSubset<Signed = Self::Signed, Unsigned = Self::Unsigned>;
    fn as_signed(self) -> Self::Signed;
fn as_unsigned(self) -> Self::Unsigned; fn abs_unsigned(self) -> Self::Unsigned { ... }
fn two() -> Self { ... }
fn mul_two(self) -> Self { ... }
fn div_two(self) -> Self { ... }
fn even(&self) -> bool { ... }
fn odd(&self) -> bool { ... } }

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

Loading content...

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

Loading content...

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

Loading content...

Implementations on Foreign Types

impl IntegerSubset for u8[src]

type Signed = i8

type Unsigned = u8

impl IntegerSubset for i8[src]

type Signed = i8

type Unsigned = u8

impl IntegerSubset for u16[src]

type Signed = i16

type Unsigned = u16

impl IntegerSubset for i16[src]

type Signed = i16

type Unsigned = u16

impl IntegerSubset for u32[src]

type Signed = i32

type Unsigned = u32

impl IntegerSubset for i32[src]

type Signed = i32

type Unsigned = u32

impl IntegerSubset for u64[src]

type Signed = i64

type Unsigned = u64

impl IntegerSubset for i64[src]

type Signed = i64

type Unsigned = u64

impl IntegerSubset for u128[src]

type Signed = i128

type Unsigned = u128

impl IntegerSubset for i128[src]

type Signed = i128

type Unsigned = u128

impl IntegerSubset for usize[src]

type Signed = isize

type Unsigned = usize

impl IntegerSubset for isize[src]

type Signed = isize

type Unsigned = usize

Loading content...

Implementors

Loading content...