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

fix: math functions (support for inferior C++14 standard)

add C++14 constexpr modifying algorithms
This commit is contained in:
bolero-MURAKAMI 2013-10-25 12:29:16 +09:00
parent 58cff54e0d
commit c58c9cc0fc
106 changed files with 3465 additions and 2144 deletions

View file

@ -20,6 +20,21 @@
namespace sprout {
namespace math {
namespace detail {
#if SPROUT_USE_BUILTIN_CMATH_FUNCTION
inline SPROUT_CONSTEXPR float
builtin_tanh(float x) {
return __builtin_tanhf(x);
}
inline SPROUT_CONSTEXPR double
builtin_tanh(double x) {
return __builtin_tanh(x);
}
inline SPROUT_CONSTEXPR long double
builtin_tanh(long double x) {
return __builtin_tanhl(x);
}
#endif
template<typename T>
inline SPROUT_CONSTEXPR T
tanh_impl_2(T t, T u) {
@ -35,35 +50,35 @@ namespace sprout {
tanh_impl(T x) {
return sprout::math::detail::tanh_impl_1(sprout::math::exp(x));
}
template<
typename FloatType,
typename sprout::enabler_if<std::is_floating_point<FloatType>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR FloatType
tanh(FloatType x) {
return sprout::math::isnan(x) ? x
: x == sprout::numeric_limits<FloatType>::infinity() ? FloatType(1)
: x == -sprout::numeric_limits<FloatType>::infinity() ? FloatType(-1)
#if SPROUT_USE_BUILTIN_CMATH_FUNCTION
: std::tanh(x)
#else
: x == 0 ? x
: static_cast<FloatType>(sprout::math::detail::tanh_impl(static_cast<typename sprout::math::detail::float_compute<FloatType>::type>(x)))
#endif
;
}
template<
typename IntType,
typename sprout::enabler_if<std::is_integral<IntType>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR double
tanh(IntType x) {
return sprout::math::detail::tanh(static_cast<double>(x));
}
} // namespace detail
using sprout::math::detail::tanh;
//
// tanh
//
template<
typename FloatType,
typename sprout::enabler_if<std::is_floating_point<FloatType>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR FloatType
tanh(FloatType x) {
return sprout::math::isnan(x) ? x
: x == sprout::numeric_limits<FloatType>::infinity() ? FloatType(1)
: x == -sprout::numeric_limits<FloatType>::infinity() ? FloatType(-1)
#if SPROUT_USE_BUILTIN_CMATH_FUNCTION
: sprout::math::detail::builtin_tanh(x)
#else
: x == 0 ? x
: static_cast<FloatType>(sprout::math::detail::tanh_impl(static_cast<typename sprout::math::detail::float_compute<FloatType>::type>(x)))
#endif
;
}
template<
typename IntType,
typename sprout::enabler_if<std::is_integral<IntType>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR double
tanh(IntType x) {
return sprout::math::tanh(static_cast<double>(x));
}
} // namespace math
using sprout::math::tanh;