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

@ -19,39 +19,54 @@
namespace sprout {
namespace math {
namespace detail {
#if SPROUT_USE_BUILTIN_CMATH_FUNCTION
inline SPROUT_CONSTEXPR float
builtin_erfc(float x) {
return __builtin_erfcf(x);
}
inline SPROUT_CONSTEXPR double
builtin_erfc(double x) {
return __builtin_erfc(x);
}
inline SPROUT_CONSTEXPR long double
builtin_erfc(long double x) {
return __builtin_erfcl(x);
}
#endif
template<typename T>
inline SPROUT_CONSTEXPR T
erfc_impl(T x) {
return T(1) - sprout::math::erf(x);
}
template<
typename FloatType,
typename sprout::enabler_if<std::is_floating_point<FloatType>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR FloatType
erfc(FloatType x) {
return sprout::math::isnan(x) ? x
: x == sprout::numeric_limits<FloatType>::infinity() ? FloatType(0)
: x == -sprout::numeric_limits<FloatType>::infinity() ? FloatType(2)
#if SPROUT_USE_BUILTIN_CMATH_FUNCTION
: std::erfc(x)
#else
: static_cast<FloatType>(sprout::math::detail::erfc_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
erfc(IntType x) {
return sprout::math::detail::erfc(static_cast<double>(x));
}
} // namespace detail
using sprout::math::detail::erfc;
//
// erfc
//
template<
typename FloatType,
typename sprout::enabler_if<std::is_floating_point<FloatType>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR FloatType
erfc(FloatType x) {
return sprout::math::isnan(x) ? x
: x == sprout::numeric_limits<FloatType>::infinity() ? FloatType(0)
: x == -sprout::numeric_limits<FloatType>::infinity() ? FloatType(2)
#if SPROUT_USE_BUILTIN_CMATH_FUNCTION
: sprout::math::detail::builtin_erfc(x)
#else
: static_cast<FloatType>(sprout::math::detail::erfc_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
erfc(IntType x) {
return sprout::math::erfc(static_cast<double>(x));
}
} // namespace math
using sprout::math::erfc;