pub trait ModularInteger: Sized + PartialEq + Add<Self, Output = Self> + Sub<Self, Output = Self> + Neg<Output = Self> + Mul<Self, Output = Self> {
    type Base;

    // Required methods
    fn modulus(&self) -> Self::Base;
    fn residue(&self) -> Self::Base;
    fn is_zero(&self) -> bool;
    fn convert(&self, n: Self::Base) -> Self;
    fn double(self) -> Self;
    fn square(self) -> Self;
}
Expand description

Represents an number defined in a modulo ring ℤ/nℤ

The operators should panic if the modulus of two number are not the same.

Required Associated Types§

source

type Base

The underlying representation type of the integer

Required Methods§

source

fn modulus(&self) -> Self::Base

Return the modulus of the ring

source

fn residue(&self) -> Self::Base

Return the normalized residue of this integer in the ring

source

fn is_zero(&self) -> bool

Check if the integer is zero

source

fn convert(&self, n: Self::Base) -> Self

Convert an normal integer into the same ring.

This method should be perferred over the static constructor to prevent unnecessary overhead of pre-computation.

source

fn double(self) -> Self

Calculate the value of self + self

source

fn square(self) -> Self

Calculate the value of self * self

Implementors§

source§

impl<T: PartialEq + Clone, R: Reducer<T> + Clone> ModularInteger for ReducedInt<T, R>

§

type Base = T