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,39 +20,38 @@
namespace sprout {
namespace math {
namespace detail {
template<
typename R = int,
typename FloatType,
typename sprout::enabler_if<std::is_floating_point<FloatType>::value && std::is_integral<R>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR R
quotient(FloatType x, FloatType y) {
return y == 0 ? R(0)
: sprout::math::isnan(y) || sprout::math::isnan(x) ? R(0)
: x == sprout::numeric_limits<FloatType>::infinity() || x == -sprout::numeric_limits<FloatType>::infinity()
? R(0)
: x == 0 ? R(0)
: y == sprout::numeric_limits<FloatType>::infinity() || y == -sprout::numeric_limits<FloatType>::infinity() ? R(0)
: sprout::math::rem_quo<R>(x, y).second
;
}
template<
typename R = int,
typename ArithmeticType1,
typename ArithmeticType2,
typename sprout::enabler_if<
std::is_arithmetic<ArithmeticType1>::value && std::is_arithmetic<ArithmeticType2>::value && std::is_integral<R>::value
>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR R
quotient(ArithmeticType1 x, ArithmeticType2 y) {
typedef typename sprout::float_promote<ArithmeticType1, ArithmeticType2>::type type;
return sprout::math::detail::quotient(static_cast<type>(x), static_cast<type>(y));
}
} // namespace detail
using sprout::math::detail::quotient;
//
// quotient
//
template<
typename R = int,
typename FloatType,
typename sprout::enabler_if<std::is_floating_point<FloatType>::value && std::is_integral<R>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR R
quotient(FloatType x, FloatType y) {
return y == 0 ? R(0)
: sprout::math::isnan(y) || sprout::math::isnan(x) ? R(0)
: x == sprout::numeric_limits<FloatType>::infinity() || x == -sprout::numeric_limits<FloatType>::infinity()
? R(0)
: x == 0 ? R(0)
: y == sprout::numeric_limits<FloatType>::infinity() || y == -sprout::numeric_limits<FloatType>::infinity() ? R(0)
: sprout::math::rem_quo<R>(x, y).second
;
}
template<
typename R = int,
typename ArithmeticType1,
typename ArithmeticType2,
typename sprout::enabler_if<
std::is_arithmetic<ArithmeticType1>::value && std::is_arithmetic<ArithmeticType2>::value && std::is_integral<R>::value
>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR R
quotient(ArithmeticType1 x, ArithmeticType2 y) {
typedef typename sprout::float_promote<ArithmeticType1, ArithmeticType2>::type type;
return sprout::math::quotient(static_cast<type>(x), static_cast<type>(y));
}
} // namespace math
using sprout::math::quotient;