/* * 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 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; } }; /* namespace Helpers */ #endif /* POTENTIALS_HELPERS_HPP_ */