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

@ -87,55 +87,56 @@ namespace sprout {
rem_quo_impl(T x, T y, R iquo) {
return sprout::math::detail::rem_quo_impl_1(x, sprout::math::fabs(y), (sprout::math::signbit(x) ^ sprout::math::signbit(y) ? -1 : 1), iquo, sprout::math::fabs(x));
}
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 sprout::pair<FloatType, R>
rem_quo(FloatType x, FloatType y) {
typedef sprout::pair<FloatType, R> type;
return y == 0 ? type(-sprout::numeric_limits<FloatType>::quiet_NaN(), R(0))
: sprout::math::isnan(y)
? sprout::math::isnan(x)
? type(sprout::math::signbit(y) && sprout::math::signbit(x) ? -sprout::numeric_limits<FloatType>::quiet_NaN() : sprout::numeric_limits<FloatType>::quiet_NaN(), R(0))
: type(y, R(0))
: sprout::math::isnan(x) ? type(x, R(0))
: x == sprout::numeric_limits<FloatType>::infinity() || x == -sprout::numeric_limits<FloatType>::infinity()
? type(-sprout::numeric_limits<FloatType>::quiet_NaN(), R(0))
: x == 0 ? type(x, R(0))
: y == sprout::numeric_limits<FloatType>::infinity() || y == -sprout::numeric_limits<FloatType>::infinity() ? type(x, R(0))
: sprout::math::detail::rem_quo_ret<R, FloatType>(sprout::math::detail::rem_quo_impl(
static_cast<typename sprout::math::detail::float_compute<FloatType>::type>(x),
static_cast<typename sprout::math::detail::float_compute<FloatType>::type>(y),
R(0)
))
;
}
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 sprout::pair<
typename sprout::float_promote<ArithmeticType1, ArithmeticType2>::type,
R
>
rem_quo(ArithmeticType1 x, ArithmeticType2 y) {
typedef typename sprout::float_promote<ArithmeticType1, ArithmeticType2>::type type;
return sprout::math::detail::rem_quo(static_cast<type>(x), static_cast<type>(y));
}
} // namespace detail
//
// rem_quo
//
//
// issue:
// rem_quo(-NaN, -NaN) returns {-NaN, _} .
// # returns {+NaN, _} . ( same as rem_quo(+NaN, +NaN) )
//
using sprout::math::detail::rem_quo;
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 sprout::pair<FloatType, R>
rem_quo(FloatType x, FloatType y) {
typedef sprout::pair<FloatType, R> type;
return y == 0 ? type(-sprout::numeric_limits<FloatType>::quiet_NaN(), R(0))
: sprout::math::isnan(y)
? sprout::math::isnan(x)
? type(sprout::math::signbit(y) && sprout::math::signbit(x) ? -sprout::numeric_limits<FloatType>::quiet_NaN() : sprout::numeric_limits<FloatType>::quiet_NaN(), R(0))
: type(y, R(0))
: sprout::math::isnan(x) ? type(x, R(0))
: x == sprout::numeric_limits<FloatType>::infinity() || x == -sprout::numeric_limits<FloatType>::infinity()
? type(-sprout::numeric_limits<FloatType>::quiet_NaN(), R(0))
: x == 0 ? type(x, R(0))
: y == sprout::numeric_limits<FloatType>::infinity() || y == -sprout::numeric_limits<FloatType>::infinity() ? type(x, R(0))
: sprout::math::detail::rem_quo_ret<R, FloatType>(sprout::math::detail::rem_quo_impl(
static_cast<typename sprout::math::detail::float_compute<FloatType>::type>(x),
static_cast<typename sprout::math::detail::float_compute<FloatType>::type>(y),
R(0)
))
;
}
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 sprout::pair<
typename sprout::float_promote<ArithmeticType1, ArithmeticType2>::type,
R
>
rem_quo(ArithmeticType1 x, ArithmeticType2 y) {
typedef typename sprout::float_promote<ArithmeticType1, ArithmeticType2>::type type;
return sprout::math::rem_quo(static_cast<type>(x), static_cast<type>(y));
}
} // namespace math
using sprout::math::rem_quo;