mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2025-08-21 14:10:51 +00:00
fix: math functions (support for inferior C++14 standard)
add C++14 constexpr modifying algorithms
This commit is contained in:
parent
58cff54e0d
commit
c58c9cc0fc
106 changed files with 3465 additions and 2144 deletions
|
@ -21,40 +21,55 @@
|
|||
namespace sprout {
|
||||
namespace math {
|
||||
namespace detail {
|
||||
#if SPROUT_USE_BUILTIN_CMATH_FUNCTION
|
||||
inline SPROUT_CONSTEXPR float
|
||||
builtin_acosh(float x) {
|
||||
return __builtin_acoshf(x);
|
||||
}
|
||||
inline SPROUT_CONSTEXPR double
|
||||
builtin_acosh(double x) {
|
||||
return __builtin_acosh(x);
|
||||
}
|
||||
inline SPROUT_CONSTEXPR long double
|
||||
builtin_acosh(long double x) {
|
||||
return __builtin_acoshl(x);
|
||||
}
|
||||
#endif
|
||||
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR T
|
||||
acosh_impl(T x) {
|
||||
return sprout::math::log(x + sprout::math::sqrt(x * x - 1));
|
||||
}
|
||||
|
||||
template<
|
||||
typename FloatType,
|
||||
typename sprout::enabler_if<std::is_floating_point<FloatType>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR FloatType
|
||||
acosh(FloatType x) {
|
||||
return sprout::math::isnan(x) ? x
|
||||
: x < 1 ? -sprout::numeric_limits<FloatType>::quiet_NaN()
|
||||
: x == sprout::numeric_limits<FloatType>::infinity() ? sprout::numeric_limits<FloatType>::infinity()
|
||||
#if SPROUT_USE_BUILTIN_CMATH_FUNCTION
|
||||
: std::acosh(x)
|
||||
#else
|
||||
: x == 1 ? FloatType(0)
|
||||
: static_cast<FloatType>(sprout::math::detail::acosh_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
|
||||
acosh(IntType x) {
|
||||
return sprout::math::detail::acosh(static_cast<double>(x));
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
using sprout::math::detail::acosh;
|
||||
//
|
||||
// acosh
|
||||
//
|
||||
template<
|
||||
typename FloatType,
|
||||
typename sprout::enabler_if<std::is_floating_point<FloatType>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR FloatType
|
||||
acosh(FloatType x) {
|
||||
return sprout::math::isnan(x) ? x
|
||||
: x < 1 ? -sprout::numeric_limits<FloatType>::quiet_NaN()
|
||||
: x == sprout::numeric_limits<FloatType>::infinity() ? sprout::numeric_limits<FloatType>::infinity()
|
||||
#if SPROUT_USE_BUILTIN_CMATH_FUNCTION
|
||||
: sprout::math::detail::builtin_acosh(x)
|
||||
#else
|
||||
: x == 1 ? FloatType(0)
|
||||
: static_cast<FloatType>(sprout::math::detail::acosh_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
|
||||
acosh(IntType x) {
|
||||
return sprout::math::acosh(static_cast<double>(x));
|
||||
}
|
||||
} // namespace math
|
||||
|
||||
using sprout::math::acosh;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue