17 #ifndef OPENKALMAN_VALUES_NEAR_HPP 18 #define OPENKALMAN_VALUES_NEAR_HPP 39 template<
unsigned int epsilon_factor = 2, value Arg1, value Arg2>
40 constexpr OpenKalman::internal::boolean_testable
auto 42 template<
unsigned int epsilon_factor = 2,
typename Arg1,
typename Arg2,
43 std::enable_if_t<value<Arg1> and value<Arg2>,
int> = 0>
46 near(
const Arg1& arg1,
const Arg2& arg2)
48 if constexpr (fixed<Arg1> or fixed<Arg2>)
51 {
return near<epsilon_factor>(a1, a2); } };
54 else if constexpr (complex<Arg1> or complex<Arg2>)
58 near<epsilon_factor>(
real(arg1),
real(arg2)),
59 near<epsilon_factor>(
imag(arg1),
imag(arg2)));
63 auto diff = arg1 - arg2;
64 using Diff = decltype(diff);
65 auto ep =
static_cast<Diff
>(epsilon_factor * std::numeric_limits<Diff>::epsilon());
66 return -ep <= diff and diff <= ep;
79 template<value Arg1, value Arg2, value Err>
80 constexpr OpenKalman::internal::boolean_testable
auto 82 template<
typename Arg1,
typename Arg2,
typename Err,
83 std::enable_if_t<value<Arg1> and value<Arg2> and value<Err>,
int> = 0>
86 near(
const Arg1& arg1,
const Arg2& arg2,
const Err& err)
88 if constexpr (fixed<Arg1> or fixed<Arg2>)
90 struct Op { constexpr
auto operator()(
94 {
return near(a1, a2, e); } };
97 else if constexpr (complex<Arg1> or complex<Arg2> or complex<Err>)
103 return dr * dr + di * di <= er * er + ei * ei;
107 auto diff = arg1 - arg2;
108 using Diff = decltype(diff);
109 auto ep =
static_cast<Diff
>(err);
110 return -ep <= diff and diff <= ep;
typename value_type_of< T >::type value_type_of_t
Helper template for value_type_of.
Definition: value_type_of.hpp:52
constexpr auto imag(const Arg &arg)
A constexpr function to obtain the imaginary part of a (complex) number.
Definition: imag.hpp:40
Definition for values::imag.
constexpr auto near(const Arg1 &arg1, const Arg2 &arg2)
Determine whether two numbers are within a rounding tolerance.
Definition: near.hpp:46
Definition of utilities for atan functions.
Definition: fixed.hpp:24
Definition for value:value_type_of and value:value_type_of_t.
constexpr auto real(const Arg &arg)
A constexpr function to obtain the real part of a (complex) number.
Definition: real.hpp:40
Basic definitions for OpenKalman as a whole.
Definition for values::real.
constexpr auto operation(Operation &&op, Args &&...args)
A potentially constant-evaluated operation involving some number of values.
Definition: operation.hpp:98
Definition for values::complex.
Definition for values::value.