simba/scalar/
field.rs

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