All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Pages
floating.hpp
Go to the documentation of this file.
1 //=======================================================================
2 // Copyright (c) 2013 Piotr Wygocki, Maciej Andrejczuk
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //=======================================================================
14 #ifndef PAAL_FLOATING_HPP
15 #define PAAL_FLOATING_HPP
16 
17 #include <limits>
18 #include <cmath>
19 #include <random>
20 
21 namespace paal {
22 namespace utils {
23 
25 template <typename T>
26 class compare {
27  T const m_epsilon;
28 public:
30  compare(T epsilon = std::numeric_limits<T>::epsilon()): m_epsilon(epsilon) {}
31 
33  bool e(T a, T b) const {
34  return std::abs(a - b) < m_epsilon;
35  // return abs(a -b ) < m_epsilon; //this line breaks
36  // generalised_assignment_long_test TODO investigate
37  }
38 
40  bool g(T a, T b) const { return a > b + m_epsilon; }
41 
43  bool ge(T a, T b) const { return a >= b - m_epsilon; }
44 
46  bool le(T a, T b) const { return a <= b + m_epsilon; }
47 
49  double get_epsilon() const { return m_epsilon; }
50 
51 
53  static T default_epsilon() { return std::numeric_limits<T>::epsilon(); }
54 };
55 
56 } // utils
57 } // paal
58 
59 #endif // PAAL_FLOATING_HPP
static T default_epsilon()
returns default epsilon equals the smallest possible difference on doubles
Definition: floating.hpp:53
bool le(T a, T b) const
less equals
Definition: floating.hpp:46
double get_epsilon() const
get_epsilon used in comparison
Definition: floating.hpp:49
bool g(T a, T b) const
greater
Definition: floating.hpp:40
compare(T epsilon=std::numeric_limits< T >::epsilon())
constructor
Definition: floating.hpp:30
bool ge(T a, T b) const
greater equals
Definition: floating.hpp:43
Class for comparing floating point.
Definition: floating.hpp:26
bool e(T a, T b) const
equals
Definition: floating.hpp:33