17 #ifndef OPENKALMAN_ARE_WITHIN_TOLERANCE_HPP 18 #define OPENKALMAN_ARE_WITHIN_TOLERANCE_HPP 35 template<
unsigned int epsilon_factor = 2,
typename Arg1,
typename Arg2>
36 constexpr
bool near(
const Arg1& arg1,
const Arg2& arg2)
38 if constexpr (not values::number<Arg1> or not values::number<Arg2>)
42 else if constexpr (values::complex<Arg1> or values::complex<Arg2>)
46 near<epsilon_factor>(
real(arg1),
real(arg2)) and
47 near<epsilon_factor>(
imag(arg1),
imag(arg2));
49 else if (arg1 != arg1 or arg2 != arg2)
return false;
52 auto diff = arg1 - arg2;
53 using Diff = decltype(diff);
54 constexpr
auto ep = epsilon_factor * std::numeric_limits<Diff>::epsilon();
55 return -
static_cast<Diff
>(ep) <= diff and diff <= static_cast<Diff>(ep);
67 template<
typename Arg1,
typename Arg2,
typename Err>
68 constexpr
bool near(
const Arg1& arg1,
const Arg2& arg2,
const Err& err)
70 if constexpr (not values::number<Arg1> or not values::number<Arg2> or not values::number<Err>)
74 else if constexpr (values::complex<Arg1> or values::complex<Arg2> or values::complex<Err>)
81 return dr * dr + di * di <= er * er + ei * ei;
83 else if (arg1 != arg1 or arg2 != arg2)
return false;
86 auto diff = arg1 - arg2;
87 using Diff = decltype(diff);
88 return -
static_cast<Diff
>(err) <= diff and diff <= static_cast<Diff>(err);
96 #endif //OPENKALMAN_ARE_WITHIN_TOLERANCE_HPP Definition for values::to_number.
constexpr auto imag(Arg arg)
A constexpr function to obtain the imaginary part of a (complex) number.
Definition: imag.hpp:40
constexpr auto to_number(Arg arg)
Convert any values::value to a values::number.
Definition: to_number.hpp:34
Definition of utilities for atan functions.
Definition: dynamic.hpp:26
constexpr auto real(Arg arg)
A constexpr function to obtain the real part of a (complex) number.
Definition: real.hpp:40
constexpr bool near(const Arg1 &arg1, const Arg2 &arg2)
Determine whether two numbers are within a rounding tolerance.
Definition: near.hpp:36
Definition for values::number.
Definition for ::complex.