Rheolef  7.2
an efficient C++ finite element environment
 
Loading...
Searching...
No Matches
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
26namespace rheolef {
27
28template <class T>
29struct 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};
39template <class T>
40struct 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};
49template <class T>
50struct 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
60template <class T> rounder_type<T> rounder (const T& prec) { return rounder_type<T>(prec); }
61template <class T> floorer_type<T> floorer (const T& prec) { return floorer_type<T>(prec); }
62template <class T> ceiler_type<T> ceiler (const T& prec) { return ceiler_type<T>(prec); }
63
64}//namespace rheolef
65#endif // _RHEOLEF_ROUNDER_H
Expr1::float_type T
Definition field_expr.h:230
This file is part of Rheolef.
rounder_type< T > rounder(const T &prec)
Definition rounder.h:60
floorer_type< T > floorer(const T &prec)
Definition rounder.h:61
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