Wayverb
almost_equal.h
1 #pragma once
2 
3 #include "glm/glm.hpp"
4 
5 namespace wayverb {
6 namespace core {
7 
8 template <typename T, typename U>
9 inline bool within_tolerance(T a, U tolerance) {
10  return std::abs(a) <= tolerance;
11 }
12 
13 template <
14  class T,
15  typename std::enable_if_t<!std::numeric_limits<T>::is_integer, int> = 0>
16 constexpr bool almost_equal(T x, T y, size_t ulp) {
17  // from cppreference.com on epsilon
18  const auto abs_diff = std::abs(x - y);
19  return abs_diff <
20  std::numeric_limits<T>::epsilon() * std::abs(x + y) * ulp ||
21  abs_diff < std::numeric_limits<T>::min();
22 }
23 
24 template <typename T>
25 inline bool nearby(const T& a, const T& b, double dist) {
26  return glm::distance(a, b) <= dist;
27 }
28 
29 } // namespace core
30 } // namespace wayverb
Definition: traits.cpp:2
Definition: capsule_base.h:9