1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
use crate::core::math::ArgminSub;
use num_complex::Complex;
macro_rules! make_sub {
($t:ty) => {
impl ArgminSub<$t, $t> for $t {
#[inline]
fn sub(&self, other: &$t) -> $t {
self - other
}
}
};
}
make_sub!(isize);
make_sub!(usize);
make_sub!(i8);
make_sub!(i16);
make_sub!(i32);
make_sub!(i64);
make_sub!(u8);
make_sub!(u16);
make_sub!(u32);
make_sub!(u64);
make_sub!(f32);
make_sub!(f64);
make_sub!(Complex<isize>);
make_sub!(Complex<usize>);
make_sub!(Complex<i8>);
make_sub!(Complex<i16>);
make_sub!(Complex<i32>);
make_sub!(Complex<i64>);
make_sub!(Complex<u8>);
make_sub!(Complex<u16>);
make_sub!(Complex<u32>);
make_sub!(Complex<u64>);
make_sub!(Complex<f32>);
make_sub!(Complex<f64>);
#[cfg(test)]
mod tests {
use super::*;
use paste::item;
macro_rules! make_test {
($t:ty) => {
item! {
#[test]
fn [<test_sub_ $t>]() {
let a = 50 as $t;
let b = 8 as $t;
let res = <$t as ArgminSub<$t, $t>>::sub(&a, &b);
assert!(((42 as $t - res) as f64).abs() < std::f64::EPSILON);
}
}
};
}
make_test!(isize);
make_test!(usize);
make_test!(i8);
make_test!(u8);
make_test!(i16);
make_test!(u16);
make_test!(i32);
make_test!(u32);
make_test!(i64);
make_test!(u64);
make_test!(f32);
make_test!(f64);
}