Module sp_arithmetic::traits
source · Expand description
Primitive traits for the runtime arithmetic.
Traits§
- A meta trait for arithmetic.
- A meta trait for arithmetic. Same as
AtLeast8Bit, but also bounded to be unsigned. - A meta trait for arithmetic.
- A meta trait for arithmetic. Same as
AtLeast16Bit, but also bounded to be unsigned. - A meta trait for arithmetic.
- A meta trait for arithmetic. Same as
AtLeast32Bit, but also bounded to be unsigned. - A meta trait for arithmetic type operations, regardless of any limitation on size.
- Numbers which have upper and lower bounds
- Performs addition that returns
Noneinstead of wrapping around on overflow. - Performs division that returns
Noneinstead of panicking on division by zero and instead of wrapping around on underflow and overflow. - Performs multiplication that returns
Noneinstead of wrapping around on underflow or overflow. - Performs negation that returns
Noneif the result can’t be represented. - Performs an integral remainder that returns
Noneinstead of panicking on division by zero and instead of wrapping around on underflow and overflow. - Performs a left shift that returns
Noneon shifts larger than or equal to the type width. - Performs a right shift that returns
Noneon shifts larger than or equal to the type width. - Performs subtraction that returns
Noneinstead of wrapping around on underflow. - Performs addition that returns
ArithmeticErrorinstead of wrapping around on overflow. - Performs self addition that returns
ArithmeticErrorinstead of wrapping around on overflow. - Performs division that returns
ArithmeticErrorinstead of wrapping around on overflow. - Performs self division that returns
ArithmeticErrorinstead of wrapping around on overflow. - Extends
FixedPointNumberwith the Ensure family functions. - Similar to
TryFrombut returning anArithmeticErrorerror. - Similar to
TryIntobut returning anArithmeticErrorerror. - Performs multiplication that returns
ArithmeticErrorinstead of wrapping around on overflow. - Performs self multiplication that returns
ArithmeticErrorinstead of wrapping around on overflow. - Meta trait that supports all immutable arithmetic
Ensure*operations - Meta trait that supports all assigned arithmetic
Ensure*operations - Performs subtraction that returns
ArithmeticErrorinstead of wrapping around on underflow. - Performs self subtraction that returns
ArithmeticErrorinstead of wrapping around on underflow. - A trait implementing integer square root.
- Defines a multiplicative identity element for
Self. - Convenience type to work around the highly unergonomic syntax needed to invoke the functions of overloaded generic traits, in this case
SaturatedFromandSaturatedInto. - Saturating arithmetic operations, returning maximum or minimum values instead of overflowing.
- Useful functions for signed numbers (i.e. numbers that can be negative).
- Just like
Fromexcept that if the source value is too big to fit into the destination type then it’ll saturate the destination. - Just like
Intoexcept that if the source value is too big to fit into the destination type then it’ll saturate the destination. - A trait for values which cannot be negative
- Defines an additive identity element for
Self.
Functions§
- Raises a value to the power of exp, returning
Noneif an overflow occurred. - Raises a value to the power of exp, returning
ArithmeticErrorif an overflow occurred.