[][src]Struct cyclic::modular::Modular

pub struct Modular<const N: u32>(pub u32);

Methods

impl<const N: u32> Modular<{ N }>[src]

A ring type taking values in Z/nZ, for any positive n.

Examples

use cyclic::modular::Modular;

const N: u32 = 6;
let r = Modular::<N>::new(2);
let s = Modular::<N>::new(3);

assert_eq!((r * s).0, 0);
This example deliberately fails to compile
use cyclic::modular::Modular;

let r = Modular::<3>::new(1);
let s = Modular::<4>::new(1);

let absurd = r + s;

pub fn new(val: u32) -> Self[src]

pub fn pow(self, exp: u32) -> Self[src]

Trait Implementations

impl<const N: u32> Add<Modular<N>> for Modular<{ N }>[src]

Adds ring elements modulo N.

type Output = Self

The resulting type after applying the + operator.

impl<const N: u32> AddAssign<Modular<N>> for Modular<{ N }>[src]

impl<const N: u32> Clone for Modular<N>[src]

impl<const N: u32> Copy for Modular<N>[src]

impl<const N: u32> Debug for Modular<N>[src]

impl<const N: u32> Div<Modular<N>> for Modular<{ N }>[src]

Divides field elements modulo N.

Division is implemented with the extended Euclidean algorithm. There might be cases where the naive exponentiation algorithm is slightly faster; it might be worth feature-flagging this.

Panics

This currently panics for composite N; as const generics are stabilized I hope to promote this to a compile-time check with a where is_prime({ N }) clause. This panic can be disabled by compiling with the composite_order_division feature.

type Output = Self

The resulting type after applying the / operator.

impl<const N: u32> DivAssign<Modular<N>> for Modular<{ N }>[src]

impl<const N: u32> From<u32> for Modular<{ N }>[src]

impl<const N: u32> Mul<Modular<N>> for Modular<{ N }>[src]

Multiplies ring elements modulo N.

type Output = Self

The resulting type after applying the * operator.

impl<const N: u32> MulAssign<Modular<N>> for Modular<{ N }>[src]

impl<const N: u32> Neg for Modular<{ N }>[src]

Returns the additive inverse of a ring element.

type Output = Self

The resulting type after applying the - operator.

impl<const N: u32> PartialEq<Modular<N>> for Modular<{ N }>[src]

impl<const N: u32> Sub<Modular<N>> for Modular<{ N }>[src]

Subtracts ring elements modulo N.

type Output = Self

The resulting type after applying the - operator.

impl<const N: u32> SubAssign<Modular<N>> for Modular<{ N }>[src]

Auto Trait Implementations

impl<const N: u32> RefUnwindSafe for Modular<N>

impl<const N: u32> Send for Modular<N>

impl<const N: u32> Sync for Modular<N>

impl<const N: u32> Unpin for Modular<N>

impl<const N: u32> UnwindSafe for Modular<N>

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, 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.