mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2025-08-03 12:49:50 +00:00
fix math functions
This commit is contained in:
parent
5d809ef5c9
commit
fa1d769bdf
76 changed files with 582 additions and 169 deletions
|
@ -2,10 +2,12 @@
|
|||
#define SPROUT_MATH_EXP_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <limits>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/detail/pow.hpp>
|
||||
#include <sprout/math/detail/config.hpp>
|
||||
#include <sprout/math/detail/float_compute.hpp>
|
||||
#include <sprout/math/factorial.hpp>
|
||||
#include <sprout/type_traits/enabler_if.hpp>
|
||||
|
||||
|
@ -24,7 +26,7 @@ namespace sprout {
|
|||
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);
|
||||
return T(1) + sprout::math::detail::exp_impl_1(x, 1, sprout::math::factorial_limit<T>() / 2 + 1);
|
||||
}
|
||||
|
||||
template<
|
||||
|
@ -33,8 +35,11 @@ namespace sprout {
|
|||
>
|
||||
inline SPROUT_CONSTEXPR FloatType
|
||||
exp(FloatType x) {
|
||||
typedef double type;
|
||||
return !(x > -1) ? static_cast<FloatType>(1 / sprout::math::detail::exp_impl(-static_cast<type>(x)))
|
||||
typedef typename sprout::math::detail::float_compute<FloatType>::type type;
|
||||
return x == 0 ? FloatType(1)
|
||||
: x == -std::numeric_limits<FloatType>::infinity() ? FloatType(0)
|
||||
: x == std::numeric_limits<FloatType>::infinity() ? std::numeric_limits<FloatType>::infinity()
|
||||
: !(x > -1) ? static_cast<FloatType>(type(1) / sprout::math::detail::exp_impl(-static_cast<type>(x)))
|
||||
: static_cast<FloatType>(sprout::math::detail::exp_impl(static_cast<type>(x)))
|
||||
;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue