[−][src]Module arithmetic_eval::arith
Arithmetic trait and its implementations.
Traits
An Arithmetic defines fallible arithmetic operations on literals
of an ExecutableModule, namely, addition, subtraction, multiplication, division,
exponentiation (all binary ops), and negation (a unary op). Any module can be run
with any Arithmetic on its literals, although some modules are reasonably tied
to a particular arithmetic or class of arithmetics (e.g., arithmetics on finite fields).
OrdArithmetic extends Arithmetic with a partial comparison operation
(i.e., an analogue to PartialOrd). This is motivated by the fact that comparisons
may be switched off during parsing, and some Arithmetics do not have well-defined comparisons.
ArithmeticExt helps converting an Arithmetic into an OrdArithmetic.
Implementations
This module defines the following kinds of arithmetics:
StdArithmetictakes all implementations from the correspondingopstraits. This means that it's safe to use provided the ops are infallible. As a counter-example, usingStdArithmeticwith built-in integer types (such asu64) is usually not a good idea since the corresponding ops have failure modes (e.g., division by zero or integer overflow).WrappingArithmeticis defined for integer types; it uses wrapping semantics for all ops.CheckedArithmeticis defined for integer types; it uses checked semantics for all ops.ModularArithmeticoperates on integers modulo the specified number.
All defined Arithmetics strive to be as generic as possible.
Structs
| Checked | Marker for |
| CheckedArithmetic | Arithmetic on an integer type (e.g., |
| FullArithmetic | Wrapper type allowing to extend an |
| ModularArithmetic | Modular arithmetic on integers. |
| NegateOnlyZero | Marker for |
| StdArithmetic | Arithmetic on a number type that implements all necessary operations natively. |
| Unchecked | Marker for |
| WrappingArithmetic | Arithmetic on an integer type (e.g., |
Traits
| Arithmetic | Encapsulates arithmetic operations on a certain number type. |
| ArithmeticExt | Extension trait for |
| CheckedArithmeticKind | Helper trait for |
| DoubleWidth | Encapsulates extension of an unsigned integer type into signed and unsigned double-width types. This allows performing certain operations (e.g., multiplication) without a possibility of integer overflow. |
| OrdArithmetic | Extends an |