2012-12-06 17:31:16 +00:00
|
|
|
#ifndef SPROUT_DETAIL_POW_HPP
|
|
|
|
#define SPROUT_DETAIL_POW_HPP
|
2012-12-11 16:47:14 +00:00
|
|
|
|
2012-12-06 17:31:16 +00:00
|
|
|
#include <sprout/config.hpp>
|
|
|
|
|
|
|
|
namespace sprout {
|
|
|
|
namespace detail {
|
|
|
|
template<typename T>
|
|
|
|
inline SPROUT_CONSTEXPR T
|
|
|
|
pow2(T const& x) {
|
|
|
|
return x * x;
|
|
|
|
}
|
2012-12-08 04:45:09 +00:00
|
|
|
|
2012-12-06 17:31:16 +00:00
|
|
|
template<typename T>
|
|
|
|
inline SPROUT_CONSTEXPR T
|
|
|
|
pow3(T const& x) {
|
|
|
|
return x * x * x;
|
|
|
|
}
|
2012-12-08 04:45:09 +00:00
|
|
|
|
2012-12-06 17:31:16 +00:00
|
|
|
template<typename T>
|
|
|
|
inline SPROUT_CONSTEXPR T
|
2012-12-08 04:45:09 +00:00
|
|
|
pow_n_impl(T const& x, int n) {
|
2012-12-06 17:31:16 +00:00
|
|
|
return n == 1 ? x
|
2012-12-08 04:45:09 +00:00
|
|
|
: n % 2 ? x * sprout::detail::pow2(sprout::detail::pow_n_impl(x, n / 2))
|
|
|
|
: sprout::detail::pow2(sprout::detail::pow_n_impl(x, n / 2))
|
|
|
|
;
|
|
|
|
}
|
|
|
|
template<typename T>
|
|
|
|
inline SPROUT_CONSTEXPR T
|
|
|
|
pow_n(T const& x, int n) {
|
|
|
|
return n == 0 ? T(1)
|
|
|
|
: sprout::detail::pow_n_impl(x, n)
|
2012-12-06 17:31:16 +00:00
|
|
|
;
|
|
|
|
}
|
|
|
|
} // namespace detail
|
|
|
|
} // namespace sprout
|
|
|
|
|
|
|
|
#endif // #ifndef SPROUT_DETAIL_POW_HPP
|