... |
... |
@@ -31,27 +31,27 @@
|
31 |
31 |
|
32 |
32 |
/// \addtogroup misc
|
33 |
33 |
/// @{
|
34 |
34 |
|
35 |
35 |
///\brief A class to provide a basic way to
|
36 |
36 |
///handle the comparison of numbers that are obtained
|
37 |
37 |
///as a result of a probably inexact computation.
|
38 |
38 |
///
|
39 |
39 |
///\ref Tolerance is a class to provide a basic way to
|
40 |
40 |
///handle the comparison of numbers that are obtained
|
41 |
41 |
///as a result of a probably inexact computation.
|
42 |
42 |
///
|
43 |
|
///This is an abstract class, it should be specialized for all numerical
|
44 |
|
///data types. These specialized classes like \ref Tolerance<double>
|
45 |
|
///may offer additional tuning parameters.
|
|
43 |
///This is an abstract class, it should be specialized for all
|
|
44 |
///numerical data types. These specialized classes like
|
|
45 |
///Tolerance<double> may offer additional tuning parameters.
|
46 |
46 |
///
|
47 |
47 |
///\sa Tolerance<float>
|
48 |
48 |
///\sa Tolerance<double>
|
49 |
49 |
///\sa Tolerance<long double>
|
50 |
50 |
///\sa Tolerance<int>
|
51 |
51 |
///\sa Tolerance<long long int>
|
52 |
52 |
///\sa Tolerance<unsigned int>
|
53 |
53 |
///\sa Tolerance<unsigned long long int>
|
54 |
54 |
|
55 |
55 |
template<class T>
|
56 |
56 |
class Tolerance
|
57 |
57 |
{
|
... |
... |
@@ -108,25 +108,25 @@
|
108 |
108 |
|
109 |
109 |
///Returns the epsilon value.
|
110 |
110 |
Value epsilon() const {return _epsilon;}
|
111 |
111 |
///Sets the epsilon value.
|
112 |
112 |
void epsilon(Value e) {_epsilon=e;}
|
113 |
113 |
|
114 |
114 |
///Returns the default epsilon value.
|
115 |
115 |
static Value defaultEpsilon() {return def_epsilon;}
|
116 |
116 |
///Sets the default epsilon value.
|
117 |
117 |
static void defaultEpsilon(Value e) {def_epsilon=e;}
|
118 |
118 |
|
119 |
119 |
///\name Comparisons
|
120 |
|
///See \ref Tolerance for more details.
|
|
120 |
///See \ref lemon::Tolerance "Tolerance" for more details.
|
121 |
121 |
|
122 |
122 |
///@{
|
123 |
123 |
|
124 |
124 |
///Returns \c true if \c a is \e surely strictly less than \c b
|
125 |
125 |
bool less(Value a,Value b) const {return a+_epsilon<b;}
|
126 |
126 |
///Returns \c true if \c a is \e surely different from \c b
|
127 |
127 |
bool different(Value a,Value b) const { return less(a,b)||less(b,a); }
|
128 |
128 |
///Returns \c true if \c a is \e surely positive
|
129 |
129 |
bool positive(Value a) const { return _epsilon<a; }
|
130 |
130 |
///Returns \c true if \c a is \e surely negative
|
131 |
131 |
bool negative(Value a) const { return -_epsilon>a; }
|
132 |
132 |
///Returns \c true if \c a is \e surely non-zero
|
... |
... |
@@ -159,25 +159,25 @@
|
159 |
159 |
|
160 |
160 |
///Returns the epsilon value.
|
161 |
161 |
Value epsilon() const {return _epsilon;}
|
162 |
162 |
///Sets the epsilon value.
|
163 |
163 |
void epsilon(Value e) {_epsilon=e;}
|
164 |
164 |
|
165 |
165 |
///Returns the default epsilon value.
|
166 |
166 |
static Value defaultEpsilon() {return def_epsilon;}
|
167 |
167 |
///Sets the default epsilon value.
|
168 |
168 |
static void defaultEpsilon(Value e) {def_epsilon=e;}
|
169 |
169 |
|
170 |
170 |
///\name Comparisons
|
171 |
|
///See \ref Tolerance for more details.
|
|
171 |
///See \ref lemon::Tolerance "Tolerance" for more details.
|
172 |
172 |
|
173 |
173 |
///@{
|
174 |
174 |
|
175 |
175 |
///Returns \c true if \c a is \e surely strictly less than \c b
|
176 |
176 |
bool less(Value a,Value b) const {return a+_epsilon<b;}
|
177 |
177 |
///Returns \c true if \c a is \e surely different from \c b
|
178 |
178 |
bool different(Value a,Value b) const { return less(a,b)||less(b,a); }
|
179 |
179 |
///Returns \c true if \c a is \e surely positive
|
180 |
180 |
bool positive(Value a) const { return _epsilon<a; }
|
181 |
181 |
///Returns \c true if \c a is \e surely negative
|
182 |
182 |
bool negative(Value a) const { return -_epsilon>a; }
|
183 |
183 |
///Returns \c true if \c a is \e surely non-zero
|
... |
... |
@@ -210,25 +210,25 @@
|
210 |
210 |
|
211 |
211 |
///Returns the epsilon value.
|
212 |
212 |
Value epsilon() const {return _epsilon;}
|
213 |
213 |
///Sets the epsilon value.
|
214 |
214 |
void epsilon(Value e) {_epsilon=e;}
|
215 |
215 |
|
216 |
216 |
///Returns the default epsilon value.
|
217 |
217 |
static Value defaultEpsilon() {return def_epsilon;}
|
218 |
218 |
///Sets the default epsilon value.
|
219 |
219 |
static void defaultEpsilon(Value e) {def_epsilon=e;}
|
220 |
220 |
|
221 |
221 |
///\name Comparisons
|
222 |
|
///See \ref Tolerance for more details.
|
|
222 |
///See \ref lemon::Tolerance "Tolerance" for more details.
|
223 |
223 |
|
224 |
224 |
///@{
|
225 |
225 |
|
226 |
226 |
///Returns \c true if \c a is \e surely strictly less than \c b
|
227 |
227 |
bool less(Value a,Value b) const {return a+_epsilon<b;}
|
228 |
228 |
///Returns \c true if \c a is \e surely different from \c b
|
229 |
229 |
bool different(Value a,Value b) const { return less(a,b)||less(b,a); }
|
230 |
230 |
///Returns \c true if \c a is \e surely positive
|
231 |
231 |
bool positive(Value a) const { return _epsilon<a; }
|
232 |
232 |
///Returns \c true if \c a is \e surely negative
|
233 |
233 |
bool negative(Value a) const { return -_epsilon>a; }
|
234 |
234 |
///Returns \c true if \c a is \e surely non-zero
|
... |
... |
@@ -243,58 +243,58 @@
|
243 |
243 |
///Integer specialization of Tolerance.
|
244 |
244 |
|
245 |
245 |
///Integer specialization of Tolerance.
|
246 |
246 |
///\sa Tolerance
|
247 |
247 |
template<>
|
248 |
248 |
class Tolerance<int>
|
249 |
249 |
{
|
250 |
250 |
public:
|
251 |
251 |
///\e
|
252 |
252 |
typedef int Value;
|
253 |
253 |
|
254 |
254 |
///\name Comparisons
|
255 |
|
///See \ref Tolerance for more details.
|
|
255 |
///See \ref lemon::Tolerance "Tolerance" for more details.
|
256 |
256 |
|
257 |
257 |
///@{
|
258 |
258 |
|
259 |
259 |
///Returns \c true if \c a is \e surely strictly less than \c b
|
260 |
260 |
static bool less(Value a,Value b) { return a<b;}
|
261 |
261 |
///Returns \c true if \c a is \e surely different from \c b
|
262 |
262 |
static bool different(Value a,Value b) { return a!=b; }
|
263 |
263 |
///Returns \c true if \c a is \e surely positive
|
264 |
264 |
static bool positive(Value a) { return 0<a; }
|
265 |
265 |
///Returns \c true if \c a is \e surely negative
|
266 |
266 |
static bool negative(Value a) { return 0>a; }
|
267 |
267 |
///Returns \c true if \c a is \e surely non-zero
|
268 |
268 |
static bool nonZero(Value a) { return a!=0; }
|
269 |
269 |
|
270 |
270 |
///@}
|
271 |
271 |
|
272 |
272 |
///Returns zero
|
273 |
273 |
static Value zero() {return 0;}
|
274 |
274 |
};
|
275 |
275 |
|
276 |
276 |
///Unsigned integer specialization of Tolerance.
|
277 |
277 |
|
278 |
|
///Unsigned integer specialization of \ref Tolerance.
|
|
278 |
///Unsigned integer specialization of Tolerance.
|
279 |
279 |
///\sa Tolerance
|
280 |
280 |
template<>
|
281 |
281 |
class Tolerance<unsigned int>
|
282 |
282 |
{
|
283 |
283 |
public:
|
284 |
284 |
///\e
|
285 |
285 |
typedef unsigned int Value;
|
286 |
286 |
|
287 |
287 |
///\name Comparisons
|
288 |
|
///See \ref Tolerance for more details.
|
|
288 |
///See \ref lemon::Tolerance "Tolerance" for more details.
|
289 |
289 |
|
290 |
290 |
///@{
|
291 |
291 |
|
292 |
292 |
///Returns \c true if \c a is \e surely strictly less than \c b
|
293 |
293 |
static bool less(Value a,Value b) { return a<b;}
|
294 |
294 |
///Returns \c true if \c a is \e surely different from \c b
|
295 |
295 |
static bool different(Value a,Value b) { return a!=b; }
|
296 |
296 |
///Returns \c true if \c a is \e surely positive
|
297 |
297 |
static bool positive(Value a) { return 0<a; }
|
298 |
298 |
///Returns \c true if \c a is \e surely negative
|
299 |
299 |
static bool negative(Value) { return false; }
|
300 |
300 |
///Returns \c true if \c a is \e surely non-zero
|
... |
... |
@@ -310,130 +310,130 @@
|
310 |
310 |
///Long integer specialization of Tolerance.
|
311 |
311 |
|
312 |
312 |
///Long integer specialization of Tolerance.
|
313 |
313 |
///\sa Tolerance
|
314 |
314 |
template<>
|
315 |
315 |
class Tolerance<long int>
|
316 |
316 |
{
|
317 |
317 |
public:
|
318 |
318 |
///\e
|
319 |
319 |
typedef long int Value;
|
320 |
320 |
|
321 |
321 |
///\name Comparisons
|
322 |
|
///See \ref Tolerance for more details.
|
|
322 |
///See \ref lemon::Tolerance "Tolerance" for more details.
|
323 |
323 |
|
324 |
324 |
///@{
|
325 |
325 |
|
326 |
326 |
///Returns \c true if \c a is \e surely strictly less than \c b
|
327 |
327 |
static bool less(Value a,Value b) { return a<b;}
|
328 |
328 |
///Returns \c true if \c a is \e surely different from \c b
|
329 |
329 |
static bool different(Value a,Value b) { return a!=b; }
|
330 |
330 |
///Returns \c true if \c a is \e surely positive
|
331 |
331 |
static bool positive(Value a) { return 0<a; }
|
332 |
332 |
///Returns \c true if \c a is \e surely negative
|
333 |
333 |
static bool negative(Value a) { return 0>a; }
|
334 |
334 |
///Returns \c true if \c a is \e surely non-zero
|
335 |
335 |
static bool nonZero(Value a) { return a!=0;}
|
336 |
336 |
|
337 |
337 |
///@}
|
338 |
338 |
|
339 |
339 |
///Returns zero
|
340 |
340 |
static Value zero() {return 0;}
|
341 |
341 |
};
|
342 |
342 |
|
343 |
343 |
///Unsigned long integer specialization of Tolerance.
|
344 |
344 |
|
345 |
|
///Unsigned long integer specialization of \ref Tolerance.
|
|
345 |
///Unsigned long integer specialization of Tolerance.
|
346 |
346 |
///\sa Tolerance
|
347 |
347 |
template<>
|
348 |
348 |
class Tolerance<unsigned long int>
|
349 |
349 |
{
|
350 |
350 |
public:
|
351 |
351 |
///\e
|
352 |
352 |
typedef unsigned long int Value;
|
353 |
353 |
|
354 |
354 |
///\name Comparisons
|
355 |
|
///See \ref Tolerance for more details.
|
|
355 |
///See \ref lemon::Tolerance "Tolerance" for more details.
|
356 |
356 |
|
357 |
357 |
///@{
|
358 |
358 |
|
359 |
359 |
///Returns \c true if \c a is \e surely strictly less than \c b
|
360 |
360 |
static bool less(Value a,Value b) { return a<b;}
|
361 |
361 |
///Returns \c true if \c a is \e surely different from \c b
|
362 |
362 |
static bool different(Value a,Value b) { return a!=b; }
|
363 |
363 |
///Returns \c true if \c a is \e surely positive
|
364 |
364 |
static bool positive(Value a) { return 0<a; }
|
365 |
365 |
///Returns \c true if \c a is \e surely negative
|
366 |
366 |
static bool negative(Value) { return false; }
|
367 |
367 |
///Returns \c true if \c a is \e surely non-zero
|
368 |
368 |
static bool nonZero(Value a) { return a!=0;}
|
369 |
369 |
|
370 |
370 |
///@}
|
371 |
371 |
|
372 |
372 |
///Returns zero
|
373 |
373 |
static Value zero() {return 0;}
|
374 |
374 |
};
|
375 |
375 |
|
376 |
376 |
#if defined __GNUC__ && !defined __STRICT_ANSI__
|
377 |
377 |
|
378 |
378 |
///Long long integer specialization of Tolerance.
|
379 |
379 |
|
380 |
|
///Long long integer specialization of \ref Tolerance.
|
|
380 |
///Long long integer specialization of Tolerance.
|
381 |
381 |
///\warning This class (more exactly, type <tt>long long</tt>)
|
382 |
382 |
///is not ansi compatible.
|
383 |
383 |
///\sa Tolerance
|
384 |
384 |
template<>
|
385 |
385 |
class Tolerance<long long int>
|
386 |
386 |
{
|
387 |
387 |
public:
|
388 |
388 |
///\e
|
389 |
389 |
typedef long long int Value;
|
390 |
390 |
|
391 |
391 |
///\name Comparisons
|
392 |
|
///See \ref Tolerance for more details.
|
|
392 |
///See \ref lemon::Tolerance "Tolerance" for more details.
|
393 |
393 |
|
394 |
394 |
///@{
|
395 |
395 |
|
396 |
396 |
///Returns \c true if \c a is \e surely strictly less than \c b
|
397 |
397 |
static bool less(Value a,Value b) { return a<b;}
|
398 |
398 |
///Returns \c true if \c a is \e surely different from \c b
|
399 |
399 |
static bool different(Value a,Value b) { return a!=b; }
|
400 |
400 |
///Returns \c true if \c a is \e surely positive
|
401 |
401 |
static bool positive(Value a) { return 0<a; }
|
402 |
402 |
///Returns \c true if \c a is \e surely negative
|
403 |
403 |
static bool negative(Value a) { return 0>a; }
|
404 |
404 |
///Returns \c true if \c a is \e surely non-zero
|
405 |
405 |
static bool nonZero(Value a) { return a!=0;}
|
406 |
406 |
|
407 |
407 |
///@}
|
408 |
408 |
|
409 |
409 |
///Returns zero
|
410 |
410 |
static Value zero() {return 0;}
|
411 |
411 |
};
|
412 |
412 |
|
413 |
413 |
///Unsigned long long integer specialization of Tolerance.
|
414 |
414 |
|
415 |
|
///Unsigned long long integer specialization of \ref Tolerance.
|
|
415 |
///Unsigned long long integer specialization of Tolerance.
|
416 |
416 |
///\warning This class (more exactly, type <tt>unsigned long long</tt>)
|
417 |
417 |
///is not ansi compatible.
|
418 |
418 |
///\sa Tolerance
|
419 |
419 |
template<>
|
420 |
420 |
class Tolerance<unsigned long long int>
|
421 |
421 |
{
|
422 |
422 |
public:
|
423 |
423 |
///\e
|
424 |
424 |
typedef unsigned long long int Value;
|
425 |
425 |
|
426 |
426 |
///\name Comparisons
|
427 |
|
///See \ref Tolerance for more details.
|
|
427 |
///See \ref lemon::Tolerance "Tolerance" for more details.
|
428 |
428 |
|
429 |
429 |
///@{
|
430 |
430 |
|
431 |
431 |
///Returns \c true if \c a is \e surely strictly less than \c b
|
432 |
432 |
static bool less(Value a,Value b) { return a<b;}
|
433 |
433 |
///Returns \c true if \c a is \e surely different from \c b
|
434 |
434 |
static bool different(Value a,Value b) { return a!=b; }
|
435 |
435 |
///Returns \c true if \c a is \e surely positive
|
436 |
436 |
static bool positive(Value a) { return 0<a; }
|
437 |
437 |
///Returns \c true if \c a is \e surely negative
|
438 |
438 |
static bool negative(Value) { return false; }
|
439 |
439 |
///Returns \c true if \c a is \e surely non-zero
|