Trait Ring
Source pub trait Ring: Semiring {
// Required method
fn subtract(a: Self, b: Self) -> Self;
}
Expand description
A type class for types that extend Semiring with subtraction.
§Laws
- Additive inverse:
subtract(a, a) = zero
- Compatibility:
subtract(a, b) = add(a, negate(b))
§Examples
use fp_library::classes::{
Ring,
Semiring,
};
assert_eq!(i32::subtract(5, 5), i32::zero());
Subtracts the second value from the first.
§Type Signature
(Self, Self) -> Self
§Parameters
a: The value to subtract from.
b: The value to subtract.
§Returns
The difference.
§Examples
use fp_library::classes::Ring;
assert_eq!(i32::subtract(5, 3), 2);
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Subtracts using the - operator.
§Type Signature
(Self, Self) -> Self
§Parameters
a: The value to subtract from.
b: The value to subtract.
§Returns
The difference.
§Examples
use fp_library::classes::Ring;
assert_eq!(<f32>::subtract(5.0 as f32, 3.0 as f32), 2.0 as f32);
Subtracts using the - operator.
§Type Signature
(Self, Self) -> Self
§Parameters
a: The value to subtract from.
b: The value to subtract.
§Returns
The difference.
§Examples
use fp_library::classes::Ring;
assert_eq!(<f64>::subtract(5.0 as f64, 3.0 as f64), 2.0 as f64);
Subtracts using wrapping subtraction.
§Type Signature
(Self, Self) -> Self
§Parameters
a: The value to subtract from.
b: The value to subtract.
§Returns
The difference (wrapping on overflow).
§Examples
use fp_library::classes::Ring;
assert_eq!(<i8>::subtract(5 as i8, 3 as i8), 2 as i8);
Subtracts using wrapping subtraction.
§Type Signature
(Self, Self) -> Self
§Parameters
a: The value to subtract from.
b: The value to subtract.
§Returns
The difference (wrapping on overflow).
§Examples
use fp_library::classes::Ring;
assert_eq!(<i16>::subtract(5 as i16, 3 as i16), 2 as i16);
Subtracts using wrapping subtraction.
§Type Signature
(Self, Self) -> Self
§Parameters
a: The value to subtract from.
b: The value to subtract.
§Returns
The difference (wrapping on overflow).
§Examples
use fp_library::classes::Ring;
assert_eq!(<i32>::subtract(5 as i32, 3 as i32), 2 as i32);
Subtracts using wrapping subtraction.
§Type Signature
(Self, Self) -> Self
§Parameters
a: The value to subtract from.
b: The value to subtract.
§Returns
The difference (wrapping on overflow).
§Examples
use fp_library::classes::Ring;
assert_eq!(<i64>::subtract(5 as i64, 3 as i64), 2 as i64);
Subtracts using wrapping subtraction.
§Type Signature
(Self, Self) -> Self
§Parameters
a: The value to subtract from.
b: The value to subtract.
§Returns
The difference (wrapping on overflow).
§Examples
use fp_library::classes::Ring;
assert_eq!(<i128>::subtract(5 as i128, 3 as i128), 2 as i128);
Subtracts using wrapping subtraction.
§Type Signature
(Self, Self) -> Self
§Parameters
a: The value to subtract from.
b: The value to subtract.
§Returns
The difference (wrapping on overflow).
§Examples
use fp_library::classes::Ring;
assert_eq!(<isize>::subtract(5 as isize, 3 as isize), 2 as isize);