Expand description
Primitive traits for the runtime arithmetic.
Traits§
- AtLeast8
Bit - A meta trait for arithmetic.
- AtLeast8
BitUnsigned - A meta trait for arithmetic. Same as
AtLeast8Bit, but also bounded to be unsigned. - AtLeast16
Bit - A meta trait for arithmetic.
- AtLeast16
BitUnsigned - A meta trait for arithmetic. Same as
AtLeast16Bit, but also bounded to be unsigned. - AtLeast32
Bit - A meta trait for arithmetic.
- AtLeast32
BitUnsigned - A meta trait for arithmetic. Same as
AtLeast32Bit, but also bounded to be unsigned. - Base
Arithmetic - A meta trait for arithmetic type operations, regardless of any limitation on size.
- Bounded
- Numbers which have upper and lower bounds
- Checked
Add - Performs addition that returns
Noneinstead of wrapping around on overflow. - Checked
Div - Performs division that returns
Noneinstead of panicking on division by zero and instead of wrapping around on underflow and overflow. - Checked
Mul - Performs multiplication that returns
Noneinstead of wrapping around on underflow or overflow. - Checked
Neg - Performs negation that returns
Noneif the result can’t be represented. - Checked
Rem - Performs an integral remainder that returns
Noneinstead of panicking on division by zero and instead of wrapping around on underflow and overflow. - Checked
Shl - Performs a left shift that returns
Noneon shifts larger than or equal to the type width. - Checked
Shr - Performs a right shift that returns
Noneon shifts larger than or equal to the type width. - Checked
Sub - Performs subtraction that returns
Noneinstead of wrapping around on underflow. - Ensure
- Ensure
Add - Performs addition that returns
ArithmeticErrorinstead of wrapping around on overflow. - Ensure
AddAssign - Performs self addition that returns
ArithmeticErrorinstead of wrapping around on overflow. - Ensure
Div - Performs division that returns
ArithmeticErrorinstead of wrapping around on overflow. - Ensure
DivAssign - Performs self division that returns
ArithmeticErrorinstead of wrapping around on overflow. - Ensure
Fixed Point Number - Extends
FixedPointNumberwith the Ensure family functions. - Ensure
From - Similar to
TryFrombut returning anArithmeticErrorerror. - Ensure
Into - Similar to
TryIntobut returning anArithmeticErrorerror. - Ensure
Mul - Performs multiplication that returns
ArithmeticErrorinstead of wrapping around on overflow. - Ensure
MulAssign - Performs self multiplication that returns
ArithmeticErrorinstead of wrapping around on overflow. - Ensure
Op - Meta trait that supports all immutable arithmetic
Ensure*operations - Ensure
OpAssign - Meta trait that supports all assigned arithmetic
Ensure*operations - Ensure
Sub - Performs subtraction that returns
ArithmeticErrorinstead of wrapping around on underflow. - Ensure
SubAssign - Performs self subtraction that returns
ArithmeticErrorinstead of wrapping around on underflow. - Integer
Square Root - A trait implementing integer square root.
- One
- Defines a multiplicative identity element for
Self. - Saturated
Conversion - Convenience type to work around the highly unergonomic syntax needed
to invoke the functions of overloaded generic traits, in this case
SaturatedFromandSaturatedInto. - Saturating
- Saturating arithmetic operations, returning maximum or minimum values instead of overflowing.
- Signed
- Useful functions for signed numbers (i.e. numbers that can be negative).
- Unique
Saturated From - Just like
Fromexcept that if the source value is too big to fit into the destination type then it’ll saturate the destination. - Unique
Saturated Into - Just like
Intoexcept that if the source value is too big to fit into the destination type then it’ll saturate the destination. - Unsigned
- A trait for values which cannot be negative
- Zero
- Defines an additive identity element for
Self.
Functions§
- checked_
pow - Raises a value to the power of exp, returning
Noneif an overflow occurred. - ensure_
pow - Raises a value to the power of exp, returning
ArithmeticErrorif an overflow occurred.