Euphoria
approx.cc
Go to the documentation of this file.
1 #include "tests/approx.h"
2 
3 namespace
4 {
5  // Performs equivalent check of std::fabs(lhs - rhs) <= margin
6  // But without the subtraction to allow for INFINITY in comparison
7  bool
8  margin_comparison(float lhs, float rhs, float margin)
9  {
10  return (lhs + margin >= rhs) && (rhs + margin >= lhs);
11  }
12 }
13 
14 
15 namespace eu::tests
16 {
17  template <>
18  bool
20  (
21  float const& lhs,
22  float const& rhs,
23  const ApproxData& data
24  )
25  {
26  const auto m_value = lhs;
27  const auto other = rhs;
28  const auto m_epsilon = data.epsilon;
29  const auto m_margin = data.margin;
30  const auto m_scale = data.scale;
31 
32  // implementation:
33 
34  // First try with fixed margin, then compute margin based on epsilon, scale and Approx's value
35  // Thanks to Richard Harris for his help refining the scaled margin value
36  return
37  margin_comparison(m_value, other, m_margin)
38  ||
39  margin_comparison
40  (
41  m_value,
42  other,
43  m_epsilon * (m_scale + std::fabs(m_value))
44  )
45  ;
46  }
47 }
constexpr float fabs(float t)
Definition: easing.cc:30
bool is_approximately_equal(float const &lhs, float const &rhs, const ApproxData &data)
Definition: approx.cc:20