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

add compost utility

This commit is contained in:
bolero-MURAKAMI 2012-12-07 02:31:16 +09:00
parent 24d2a229f3
commit b44f7c8f2a
14 changed files with 670 additions and 29 deletions

View file

@ -5,6 +5,7 @@
#include <limits>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/detail/pow.hpp>
#include <sprout/math/detail/config.hpp>
#include <sprout/math/factorial.hpp>
#include <sprout/math/constants.hpp>
@ -16,28 +17,23 @@ namespace sprout {
namespace detail {
template<typename T>
inline SPROUT_CONSTEXPR T
cos_impl_1(T x, T tmp, std::size_t n, T x2n) {
return 2 * n > sprout::math::factorial_limit<T>() ? tmp
: sprout::math::detail::cos_impl_1(
x,
tmp + (n % 2 ? -1 : 1) * x2n / sprout::math::factorial<T>(2 * n),
n + 1,
x2n * x * x
)
cos_impl_1(T x2, std::size_t first, std::size_t last) {
return last - first == 1
? (first % 2 ? -1 : 1) * sprout::detail::pow_n(x2, first) / sprout::math::factorial<T>(2 * first)
: sprout::math::detail::cos_impl_1(x2, first, first + (last - first) / 2)
+ sprout::math::detail::cos_impl_1(x2, first + (last - first) / 2, last)
;
}
template<typename FloatType>
inline SPROUT_CONSTEXPR FloatType
cos_impl(FloatType x) {
typedef double type;
return static_cast<FloatType>(sprout::math::detail::cos_impl_1(
static_cast<type>(x),
type(1),
1,
static_cast<type>(x) * static_cast<type>(x)
))
;
return static_cast<FloatType>(
type(1) + sprout::math::detail::cos_impl_1(
static_cast<type>(x) * static_cast<type>(x),
1, sprout::math::factorial_limit<type>() / 2 + 1
)
);
}
template<