1use crate::simd::SimdValue;
2use num::NumAssign;
3pub use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
4
5pub trait ClosedAdd<Right = Self>: Sized + Add<Right, Output = Self> {}
7
8pub trait ClosedSub<Right = Self>: Sized + Sub<Right, Output = Self> {}
10
11pub trait ClosedMul<Right = Self>: Sized + Mul<Right, Output = Self> {}
13
14pub trait ClosedDiv<Right = Self>: Sized + Div<Right, Output = Self> {}
16
17pub trait ClosedNeg: Sized + Neg<Output = Self> {}
19
20pub trait ClosedAddAssign<Right = Self>: ClosedAdd<Right> + AddAssign<Right> {}
22
23pub trait ClosedSubAssign<Right = Self>: ClosedSub<Right> + SubAssign<Right> {}
25
26pub trait ClosedMulAssign<Right = Self>: ClosedMul<Right> + MulAssign<Right> {}
28
29pub 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
50pub 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