Struct ibig::modular::Modulo[][src]

pub struct Modulo<'a>(_);

Modular arithmetic.

Examples

let ring = ModuloRing::new(&ubig!(10000));
let x = ring.from(12345);
let y = ring.from(55443);
assert_eq!((x - y).residue(), ubig!(6902));

Implementations

impl Modulo<'_>[src]

pub fn residue(&self) -> UBig[src]

Get the residue in range 0..n in an n-element ring.

Examples

let ring = ModuloRing::new(&ubig!(100));
let x = ring.from(-1234);
assert_eq!(x.residue(), ubig!(66));

impl Modulo<'_>[src]

pub fn pow(&self, exp: &UBig) -> Modulo<'_>[src]

Exponentiation.

Examples

// A Mersenne prime.
let p = ubig!(2).pow(607) - ubig!(1);
let ring = ModuloRing::new(&p);
// Fermat's little theorem: a^(p-1) = 1 (mod p)
let a = ring.from(123);
assert_eq!(a.pow(&(p - ubig!(1))), ring.from(1));

Trait Implementations

impl<'a> Add<&'_ Modulo<'a>> for Modulo<'a>[src]

type Output = Modulo<'a>

The resulting type after applying the + operator.

impl<'a> Add<&'_ Modulo<'a>> for &Modulo<'a>[src]

type Output = Modulo<'a>

The resulting type after applying the + operator.

impl<'a> Add<Modulo<'a>> for Modulo<'a>[src]

type Output = Modulo<'a>

The resulting type after applying the + operator.

impl<'a> Add<Modulo<'a>> for &Modulo<'a>[src]

type Output = Modulo<'a>

The resulting type after applying the + operator.

impl<'a> AddAssign<&'_ Modulo<'a>> for Modulo<'a>[src]

impl<'a> AddAssign<Modulo<'a>> for Modulo<'a>[src]

impl Binary for Modulo<'_>[src]

impl Clone for Modulo<'_>[src]

impl Debug for Modulo<'_>[src]

impl Display for Modulo<'_>[src]

impl Eq for Modulo<'_>[src]

impl LowerHex for Modulo<'_>[src]

impl<'a> Mul<&'_ Modulo<'a>> for Modulo<'a>[src]

type Output = Modulo<'a>

The resulting type after applying the * operator.

impl<'a> Mul<&'_ Modulo<'a>> for &Modulo<'a>[src]

type Output = Modulo<'a>

The resulting type after applying the * operator.

impl<'a> Mul<Modulo<'a>> for Modulo<'a>[src]

type Output = Modulo<'a>

The resulting type after applying the * operator.

impl<'a> Mul<Modulo<'a>> for &Modulo<'a>[src]

type Output = Modulo<'a>

The resulting type after applying the * operator.

impl<'a> MulAssign<&'_ Modulo<'a>> for Modulo<'a>[src]

impl<'a> MulAssign<Modulo<'a>> for Modulo<'a>[src]

impl<'a> Neg for Modulo<'a>[src]

type Output = Modulo<'a>

The resulting type after applying the - operator.

impl<'a> Neg for &Modulo<'a>[src]

type Output = Modulo<'a>

The resulting type after applying the - operator.

impl Octal for Modulo<'_>[src]

impl PartialEq<Modulo<'_>> for Modulo<'_>[src]

Equality within a ring.

Panics

Panics if the two values are from different rings.

impl<'a> Sub<&'_ Modulo<'a>> for Modulo<'a>[src]

type Output = Modulo<'a>

The resulting type after applying the - operator.

impl<'a> Sub<&'_ Modulo<'a>> for &Modulo<'a>[src]

type Output = Modulo<'a>

The resulting type after applying the - operator.

impl<'a> Sub<Modulo<'a>> for Modulo<'a>[src]

type Output = Modulo<'a>

The resulting type after applying the - operator.

impl<'a> Sub<Modulo<'a>> for &Modulo<'a>[src]

type Output = Modulo<'a>

The resulting type after applying the - operator.

impl<'a> SubAssign<&'_ Modulo<'a>> for Modulo<'a>[src]

impl<'a> SubAssign<Modulo<'a>> for Modulo<'a>[src]

impl UpperHex for Modulo<'_>[src]

Auto Trait Implementations

impl<'a> RefUnwindSafe for Modulo<'a>

impl<'a> Send for Modulo<'a>

impl<'a> Sync for Modulo<'a>

impl<'a> Unpin for Modulo<'a>

impl<'a> UnwindSafe for Modulo<'a>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,