-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEpsilon.cpp
More file actions
38 lines (31 loc) · 944 Bytes
/
Epsilon.cpp
File metadata and controls
38 lines (31 loc) · 944 Bytes
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
#ifndef _LIB_EPSILON
#define _LIB_EPSILON
#include <bits/stdc++.h>
namespace lib {
using namespace std;
template <typename T = double> struct Epsilon {
T eps;
constexpr Epsilon(T eps = 1e-9) : eps(eps) {}
template <typename G,
typename enable_if<is_floating_point<G>::value>::type * = nullptr>
int operator()(G a, G b = 0) const {
return a + eps < b ? -1 : (b + eps < a ? 1 : 0);
}
template <typename G,
typename enable_if<!is_floating_point<G>::value>::type * = nullptr>
int operator()(G a, G b = 0) const {
return a < b ? -1 : (a > b ? 1 : 0);
}
template <typename G,
typename enable_if<is_floating_point<G>::value>::type * = nullptr>
bool null(G a) const {
return (*this)(a) == 0;
}
template <typename G,
typename enable_if<!is_floating_point<G>::value>::type * = nullptr>
bool null(G a) const {
return a == 0;
}
};
} // namespace lib
#endif