NumericTools.h
Go to the documentation of this file.
1 /*
2  * NumericTools.h
3  *
4  * Created on: 15.02.2013
5  * Author: Christian Staudt (christian.staudt@kit.edu)
6  */
7
8 #ifndef NUMERICTOOLS_H_
9 #define NUMERICTOOLS_H_
10
11 #include <limits>
12
13
14
15 namespace Aux {
16
20 namespace NumericTools {
21
22
23 static constexpr double machineEpsilon = std::numeric_limits<double>::epsilon();
24
25 static constexpr double acceptableError = 1e-12;
26
27 template <typename T>
28 bool willOverflow(const T& pX, const T& pValue, const T& pMax = std::numeric_limits<T>::max()) {
29  return pMax - pValue < pX;
30 }
31
32 template <typename T>
33 bool willUnderflow(const T& pX, const T& pValue, const T& pMin = std::numeric_limits<T>::min()) {
34  return pMin + pValue > pX;
35 }
36
37
41 bool equal(double x, double y, double error = acceptableError);
42
46 bool le(double x, double y, double error = acceptableError);
47
51 bool ge(double x, double y, double error = acceptableError);
52
56 bool logically_equal(double a, double b, double error_factor=1.0);
57
58 } /* namespace NumericTools */
59
60 } /* namespace NetworKit */
61 #endif /* NUMERICTOOLS_H_ */
bool willUnderflow(const T &pX, const T &pValue, const T &pMin=std::numeric_limits< T >::min())
Definition: NumericTools.h:33
bool willOverflow(const T &pX, const T &pValue, const T &pMax=std::numeric_limits< T >::max())
Definition: NumericTools.h:28
bool le(const double x, const double y, const double error)
Test doubles for equality within a given error.
Definition: NumericTools.cpp:20
bool logically_equal(double a, double b, double error_factor)
Test doubles for equality within the smallest possible error.
Definition: NumericTools.cpp:28
bool ge(const double x, const double y, const double error)
Test doubles for equality within a given error.
Definition: NumericTools.cpp:24
bool equal(const double x, const double y, const double error)
Test doubles for equality within a given error.
Definition: NumericTools.cpp:16