Dune Core Modules (2.4.2)

float_cmp.hh
Go to the documentation of this file.
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3#ifndef DUNE_COMMON_FLOAT_CMP_HH
4#define DUNE_COMMON_FLOAT_CMP_HH
5
96namespace Dune {
99 namespace FloatCmp {
100 // basic constants
103 enum CmpStyle {
112 };
126 };
127
128 template<class T> struct EpsilonType;
129
131
136 template<class T, CmpStyle style = defaultCmpStyle>
139 static typename EpsilonType<T>::Type value();
140 };
141
142 // operations in functional style
143
146
148
155 template <class T, CmpStyle style /*= defaultCmpStyle*/>
156 bool eq(const T &first,
157 const T &second,
160
168 template <class T, CmpStyle style /*= defaultCmpStyle*/>
169 bool ne(const T &first,
170 const T &second,
173
184 template <class T, CmpStyle style /*= defaultCmpStyle*/>
185 bool gt(const T &first,
186 const T &second,
189
200 template <class T, CmpStyle style /*= defaultCmpStyle*/>
201 bool lt(const T &first,
202 const T &second,
205
216 template <class T, CmpStyle style /*= defaultCmpStyle*/>
217 bool ge(const T &first,
218 const T &second,
221
232 template <class T, CmpStyle style /*= defaultCmpStyle*/>
233 bool le(const T &first,
234 const T &second,
236
237 // rounding operations
239
252 template<class I, class T, CmpStyle cstyle /*= defaultCmpStyle*/, RoundingStyle rstyle /*= defaultRoundingStyle*/>
253 I round(const T &val, typename EpsilonType<T>::Type epsilon = DefaultEpsilon<T, cstyle>::value());
254 // truncation
256
269 template<class I, class T, CmpStyle cstyle /*= defaultCmpStyle*/, RoundingStyle rstyle /*= defaultRoundingStyle*/>
270 I trunc(const T &val, typename EpsilonType<T>::Type epsilon = DefaultEpsilon<T, cstyle>::value());
271
273 // group FloatCmp
274 } //namespace FloatCmp
275
276
277 // oo interface
279
285 template<class T, FloatCmp::CmpStyle cstyle_ = FloatCmp::defaultCmpStyle,
290
291 public:
292 // record template parameters
294 static const CmpStyle cstyle = cstyle_;
296 static const RoundingStyle rstyle = rstyle_;
298 typedef T ValueType;
300
304
305 private:
306 EpsilonType epsilon_;
307
309
310 public:
312
316
318 EpsilonType epsilon() const;
320 void epsilon(EpsilonType epsilon__);
321
323 bool eq(const ValueType &first, const ValueType &second) const;
325
328 bool ne(const ValueType &first, const ValueType &second) const;
330
334 bool gt(const ValueType &first, const ValueType &second) const;
336
340 bool lt(const ValueType &first, const ValueType &second) const;
342
346 bool ge(const ValueType &first, const ValueType &second) const;
348
352 bool le(const ValueType &first, const ValueType &second) const;
353
355
364 template<class I>
365 I round(const ValueType &val) const;
366
368
377 template<class I>
378 I trunc(const ValueType &val) const;
379
380 };
381
382} //namespace Dune
383
384#include "float_cmp.cc"
385
386#endif //DUNE_COMMON_FLOAT_CMP_HH
Class encapsulating a default epsilon.
Definition: float_cmp.hh:287
bool le(const ValueType &first, const ValueType &second) const
test if first lesser or equal second
Definition: float_cmp.cc:460
FloatCmpOps(EpsilonType epsilon=DefaultEpsilon::value())
construct an operations object
Definition: float_cmp.cc:405
bool eq(const ValueType &first, const ValueType &second) const
test for equality using epsilon
Definition: float_cmp.cc:425
static const CmpStyle cstyle
How comparisons are done.
Definition: float_cmp.hh:294
bool lt(const ValueType &first, const ValueType &second) const
test if first lesser than second
Definition: float_cmp.cc:446
bool ge(const ValueType &first, const ValueType &second) const
test if first greater or equal second
Definition: float_cmp.cc:453
static const RoundingStyle rstyle
How rounding is done.
Definition: float_cmp.hh:296
FloatCmp::EpsilonType< T >::Type EpsilonType
Type of the epsilon.
Definition: float_cmp.hh:303
bool ne(const ValueType &first, const ValueType &second) const
test for inequality using epsilon
Definition: float_cmp.cc:432
T ValueType
Type of the values to compare.
Definition: float_cmp.hh:298
EpsilonType epsilon() const
return the current epsilon
Definition: float_cmp.cc:410
I round(const ValueType &val) const
round using epsilon
Definition: float_cmp.cc:469
I trunc(const ValueType &val) const
truncate using epsilon
Definition: float_cmp.cc:477
bool gt(const ValueType &first, const ValueType &second) const
test if first greater than second
Definition: float_cmp.cc:439
bool ne(const T &first, const T &second, typename EpsilonType< T >::Type epsilon)
test for inequality using epsilon
Definition: float_cmp.cc:125
CmpStyle
Definition: float_cmp.hh:103
bool eq(const T &first, const T &second, typename EpsilonType< T >::Type epsilon)
test for equality using epsilon
Definition: float_cmp.cc:118
I round(const T &val, typename EpsilonType< T >::Type epsilon)
round using epsilon
Definition: float_cmp.cc:285
I trunc(const T &val, typename EpsilonType< T >::Type epsilon)
truncate using epsilon
Definition: float_cmp.cc:381
RoundingStyle
Definition: float_cmp.hh:115
bool lt(const T &first, const T &second, typename EpsilonType< T >::Type epsilon)
test if first lesser than second
Definition: float_cmp.cc:139
bool gt(const T &first, const T &second, typename EpsilonType< T >::Type epsilon)
test if first greater than second
Definition: float_cmp.cc:132
bool ge(const T &first, const T &second, typename EpsilonType< T >::Type epsilon)
test if first greater or equal second
Definition: float_cmp.cc:146
bool le(const T &first, const T &second, typename EpsilonType< T >::Type epsilon)
test if first lesser or equal second
Definition: float_cmp.cc:153
@ defaultCmpStyle
the global default compare style (relative_weak)
Definition: float_cmp.hh:111
@ relativeStrong
|a-b|/|a| <= epsilon && |a-b|/|b| <= epsilon
Definition: float_cmp.hh:107
@ relativeWeak
|a-b|/|a| <= epsilon || |a-b|/|b| <= epsilon
Definition: float_cmp.hh:105
@ absolute
|a-b| <= epsilon
Definition: float_cmp.hh:109
@ towardZero
always round toward 0
Definition: float_cmp.hh:117
@ towardInf
always round away from 0
Definition: float_cmp.hh:119
@ upward
round toward
Definition: float_cmp.hh:123
@ downward
round toward
Definition: float_cmp.hh:121
@ defaultRoundingStyle
the global default rounding style (toward_zero)
Definition: float_cmp.hh:125
Dune namespace.
Definition: alignment.hh:10
mapping from a value type and a compare style to a default epsilon
Definition: float_cmp.hh:137
static EpsilonType< T >::Type value()
Returns the default epsilon for the given value type and compare style.
T Type
The epsilon type corresponding to value type T.
Definition: float_cmp.cc:23
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)