Rheolef  7.1
an efficient C++ finite element environment
rounder.h
Go to the documentation of this file.
1 #ifndef _RHEOLEF_ROUNDER_H
2 #define _RHEOLEF_ROUNDER_H
23 #include "rheolef/compiler.h"
24 #include <cmath>
25 
26 namespace rheolef {
27 
28 template <class T>
29 struct rounder_type : std::unary_function<T,T> {
30  rounder_type (const T& prec) : _prec(prec) {}
31  T operator() (const T& x) const {
32  // use floor : std::round() is non-standard (INTEL C++)
33  T value = _prec*floor(x/_prec + 0.5);
34  if (1+value == 1) value = T(0);
35  return value;
36  }
38 };
39 template <class T>
40 struct floorer_type : std::unary_function<T,T> {
41  floorer_type (const T& prec) : _prec(prec) {}
42  T operator() (const T& x) const {
43  T value = _prec*floor(x/_prec);
44  if (1+value == 1) value = T(0);
45  return value;
46  }
48 };
49 template <class T>
50 struct ceiler_type : std::unary_function<T,T> {
51  ceiler_type (const T& prec) : _prec(prec) {}
52  T operator() (const T& x) const {
53  T value = _prec*ceil(x/_prec);
54  if (1+value == 1) value = T(0);
55  return value;
56  }
58 };
59 
60 template <class T> rounder_type<T> rounder (const T& prec) { return rounder_type<T>(prec); }
61 template <class T> floorer_type<T> floorer (const T& prec) { return floorer_type<T>(prec); }
62 template <class T> ceiler_type<T> ceiler (const T& prec) { return ceiler_type<T>(prec); }
63 
64 }//namespace rheolef
65 #endif // _RHEOLEF_ROUNDER_H
rheolef::std value
Expr1::float_type T
Definition: field_expr.h:261
This file is part of Rheolef.
floorer_type< T > floorer(const T &prec)
Definition: rounder.h:61
rounder_type< T > rounder(const T &prec)
Definition: rounder.h:60
ceiler_type< T > ceiler(const T &prec)
Definition: rounder.h:62
T operator()(const T &x) const
Definition: rounder.h:52
ceiler_type(const T &prec)
Definition: rounder.h:51
T operator()(const T &x) const
Definition: rounder.h:42
floorer_type(const T &prec)
Definition: rounder.h:41
rounder_type(const T &prec)
Definition: rounder.h:30
T operator()(const T &x) const
Definition: rounder.h:31