Trait ArithmeticOps
Source pub trait ArithmeticOps {
// Required methods
fn add(&self, other: &Self) -> Result<Self, String>
where Self: Sized;
fn subtract(&self, other: &Self) -> Result<Self, String>
where Self: Sized;
fn multiply(&self, other: &Self) -> Result<Self, String>
where Self: Sized;
fn divide(&self, other: &Self) -> Result<Self, String>
where Self: Sized;
fn negate(&self) -> Result<Self, String>
where Self: Sized;
}
Expand description
Arithmetic operations on values
Adds two values and returns the result.
§Arguments
other
- The other value to add
§Returns
- The result of the addition
- An error message if the types are incompatible
Subtracts one value from another and returns the result.
§Arguments
other
- The value to subtract
§Returns
- The result of the subtraction
- An error message if the types are incompatible or if an underflow occurs
Multiplies two values and returns the result.
§Arguments
other
- The other value to multiply
§Returns
- The result of the multiplication
- An error message if the types are incompatible or if an overflow occurs
Divides one value by another and returns the result.
§Arguments
other
- The value to divide by
§Returns
- The result of the division
- An error message if the types are incompatible or if division by zero occurs
Negates a value and returns the result.
§Returns
- The negated value
- An error message if the type is incompatible, or an overflow occurs