mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2024-11-14 10:39:05 +00:00
fix math::exp implementation
This commit is contained in:
parent
66da9f4fea
commit
4b3d4e82d7
2 changed files with 12 additions and 10 deletions
|
@ -14,13 +14,18 @@ namespace sprout {
|
|||
namespace detail {
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR T
|
||||
exp_impl(T x, std::size_t n, std::size_t last) {
|
||||
exp_impl_1(T x, std::size_t n, std::size_t last) {
|
||||
return last - n == 1
|
||||
? sprout::detail::pow_n(x, n) / sprout::math::factorial<T>(n)
|
||||
: sprout::math::detail::exp_impl(x, n, n + (last - n) / 2)
|
||||
+ sprout::math::detail::exp_impl(x, n + (last - n) / 2, last)
|
||||
: sprout::math::detail::exp_impl_1(x, n, n + (last - n) / 2)
|
||||
+ sprout::math::detail::exp_impl_1(x, n + (last - n) / 2, last)
|
||||
;
|
||||
}
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR T
|
||||
exp_impl(T x) {
|
||||
return 1 + sprout::math::detail::exp_impl_1(x, 1, sprout::math::factorial_limit<T>() + 1);
|
||||
}
|
||||
|
||||
template<
|
||||
typename FloatType,
|
||||
|
@ -29,12 +34,9 @@ namespace sprout {
|
|||
inline SPROUT_CONSTEXPR FloatType
|
||||
exp(FloatType x) {
|
||||
typedef double type;
|
||||
return static_cast<FloatType>(
|
||||
type(1) + sprout::math::detail::exp_impl(
|
||||
static_cast<type>(x),
|
||||
1, sprout::math::factorial_limit<type>() + 1
|
||||
)
|
||||
);
|
||||
return !(x > -1) ? 1 / sprout::math::detail::exp_impl(-static_cast<type>(x))
|
||||
: sprout::math::detail::exp_impl(static_cast<type>(x))
|
||||
;
|
||||
}
|
||||
|
||||
template<
|
||||
|
|
|
@ -42,7 +42,7 @@ namespace sprout {
|
|||
typedef double type;
|
||||
return x == 0 ? std::numeric_limits<FloatType>::quiet_NaN()
|
||||
: !(x > 0) ? -std::numeric_limits<FloatType>::infinity()
|
||||
: x < 1 ? static_cast<FloatType>(-sprout::math::detail::log_impl(type(1) / static_cast<type>(x)))
|
||||
: x < 1 ? static_cast<FloatType>(-sprout::math::detail::log_impl(1 / static_cast<type>(x)))
|
||||
: static_cast<FloatType>(sprout::math::detail::log_impl(static_cast<type>(x)))
|
||||
;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue