#ifndef SPROUT_MATH_REMAINDER_HPP #define SPROUT_MATH_REMAINDER_HPP #include #include #include #include #include #include #include #include #include #include #include namespace sprout { namespace math { namespace detail { template inline SPROUT_CONSTEXPR T remainder_impl(T x, T y) { return x - sprout::math::round(x / y) * y; } template< typename FloatType, typename sprout::enabler_if::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR FloatType remainder(FloatType x, FloatType y) { return sprout::math::isnan(y) ? sprout::math::isnan(x) ? sprout::math::signbit(y) || sprout::math::signbit(x) ? -std::numeric_limits::quiet_NaN() : std::numeric_limits::quiet_NaN() : y : sprout::math::isnan(x) ? x : x == 0 && y != 0 ? x : x == std::numeric_limits::infinity() || x == -std::numeric_limits::infinity() || y == 0 ? std::numeric_limits::quiet_NaN() : y == std::numeric_limits::infinity() || y == -std::numeric_limits::infinity() ? x #if SPROUT_USE_BUILTIN_CMATH_FUNCTION : std::remainder(x, y) #else : static_cast(sprout::math::detail::remainder_impl( static_cast::type>(x), static_cast::type>(y) )) #endif ; } template< typename ArithmeticType1, typename ArithmeticType2, typename sprout::enabler_if< std::is_arithmetic::value && std::is_arithmetic::value >::type = sprout::enabler > inline SPROUT_CONSTEXPR typename sprout::float_promote::type remainder(ArithmeticType1 x, ArithmeticType2 y) { typedef typename sprout::float_promote::type type; return sprout::math::detail::remainder(static_cast(x), static_cast(y)); } } // namespace detail using NS_SPROUT_MATH_DETAIL::remainder; } // namespace math using sprout::math::remainder; } // namespace sprout #endif // #ifndef SPROUT_MATH_REMAINDER_HPP