rounder.h
Go to the documentation of this file.
#ifndef _RHEOLEF_ROUNDER_H
#define _RHEOLEF_ROUNDER_H
#include "rheolef/compiler.h"
#include <cmath>
namespace rheolef {
template <class T>
struct rounder_type : std::unary_function<T,T> {
rounder_type (const T& prec) : _prec(prec) {}
T operator() (const T& x) const {
// use floor : std::round() is non-standard (INTEL C++)
T value = _prec*floor(x/_prec + 0.5);
if (1+value == 1) value = T(0);
return value;
}
T _prec;
};
template <class T>
struct floorer_type : std::unary_function<T,T> {
floorer_type (const T& prec) : _prec(prec) {}
T operator() (const T& x) const {
T value = _prec*floor(x/_prec);
if (1+value == 1) value = T(0);
return value;
}
T _prec;
};
template <class T>
struct ceiler_type : std::unary_function<T,T> {
ceiler_type (const T& prec) : _prec(prec) {}
T operator() (const T& x) const {
T value = _prec*ceil(x/_prec);
if (1+value == 1) value = T(0);
return value;
}
T _prec;
};
template <class T> rounder_type<T> rounder (const T& prec) { return rounder_type<T>(prec); }
template <class T> floorer_type<T> floorer (const T& prec) { return floorer_type<T>(prec); }
template <class T> ceiler_type<T> ceiler (const T& prec) { return ceiler_type<T>(prec); }
}//namespace rheolef
#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:218
rheolef::rounder
rounder_type< T > rounder(const T &prec)
Definition: rounder.h:60