pub struct ConstDivisor(/* private fields */);
Expand description

An UBig with some pre-computed fields to support faster division.

Implementations§

source§

impl ConstDivisor

source

pub fn new(n: UBig) -> ConstDivisor

source

pub const fn from_word(word: u64) -> Self

source

pub const fn from_dword(dword: u128) -> Self

source

pub fn value(&self) -> UBig

source§

impl ConstDivisor

source

pub fn reduce<'a, T: IntoRing<'a, ConstDivisor, RingElement = Reduced<'a>>>( &'a self, x: T ) -> Reduced<'_>

Create an element of the modulo ring from another type.

Examples
let ring = ConstDivisor::new(UBig::from(100u8));
let x = ring.reduce(-1234);
let y = ring.reduce(IBig::from(3366));
assert!(x == y);

Trait Implementations§

source§

impl Debug for ConstDivisor

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Display for ConstDivisor

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'l, 'r> Div<&'r ConstDivisor> for &'l IBig

§

type Output = IBig

The resulting type after applying the / operator.
source§

fn div(self, rhs: &ConstDivisor) -> IBig

Performs the / operation. Read more
source§

impl<'l, 'r> Div<&'r ConstDivisor> for &'l UBig

§

type Output = UBig

The resulting type after applying the / operator.
source§

fn div(self, rhs: &ConstDivisor) -> UBig

Performs the / operation. Read more
source§

impl<'r> Div<&'r ConstDivisor> for IBig

§

type Output = IBig

The resulting type after applying the / operator.
source§

fn div(self, rhs: &ConstDivisor) -> IBig

Performs the / operation. Read more
source§

impl<'r> Div<&'r ConstDivisor> for UBig

§

type Output = UBig

The resulting type after applying the / operator.
source§

fn div(self, rhs: &ConstDivisor) -> UBig

Performs the / operation. Read more
source§

impl<'r> DivAssign<&'r ConstDivisor> for IBig

source§

fn div_assign(&mut self, rhs: &'r ConstDivisor)

Performs the /= operation. Read more
source§

impl<'r> DivAssign<&'r ConstDivisor> for UBig

source§

fn div_assign(&mut self, rhs: &'r ConstDivisor)

Performs the /= operation. Read more
source§

impl<'l, 'r> DivRem<&'r ConstDivisor> for &'l IBig

source§

impl<'l, 'r> DivRem<&'r ConstDivisor> for &'l UBig

source§

impl<'r> DivRem<&'r ConstDivisor> for IBig

source§

impl<'r> DivRem<&'r ConstDivisor> for UBig

source§

impl<'r> DivRemAssign<&'r ConstDivisor> for IBig

source§

impl<'r> DivRemAssign<&'r ConstDivisor> for UBig

source§

impl<'a> IntoRing<'a, ConstDivisor> for IBig

§

type RingElement = Reduced<'a>

source§

fn into_ring(self, ring: &ConstDivisor) -> Reduced<'_>

source§

impl<'a> IntoRing<'a, ConstDivisor> for UBig

§

type RingElement = Reduced<'a>

source§

fn into_ring(self, ring: &ConstDivisor) -> Reduced<'_>

source§

impl<'a> IntoRing<'a, ConstDivisor> for bool

§

type RingElement = Reduced<'a>

source§

fn into_ring(self, ring: &'a ConstDivisor) -> Reduced<'a>

source§

impl<'a> IntoRing<'a, ConstDivisor> for i128

§

type RingElement = Reduced<'a>

source§

fn into_ring(self, ring: &'a ConstDivisor) -> Reduced<'a>

source§

impl<'a> IntoRing<'a, ConstDivisor> for i16

§

type RingElement = Reduced<'a>

source§

fn into_ring(self, ring: &'a ConstDivisor) -> Reduced<'a>

source§

impl<'a> IntoRing<'a, ConstDivisor> for i32

§

type RingElement = Reduced<'a>

source§

fn into_ring(self, ring: &'a ConstDivisor) -> Reduced<'a>

source§

impl<'a> IntoRing<'a, ConstDivisor> for i64

§

type RingElement = Reduced<'a>

source§

fn into_ring(self, ring: &'a ConstDivisor) -> Reduced<'a>

source§

impl<'a> IntoRing<'a, ConstDivisor> for i8

§

type RingElement = Reduced<'a>

source§

fn into_ring(self, ring: &'a ConstDivisor) -> Reduced<'a>

source§

impl<'a> IntoRing<'a, ConstDivisor> for isize

§

type RingElement = Reduced<'a>

source§

fn into_ring(self, ring: &'a ConstDivisor) -> Reduced<'a>

source§

impl<'a> IntoRing<'a, ConstDivisor> for u128

§

type RingElement = Reduced<'a>

source§

fn into_ring(self, ring: &'a ConstDivisor) -> Reduced<'a>

source§

impl<'a> IntoRing<'a, ConstDivisor> for u16

§

type RingElement = Reduced<'a>

source§

fn into_ring(self, ring: &'a ConstDivisor) -> Reduced<'a>

source§

impl<'a> IntoRing<'a, ConstDivisor> for u32

§

type RingElement = Reduced<'a>

source§

fn into_ring(self, ring: &'a ConstDivisor) -> Reduced<'a>

source§

impl<'a> IntoRing<'a, ConstDivisor> for u64

§

type RingElement = Reduced<'a>

source§

fn into_ring(self, ring: &'a ConstDivisor) -> Reduced<'a>

source§

impl<'a> IntoRing<'a, ConstDivisor> for u8

§

type RingElement = Reduced<'a>

source§

fn into_ring(self, ring: &'a ConstDivisor) -> Reduced<'a>

source§

impl<'a> IntoRing<'a, ConstDivisor> for usize

§

type RingElement = Reduced<'a>

source§

fn into_ring(self, ring: &'a ConstDivisor) -> Reduced<'a>

source§

impl PartialEq<ConstDivisor> for ConstDivisor

source§

fn eq(&self, other: &ConstDivisor) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Reducer<UBig> for ConstDivisor

source§

fn new(m: &UBig) -> Self

Create a reducer for a modulus m
source§

fn transform(&self, target: UBig) -> UBig

Transform a normal integer into reduced form
source§

fn check(&self, target: &UBig) -> bool

Check whether target is a valid reduced form
source§

fn modulus(&self) -> UBig

Get the modulus in original integer type
source§

fn residue(&self, target: UBig) -> UBig

Transform a reduced form back to normal integer
source§

fn is_zero(&self, target: &UBig) -> bool

Test if the residue() == 0
source§

fn add(&self, lhs: &UBig, rhs: &UBig) -> UBig

Calculate (lhs + rhs) mod m in reduced form
source§

fn dbl(&self, target: UBig) -> UBig

Calculate 2*target mod m
source§

fn sub(&self, lhs: &UBig, rhs: &UBig) -> UBig

Calculate (lhs - rhs) mod m in reduced form
source§

fn neg(&self, target: UBig) -> UBig

Calculate -monty mod m in reduced form
source§

fn mul(&self, lhs: &UBig, rhs: &UBig) -> UBig

Calculate (lhs * rhs) mod m in reduced form
source§

fn sqr(&self, target: UBig) -> UBig

Calculate target^2 mod m in reduced form
source§

fn inv(&self, target: UBig) -> Option<UBig>

Calculate target^-1 mod m in reduced form, it may return None when there is no modular inverse.
source§

fn pow(&self, base: UBig, exp: &UBig) -> UBig

Calculate base ^ exp mod m in reduced form
source§

fn add_in_place(&self, lhs: &mut T, rhs: &T)

source§

fn sub_in_place(&self, lhs: &mut T, rhs: &T)

source§

fn mul_in_place(&self, lhs: &mut T, rhs: &T)

source§

impl<'l, 'r> Rem<&'r ConstDivisor> for &'l IBig

§

type Output = IBig

The resulting type after applying the % operator.
source§

fn rem(self, rhs: &ConstDivisor) -> IBig

Performs the % operation. Read more
source§

impl<'l, 'r> Rem<&'r ConstDivisor> for &'l UBig

§

type Output = UBig

The resulting type after applying the % operator.
source§

fn rem(self, rhs: &ConstDivisor) -> UBig

Performs the % operation. Read more
source§

impl<'r> Rem<&'r ConstDivisor> for IBig

§

type Output = IBig

The resulting type after applying the % operator.
source§

fn rem(self, rhs: &ConstDivisor) -> IBig

Performs the % operation. Read more
source§

impl<'r> Rem<&'r ConstDivisor> for UBig

§

type Output = UBig

The resulting type after applying the % operator.
source§

fn rem(self, rhs: &ConstDivisor) -> UBig

Performs the % operation. Read more
source§

impl<'r> RemAssign<&'r ConstDivisor> for IBig

source§

fn rem_assign(&mut self, rhs: &'r ConstDivisor)

Performs the %= operation. Read more
source§

impl<'r> RemAssign<&'r ConstDivisor> for UBig

source§

fn rem_assign(&mut self, rhs: &'r ConstDivisor)

Performs the %= operation. Read more
source§

impl Eq for ConstDivisor

source§

impl StructuralEq for ConstDivisor

source§

impl StructuralPartialEq for ConstDivisor

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.