simba/scalar/
field.rs

1use crate::simd::SimdValue;
2use num::NumAssign;
3pub use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Rem, Sub, SubAssign};
4
5/// Trait __alias__ for `Add` and `AddAssign` with result of type `Self`.
6pub trait ClosedAdd<Right = Self>: Sized + Add<Right, Output = Self> + AddAssign<Right> {}
7
8/// Trait __alias__ for `Sub` and `SubAssign` with result of type `Self`.
9pub trait ClosedSub<Right = Self>: Sized + Sub<Right, Output = Self> + SubAssign<Right> {}
10
11/// Trait __alias__ for `Mul` and `MulAssign` with result of type `Self`.
12pub trait ClosedMul<Right = Self>: Sized + Mul<Right, Output = Self> + MulAssign<Right> {}
13
14/// Trait __alias__ for `Div` and `DivAssign` with result of type `Self`.
15pub trait ClosedDiv<Right = Self>: Sized + Div<Right, Output = Self> + DivAssign<Right> {}
16
17/// Trait __alias__ for `Neg` with result of type `Self`.
18pub trait ClosedNeg: Sized + Neg<Output = Self> {}
19
20impl<T, Right> ClosedAdd<Right> for T where T: Add<Right, Output = T> + AddAssign<Right> {}
21impl<T, Right> ClosedSub<Right> for T where T: Sub<Right, Output = T> + SubAssign<Right> {}
22impl<T, Right> ClosedMul<Right> for T where T: Mul<Right, Output = T> + MulAssign<Right> {}
23impl<T, Right> ClosedDiv<Right> for T where T: Div<Right, Output = T> + DivAssign<Right> {}
24impl<T> ClosedNeg for T where T: Neg<Output = T> {}
25
26/// Trait implemented by fields, i.e., complex numbers and floats.
27pub trait Field: SimdValue + NumAssign + ClosedNeg {}
28
29impl<N: SimdValue + Clone + NumAssign + ClosedNeg> Field for num_complex::Complex<N> {}
30
31macro_rules! impl_field(
32    ($($t: ty),*) => {$(
33        impl Field for $t {}
34    )*}
35);
36
37impl_field!(f32, f64);
38//#[cfg(feature = "decimal")]
39//impl_field!(decimal::d128);