pub trait Number: Primitive + Copy + NumCast + AlertingAbs + NumOps + SaturatingAdd + SaturatingMul + InfAdd + InfSub + InfMul + InfDiv + ProductOrd + Zero + One + PartialEq + AddAssign + SubAssign + MulAssign + DivAssign + FiniteBounds + ExactIntCast<usize> + ExactIntCast<i32> + InfCast<IntDistance> + InfCast<usize> + Sum<Self> + for<'a> Sum<&'a Self> + DistanceConstant<Self> { }
Expand description
The subset of Primitive
types that have numerical operations.
Examples: u8, u16, u32, u64, u128, i8, i16, i32, i64, i128, usize, f32, f64
This trait lists many traits that are implemented for numerical types. It is a shorthand to provide broad numerical functionality to a generic type, without polluting trait bounds with a large number of highly-specific traits.
Refer to the constituent traits to see proof definitions on methods.
§Example
use opendp::traits::Number;
fn test_func<T: Number>(value: T) {
// can be debugged, as Number inherits all traits from Primitive:
println!("{value:?}");
// supports basic arithmetic and numerical properties
assert_eq!(T::zero().inf_mul(&value).ok(), Some(T::zero()));
}
test_func(1i8);
Object Safety§
This trait is not object safe.