Go to the documentation of this file.
5 #ifndef UAVCAN_UTIL_COMPARISON_HPP_INCLUDED
6 #define UAVCAN_UTIL_COMPARISON_HPP_INCLUDED
20 return (left <= right) && (left >= right);
31 inline bool areFloatsClose(T a, T b,
const T& absolute_epsilon,
const T& relative_epsilon)
46 const T diff = std::fabs(a - b);
47 if (diff <= absolute_epsilon)
55 const T largest = (b > a) ? b : a;
56 return (diff <= largest * relative_epsilon);
63 namespace are_close_impl_
69 template <
typename This,
typename Rhs>
72 template <
typename U,
typename R,
bool (U::*)(const R&) const>
struct ConstRef { };
73 template <
typename U,
typename R,
bool (U::*)(R) const>
struct ByValue { };
84 template <
typename L,
typename R>
88 return left.isClose(right);
92 template <
typename L,
typename R>
96 return right.isClose(left);
100 template <
typename L,
typename R>
104 return left == right;
108 template <
typename L,
typename R>
156 template <
typename L,
typename R>
158 inline bool areClose(
const L& left,
const R& right)
187 return areFloatsClose(left, right, NumericTraits<long double>::epsilon(),
198 return areClose(left,
static_cast<float>(right));
205 return areClose(
static_cast<float>(left), right);
212 return areClose(left,
static_cast<float>(right));
219 return areClose(
static_cast<float>(left), right);
226 return areClose(left,
static_cast<double>(right));
233 return areClose(
static_cast<double>(left), right);
241 template <
typename T>
252 return areClose(
x,
static_cast<float>(0.0F));
259 return areClose(
x,
static_cast<double>(0.0));
266 return areClose(
x,
static_cast<long double>(0.0L));
271 #endif // UAVCAN_UTIL_COMPARISON_HPP_INCLUDED
static const unsigned FloatComparisonEpsilonMult
UAVCAN_EXPORT bool areCloseImplSecond(const L &left, const R &right, IntToType< sizeof(Applicable)>)
Second stage: bool R::isClose(L)
UAVCAN_EXPORT bool areFloatsExactlyEqual(const T &left, const T &right)
UAVCAN_EXPORT bool areClose< double, double >(const double &left, const double &right)
UAVCAN_EXPORT bool areClose< float, float >(const float &left, const float &right)
UAVCAN_EXPORT bool areClose< float, double >(const float &left, const double &right)
UAVCAN_EXPORT bool areClose< double, long double >(const double &left, const long double &right)
static Applicable test(ConstRef< U, R, &U::isClose > *)
UAVCAN_EXPORT bool areClose(const L &left, const R &right)
UAVCAN_EXPORT bool areClose< double, float >(const double &left, const float &right)
UAVCAN_EXPORT bool areClose< float, long double >(const float &left, const long double &right)
UAVCAN_EXPORT bool areClose< long double, long double >(const long double &left, const long double &right)
UAVCAN_EXPORT bool isCloseToZero< double >(const double &x)
UAVCAN_EXPORT bool areCloseImplFirst(const L &left, const R &right, IntToType< sizeof(Applicable)>)
First stage: bool L::isClose(R)
UAVCAN_EXPORT bool isCloseToZero< float >(const float &x)
UAVCAN_EXPORT bool areClose< long double, double >(const long double &left, const double &right)
UAVCAN_EXPORT bool areClose< long double, float >(const long double &left, const float &right)
UAVCAN_EXPORT bool areFloatsClose(T a, T b, const T &absolute_epsilon, const T &relative_epsilon)
UAVCAN_EXPORT bool isCloseToZero< long double >(const long double &x)
UAVCAN_EXPORT bool isCloseToZero(const T &x)