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
5pub trait ClosedAdd<Right = Self>: Sized + Add<Right, Output = Self> + AddAssign<Right> {}
7
8pub trait ClosedSub<Right = Self>: Sized + Sub<Right, Output = Self> + SubAssign<Right> {}
10
11pub trait ClosedMul<Right = Self>: Sized + Mul<Right, Output = Self> + MulAssign<Right> {}
13
14pub trait ClosedDiv<Right = Self>: Sized + Div<Right, Output = Self> + DivAssign<Right> {}
16
17pub 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
26pub 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