Struct ConstDivisor

Source
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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

impl PartialEq for ConstDivisor

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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

Source§

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

Source§

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

Source§

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

Source§

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 StructuralPartialEq for ConstDivisor

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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 T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

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

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.