SheafSystem  0.0.0.0
tolerance_comparison.h
Go to the documentation of this file.
1 
2 //
3 // Copyright (c) 2014 Limit Point Systems, Inc.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 
20 
21 #ifndef TOLERANCE_COMPARISON_H
22 #define TOLERANCE_COMPARISON_H
23 
24 #ifndef SHEAF_DLL_SPEC_H
25 #include "SheafSystem/sheaf_dll_spec.h"
26 #endif
27 
28 #ifndef STD_LIMITS_H
29 #include "SheafSystem/std_limits.h"
30 #endif
31 
32 #ifndef STD_MATH_H
33 #include "SheafSystem/std_cmath.h"
34 #endif
35 
36 namespace sheaf
37 {
38 
39  // ===========================================================
40  // FLOAT COMPARISION
41  // ===========================================================
42 
46  const float float_tolerance = sqrt(std::numeric_limits<float>::epsilon());
47 
51  SHEAF_DLL_SPEC inline bool a_eql_0(float xf0)
52  {
53  return std::abs(xf0) <= float_tolerance;
54  };
55 
59  SHEAF_DLL_SPEC inline bool a_eql_0(float xf0, float xtolerance)
60  {
61  return std::abs(xf0) <= xtolerance;
62  };
63 
67  SHEAF_DLL_SPEC inline bool a_eql_1(float xf0)
68  {
69  return std::abs(xf0 - 1.0f) <= float_tolerance;
70  };
71 
75  SHEAF_DLL_SPEC inline bool a_eql_1(float xf0, float xtolerance)
76  {
77  return std::abs(xf0 - 1.0f) <= xtolerance;
78  };
79 
83  SHEAF_DLL_SPEC inline bool a_eql(float xf0, float xf1)
84  {
85  return std::abs(xf0 - xf1) <= float_tolerance;
86  };
87 
91  SHEAF_DLL_SPEC inline bool a_eql(float xf0, float xf1, float xtolerance)
92  {
93  return std::abs(xf0 - xf1) <= xtolerance;
94  };
95 
99  SHEAF_DLL_SPEC inline bool r_eql(float xf0, float xf1)
100  {
101  return std::abs(xf0 - xf1) <= float_tolerance*(std::abs(xf0) + std::abs(xf1));
102  };
103 
107  SHEAF_DLL_SPEC inline bool r_eql(float xf0, float xf1, float xtolerance)
108  {
109  return std::abs(xf0 - xf1) <= xtolerance*(std::abs(xf0) + std::abs(xf1));
110  };
111 
115  SHEAF_DLL_SPEC inline bool c_eql(float xf0, float xf1)
116  {
117  return std::abs(xf0 - xf1) <= float_tolerance*(std::abs(xf0) + std::abs(xf1) + 1.0f);
118  };
119 
123  SHEAF_DLL_SPEC inline bool c_eql(float xf0, float xf1, float xtolerance)
124  {
125  return std::abs(xf0 - xf1) <= xtolerance*(std::abs(xf0) + std::abs(xf1) + 1.0f);
126  };
127 
128 
129  // ===========================================================
130  // DOUBLE EQUALITY COMPARISION
131  // ===========================================================
132 
136  const double double_tolerance = sqrt(std::numeric_limits<double>::epsilon());
137 
141  SHEAF_DLL_SPEC inline bool a_eql_0(double xd0)
142  {
143  return std::abs(xd0) <= double_tolerance;
144  };
145 
149  SHEAF_DLL_SPEC inline bool a_eql_0(double xd0, double xtolerance)
150  {
151  return std::abs(xd0) <= xtolerance;
152  };
153 
157  SHEAF_DLL_SPEC inline bool a_eql_1(double xd0)
158  {
159  return std::abs(xd0 - 1.0) <= double_tolerance;
160  };
161 
165  SHEAF_DLL_SPEC inline bool a_eql_1(double xd0, double xtolerance)
166  {
167  return std::abs(xd0 - 1.0) <= xtolerance;
168  };
169 
173  SHEAF_DLL_SPEC inline bool a_eql(double xd0, double xd1)
174  {
175  return std::abs(xd0 - xd1) <= double_tolerance;
176  };
177 
181  SHEAF_DLL_SPEC inline bool a_eql(double xd0, double xd1, double xtolerance)
182  {
183  return std::abs(xd0 - xd1) <= xtolerance;
184  };
185 
189  SHEAF_DLL_SPEC inline bool r_eql(double xd0, double xd1)
190  {
191  return std::abs(xd0 - xd1) <= double_tolerance*(std::abs(xd0) + std::abs(xd1));
192  };
193 
197  SHEAF_DLL_SPEC inline bool r_eql(double xd0, double xd1, double xtolerance)
198  {
199  return std::abs(xd0 - xd1) <= xtolerance*(std::abs(xd0) + std::abs(xd1));
200  };
201 
205  SHEAF_DLL_SPEC inline bool c_eql(double xd0, double xd1)
206  {
207  return std::abs(xd0 - xd1) <= double_tolerance*(std::abs(xd0) + std::abs(xd1) + 1.0);
208  };
209 
213  SHEAF_DLL_SPEC inline bool c_eql(double xd0, double xd1, double xtolerance)
214  {
215  return std::abs(xd0 - xd1) <= xtolerance*(std::abs(xd0) + std::abs(xd1) + 1.0);
216  };
217 
218 
219  // ===========================================================
220  // DOUBLE LESS THAN OR EQUAL COMPARISION
221  // ===========================================================
222 
226  SHEAF_DLL_SPEC inline bool c_lte(double xd0, double xd1)
227  {
228  return xd0 <= (xd1 + double_tolerance*(std::abs(xd0) + std::abs(xd1) + 1.0));
229  };
230 
234  SHEAF_DLL_SPEC inline bool c_lte(double xd0, double xd1, double xtolerance)
235  {
236  return xd0 <= (xd1 + xtolerance*(std::abs(xd0) + std::abs(xd1) + 1.0));
237  };
238 
239 
240  // ===========================================================
241  // DOUBLE LESS THAN COMPARISION
242  // ===========================================================
243 
247  SHEAF_DLL_SPEC inline bool c_lt(double xd0, double xd1)
248  {
249  return xd0 < (xd1 - double_tolerance*(std::abs(xd0) + std::abs(xd1) + 1.0));
250  };
251 
255  SHEAF_DLL_SPEC inline bool c_lt(double xd0, double xd1, double xtolerance)
256  {
257  return xd0 < (xd1 - xtolerance*(std::abs(xd0) + std::abs(xd1) + 1.0));
258  };
259 
260 
261  // ===========================================================
262  // DOUBLE GREATER THAN OR EQUAL COMPARISION
263  // ===========================================================
264 
268  SHEAF_DLL_SPEC inline bool c_gte(double xd0, double xd1)
269  {
270  return xd0 >= (xd1 - double_tolerance*(std::abs(xd0) + std::abs(xd1) + 1.0));
271  };
272 
276  SHEAF_DLL_SPEC inline bool c_gte(double xd0, double xd1, double xtolerance)
277  {
278  return xd0 >= (xd1 - xtolerance*(std::abs(xd0) + std::abs(xd1) + 1.0));
279  };
280 
281 
282  // ===========================================================
283  // DOUBLE GREATER THAN COMPARISION
284  // ===========================================================
285 
289  SHEAF_DLL_SPEC inline bool c_gt(double xd0, double xd1)
290  {
291  return xd0 > (xd1 + double_tolerance*(std::abs(xd0) + std::abs(xd1) + 1.0));
292  };
293 
297  SHEAF_DLL_SPEC inline bool c_gt(double xd0, double xd1, double xtolerance)
298  {
299  return xd0 > (xd1 + xtolerance*(std::abs(xd0) + std::abs(xd1) + 1.0));
300  };
301 
302 
303 
304 
305 } // end namespace sheaf
306 
307 #endif // ifndef TOLERANCE_COMPARISON_H
SHEAF_DLL_SPEC void sqrt(const sec_at0 &x0, sec_at0 &xresult, bool xauto_access)
Compute sqrt of x0 (sqrt(x0)) (pre-allocated version).
Definition: sec_at0.cc:1556
SHEAF_DLL_SPEC bool a_eql_1(float xf0)
Absolute equality comparison of float xf0 to 1.0f using tolerance float_tolerance.
SHEAF_DLL_SPEC bool a_eql_0(float xf0)
Absolute equality comparison of float xf0 to 0.0f using tolerance float_tolerance.
SHEAF_DLL_SPEC bool c_eql(float xf0, float xf1)
Combined equality comparison of float xf0 to float xf1 using tolerance float_tolerance.
SHEAF_DLL_SPEC bool c_lt(double xd0, double xd1)
Combined less than comparison of double xd0 to double xd1 using tolerance double_tolerance.
const double double_tolerance
Tolerance for double comparisons.
SHEAF_DLL_SPEC bool c_lte(double xd0, double xd1)
Combined less than or equal comparison of double xd0 to double xd1 using tolerance double_tolerance...
SHEAF_DLL_SPEC bool c_gt(double xd0, double xd1)
Combined greater than comparison of double xd0 to double xd1 using tolerance double_tolerance.
SHEAF_DLL_SPEC bool r_eql(float xf0, float xf1)
Relative equality comparison of float xf0 to float xf1 using tolerance float_tolerance.
Namespace for the sheaves component of the sheaf system.
SHEAF_DLL_SPEC bool a_eql(float xf0, float xf1)
Absolute equality comparison of float xf0 to float xf1 using tolerance float_tolerance.
SHEAF_DLL_SPEC bool c_gte(double xd0, double xd1)
Combined greater than or equal comparison of double xd0 to double xd1 using tolerance double_toleranc...
const float float_tolerance
Tolerance for float comparisons.