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
3 #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::rounder_type::operator()
T operator()(const T &x) const
Definition: rounder.h:31
rheolef::value
rheolef::std value
rheolef::ceiler_type::_prec
T _prec
Definition: rounder.h:57
rheolef::floorer_type::floorer_type
floorer_type(const T &prec)
Definition: rounder.h:41
rheolef::floorer_type::operator()
T operator()(const T &x) const
Definition: rounder.h:42
rheolef::ceiler_type::ceiler_type
ceiler_type(const T &prec)
Definition: rounder.h:51
rheolef::rounder_type::rounder_type
rounder_type(const T &prec)
Definition: rounder.h:30
rheolef
This file is part of Rheolef.
Definition: compiler_eigen.h:37
rheolef::rounder_type::_prec
T _prec
Definition: rounder.h:37
rheolef::floorer
floorer_type< T > floorer(const T &prec)
Definition: rounder.h:61
rheolef::ceiler
ceiler_type< T > ceiler(const T &prec)
Definition: rounder.h:62
rheolef::floorer_type::_prec
T _prec
Definition: rounder.h:47
rheolef::ceiler_type
Definition: rounder.h:50
rheolef::floorer_type
Definition: rounder.h:40
rheolef::rounder_type
Definition: rounder.h:29
rheolef::ceiler_type::operator()
T operator()(const T &x) const
Definition: rounder.h:52
T
Expr1::float_type T
Definition: field_expr.h:261
rheolef::rounder
rounder_type< T > rounder(const T &prec)
Definition: rounder.h:60