/* * helpers.hpp * * Created on: Sep 26, 2012 * Author: heber */ #ifndef POTENTIALS_HELPERS_HPP_ #define POTENTIALS_HELPERS_HPP_ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include //#include #include //#include #include "FunctionApproximation/FunctionModel.hpp" #include "FunctionApproximation/FunctionArgument.hpp" //#include "CodePatterns/Log.hpp" namespace Helpers { /** Integer-optimized version for power of n. * * This is taken from Julian Iseringhausen's VMG project which is under * GPL. * * @param base base * @param power power to take \a base to * @return \a base to the power of \a power */ inline int intpow(int base, unsigned int power) { int result = 1; while (power != 0) { if (power & 1) result *= base; base *= base; power >>= 1; } return result; } /** Double-optimized version for power of n. * * This is taken from Julian Iseringhausen's VMG project which is under * GPL. * * @param base base * @param power power to take \a base to * @return \a base to the power of \a power */ inline double pow(double base, unsigned int power) { double result = 1.0; while (power != 0) { if (power & 1) result *= base; base *= base; power >>= 1; } return result; } /** Equality operator that takes numerical precision into account. * * \param first first operand * \param second second operand * \param factor factor to influence numeric threshold */ template inline bool isEqual(const T &first, const T &second, const double factor=1.) { // std::stringstream stream; // stream << std::setprecision(10) // << "Comparing " << first << " to " << second << ": " // << fabs(first-second) << "<" << std::numeric_limits::epsilon()*factor << "?"; // LOG(1, stream.str()); return (fabs(first-second) < std::numeric_limits::epsilon()*factor); } inline std::vector< FunctionModel::arguments_t > NoOp_Triplefunction( const argument_t &, const double) { return std::vector< FunctionModel::arguments_t >(); } inline FunctionModel::arguments_t NoOp_Filterfunction( const FunctionModel::arguments_t &args ) { return args; } inline FunctionModel::arguments_t returnEmptyArguments() { return FunctionModel::arguments_t(); } inline FunctionModel::list_of_arguments_t returnEmptyListArguments() { return FunctionModel::list_of_arguments_t(); } }; /* namespace Helpers */ #endif /* POTENTIALS_HELPERS_HPP_ */