[−][src]Trait arithmetic_eval::arith::Arithmetic
Encapsulates arithmetic operations on a certain number type.
Unlike operations on built-in integer types, arithmetic operations may be fallible.
Additionally, the arithmetic can have a state. This is used, for example, in
ModularArithmetic
, which stores the modulus in the state.
Required methods
pub fn add(&self, x: T, y: T) -> Result<T, ArithmeticError>
[src]
Adds two numbers.
Errors
Returns an error if the operation is unsuccessful (e.g., on integer overflow).
pub fn sub(&self, x: T, y: T) -> Result<T, ArithmeticError>
[src]
Subtracts two numbers.
Errors
Returns an error if the operation is unsuccessful (e.g., on integer underflow).
pub fn mul(&self, x: T, y: T) -> Result<T, ArithmeticError>
[src]
Multiplies two numbers.
Errors
Returns an error if the operation is unsuccessful (e.g., on integer overflow).
pub fn div(&self, x: T, y: T) -> Result<T, ArithmeticError>
[src]
Divides two numbers.
Errors
Returns an error if the operation is unsuccessful (e.g., if y
is zero or does
not have a multiplicative inverse in the case of modular arithmetic).
pub fn pow(&self, x: T, y: T) -> Result<T, ArithmeticError>
[src]
Raises x
to the power of y
.
Errors
Returns an error if the operation is unsuccessful (e.g., on integer overflow).
pub fn neg(&self, x: T) -> Result<T, ArithmeticError>
[src]
Negates a number.
Errors
Returns an error if the operation is unsuccessful (e.g., on integer overflow).
pub fn eq(&self, x: &T, y: &T) -> bool
[src]
Checks if two numbers are equal. Note that equality can be a non-trivial operation; e.g., different numbers may be equal as per modular arithmetic.
Implementors
impl Arithmetic<BigUint> for ModularArithmetic<BigUint>
[src]
pub fn add(&self, x: BigUint, y: BigUint) -> Result<BigUint, ArithmeticError>
[src]
pub fn sub(&self, x: BigUint, y: BigUint) -> Result<BigUint, ArithmeticError>
[src]
pub fn mul(&self, x: BigUint, y: BigUint) -> Result<BigUint, ArithmeticError>
[src]
pub fn div(&self, x: BigUint, y: BigUint) -> Result<BigUint, ArithmeticError>
[src]
pub fn pow(&self, x: BigUint, y: BigUint) -> Result<BigUint, ArithmeticError>
[src]
pub fn neg(&self, x: BigUint) -> Result<BigUint, ArithmeticError>
[src]
pub fn eq(&self, x: &BigUint, y: &BigUint) -> bool
[src]
impl<T> Arithmetic<T> for ModularArithmetic<T> where
T: Copy + PartialEq + NumOps + Zero + One + DoubleWidth,
usize: TryFrom<T>,
[src]
T: Copy + PartialEq + NumOps + Zero + One + DoubleWidth,
usize: TryFrom<T>,
pub fn add(&self, x: T, y: T) -> Result<T, ArithmeticError>
[src]
pub fn sub(&self, x: T, y: T) -> Result<T, ArithmeticError>
[src]
pub fn mul(&self, x: T, y: T) -> Result<T, ArithmeticError>
[src]
pub fn div(&self, x: T, y: T) -> Result<T, ArithmeticError>
[src]
pub fn pow(&self, x: T, y: T) -> Result<T, ArithmeticError>
[src]
pub fn neg(&self, x: T) -> Result<T, ArithmeticError>
[src]
pub fn eq(&self, x: &T, y: &T) -> bool
[src]
impl<T> Arithmetic<T> for StdArithmetic where
T: Clone + NumOps + PartialEq + Neg<Output = T> + Pow<T, Output = T>,
[src]
T: Clone + NumOps + PartialEq + Neg<Output = T> + Pow<T, Output = T>,
pub fn add(&self, x: T, y: T) -> Result<T, ArithmeticError>
[src]
pub fn sub(&self, x: T, y: T) -> Result<T, ArithmeticError>
[src]
pub fn mul(&self, x: T, y: T) -> Result<T, ArithmeticError>
[src]
pub fn div(&self, x: T, y: T) -> Result<T, ArithmeticError>
[src]
pub fn pow(&self, x: T, y: T) -> Result<T, ArithmeticError>
[src]
pub fn neg(&self, x: T) -> Result<T, ArithmeticError>
[src]
pub fn eq(&self, x: &T, y: &T) -> bool
[src]
impl<T> Arithmetic<T> for WrappingArithmetic where
T: Copy + PartialEq + Zero + One + WrappingAdd + WrappingSub + WrappingMul + WrappingNeg + Div<T, Output = T>,
usize: TryFrom<T>,
[src]
T: Copy + PartialEq + Zero + One + WrappingAdd + WrappingSub + WrappingMul + WrappingNeg + Div<T, Output = T>,
usize: TryFrom<T>,
pub fn add(&self, x: T, y: T) -> Result<T, ArithmeticError>
[src]
pub fn sub(&self, x: T, y: T) -> Result<T, ArithmeticError>
[src]
pub fn mul(&self, x: T, y: T) -> Result<T, ArithmeticError>
[src]
pub fn div(&self, x: T, y: T) -> Result<T, ArithmeticError>
[src]
pub fn pow(&self, x: T, y: T) -> Result<T, ArithmeticError>
[src]
pub fn neg(&self, x: T) -> Result<T, ArithmeticError>
[src]
pub fn eq(&self, x: &T, y: &T) -> bool
[src]
impl<T, A> Arithmetic<T> for FullArithmetic<T, A> where
A: Arithmetic<T>,
[src]
A: Arithmetic<T>,
pub fn add(&self, x: T, y: T) -> Result<T, ArithmeticError>
[src]
pub fn sub(&self, x: T, y: T) -> Result<T, ArithmeticError>
[src]
pub fn mul(&self, x: T, y: T) -> Result<T, ArithmeticError>
[src]
pub fn div(&self, x: T, y: T) -> Result<T, ArithmeticError>
[src]
pub fn pow(&self, x: T, y: T) -> Result<T, ArithmeticError>
[src]
pub fn neg(&self, x: T) -> Result<T, ArithmeticError>
[src]
pub fn eq(&self, x: &T, y: &T) -> bool
[src]
impl<T, Kind> Arithmetic<T> for CheckedArithmetic<Kind> where
T: Clone + PartialEq + Zero + One + CheckedAdd + CheckedSub + CheckedMul + CheckedDiv,
Kind: CheckedArithmeticKind<T>,
usize: TryFrom<T>,
[src]
T: Clone + PartialEq + Zero + One + CheckedAdd + CheckedSub + CheckedMul + CheckedDiv,
Kind: CheckedArithmeticKind<T>,
usize: TryFrom<T>,