1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2025-08-03 12:49:50 +00:00

fix recursion depth math functions.

This commit is contained in:
bolero-MURAKAMI 2012-12-08 13:45:09 +09:00
parent 0754fd0fad
commit 74729ce14f
8 changed files with 80 additions and 115 deletions

View file

@ -9,17 +9,26 @@ namespace sprout {
pow2(T const& x) {
return x * x;
}
template<typename T>
inline SPROUT_CONSTEXPR T
pow3(T const& x) {
return x * x * x;
}
template<typename T>
inline SPROUT_CONSTEXPR T
pow_n_impl(T const& x, int n) {
return n == 1 ? x
: 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 == 1 ? x
: n % 2 ? x * sprout::detail::pow2(sprout::detail::pow_n(x, n / 2))
: sprout::detail::pow2(sprout::detail::pow_n(x, n / 2))
return n == 0 ? T(1)
: sprout::detail::pow_n_impl(x, n)
;
}
} // namespace detail