2
2
3
3
#include < fftw-cpp/fftw-cpp.h>
4
4
#include < gmock/gmock.h>
5
- #include < tuple>
6
5
#include < iomanip>
6
+ #include < tuple>
7
7
8
8
// Function to slice the tuple
9
9
template <std::size_t Start, std::size_t End, typename Tuple, std::size_t ... Indices>
@@ -21,11 +21,19 @@ template <std::size_t Start, typename... Args> auto slice(const std::tuple<Args.
21
21
return slice<Start, sizeof ...(Args)>(t);
22
22
}
23
23
24
+ template <typename T> T absdiff_no_overflow (T a, T b) { return std::max (a, b) - std::min (a, b); }
25
+
26
+ template <typename T> T absdiff_no_overflow (std::complex <T> a, std::complex <T> b) {
27
+ auto const real_diff = absdiff_no_overflow (a.real (), b.real ());
28
+ auto const imag_diff = absdiff_no_overflow (a.imag (), b.imag ());
29
+ return std::abs (std::complex <T>{real_diff, imag_diff});
30
+ }
31
+
24
32
using ::testing::PrintToString;
25
33
MATCHER_P3 (AllClose, val, rel_tol, abs_tol,
26
34
PrintToString (val) + " ±" + PrintToString(abs_tol) + " (±" +
27
35
PrintToString(double(rel_tol) * std::abs(val)) + " )") {
28
- auto diff = std::max (arg, val) - std::min (arg, val );
36
+ auto diff = absdiff_no_overflow ( val, arg );
29
37
double tolerance_diff = double (diff) - double (abs_tol) - double (rel_tol) * std::abs (val);
30
38
return tolerance_diff <= 0 ;
31
39
}
0 commit comments