FougTools  0.7.0dev-046fb6a
Handy tools for C++, Qt and OpenCascade
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
utils.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** FougTools
3 ** Copyright Fougue (30 Mar. 2015)
4 ** contact@fougue.pro
5 **
6 ** This software is a computer program whose purpose is to provide utility
7 ** tools for the C++ language and the Qt toolkit.
8 **
9 ** This software is governed by the CeCILL-C license under French law and
10 ** abiding by the rules of distribution of free software. You can use,
11 ** modify and/ or redistribute the software under the terms of the CeCILL-C
12 ** license as circulated by CEA, CNRS and INRIA at the following URL
13 ** "http://www.cecill.info".
14 ****************************************************************************/
15 
16 #ifndef BITS_MATH_UTILS_H
17 #define BITS_MATH_UTILS_H
18 
19 #include <cmath>
20 #include <limits>
21 #include "consts.h"
22 #include "utils_helpers.h"
23 
24 namespace math {
25 
26 // ---- Types Definitions
27 
29 {
30  NoCheck = 0x1,
32  NanCheck = 0x4,
33  SignCheck = 0x8,
35 };
36 
37 // ---- Comparison
38 
39 template<typename T>
40 bool equalByAbsError(const T& a, const T& b,
41  const T& tol = static_cast<T>(1e-6));
42 
43 template<typename T>
44 bool equalByRelError(const T& a, const T& b,
45  const T& maxRelError = static_cast<T>(1e-5),
46  const T& maxAbsError = std::numeric_limits<T>::epsilon());
47 
48 template<typename T>
49 bool equalByIntDiff(const T& a, const T& b,
50  typename __impl::TypeTraits<T>::IntegralType_t maxDistInts = 10,
51  ComparisonCheckFlags checkFlags = NoCheck);
52 
53 template<typename T>
54 T clamped(const T& v, const T& min, const T& max);
55 
56 // ---- Conversion
57 
58 template<typename T>
59 double radianToDegree(const T& angle);
60 
61 template<typename T>
62 double degreeToRadian(const T& angle);
63 
64 // ---- Misceallenous
65 
66 template<typename T>
67 int sign(const T& v);
68 
69 template<typename T>
70 T square(const T& x);
71 
72 template<typename T>
73 T zero();
74 
75 // ---- Status Report
76 
77 template<typename T>
78 bool isPositive(const T& v);
79 
80 template<typename T>
81 bool isNegative(const T& v);
82 
83 // inline const bool isInfinite(const float v);
84 // inline const bool isNan(const float v);
85 
86 #include "mathtools/utils.impl.h"
87 
88 } // namespace math
89 
90 #endif // BITS_MATH_UTILS_H
Definition: utils.h:32
double degreeToRadian(const T &angle)
int sign(const T &v)
bool isNegative(const T &v)
Definition: utils.h:31
Definition: utils.h:33
Definition: utils.h:30
T zero()
T clamped(const T &v, const T &min, const T &max)
Definition: utils.h:34
Definition: consts.h:18
bool isPositive(const T &v)
T square(const T &x)
bool equalByIntDiff(const T &a, const T &b, typename __impl::TypeTraits< T >::IntegralType_t maxDistInts=10, ComparisonCheckFlags checkFlags=NoCheck)
bool equalByRelError(const T &a, const T &b, const T &maxRelError=static_cast< T >(1e-5), const T &maxAbsError=std::numeric_limits< T >::epsilon())
bool equalByAbsError(const T &a, const T &b, const T &tol=static_cast< T >(1e-6))
double radianToDegree(const T &angle)
ComparisonCheckFlags
Definition: utils.h:28