#ifndef SPROUT_MATH_IFLOOR_HPP #define SPROUT_MATH_IFLOOR_HPP #include #include #include #include #include #include #if SPROUT_USE_BUILTIN_CMATH_FUNCTION # include #else # include #endif namespace sprout { namespace math { namespace detail { #if SPROUT_USE_BUILTIN_CMATH_FUNCTION template inline SPROUT_CONSTEXPR To ifloor_impl(FloatType x) { return std::numeric_limits::max() < x || std::numeric_limits::min() > x ? SPROUT_MATH_THROW_LARGE_FLOAT_ROUNDING(std::domain_error("ifloor: large float rounding."), static_cast(x)) : static_cast(x) ; } template< typename To = int, typename FloatType, typename sprout::enabler_if::value && std::is_integral::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR To ifloor(FloatType x) { return sprout::math::detail::ifloor_impl(sprout::math::floor(x)); } #else template inline SPROUT_CONSTEXPR To ifloor_impl(FloatType x, To x0) { return sprout::math::equal_to(x, x0) ? x0 : x0 - 1 ; } template< typename To = int, typename FloatType, typename sprout::enabler_if::value && std::is_integral::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR To ifloor(FloatType x) { return x == 0 ? To(0) : std::numeric_limits::max() < x || std::numeric_limits::min() > x ? SPROUT_MATH_THROW_LARGE_FLOAT_ROUNDING(std::domain_error("ifloor: large float rounding."), static_cast(x)) : sprout::math::detail::ifloor_impl(x, static_cast(x)) ; } #endif template< typename To = int, typename IntType, typename sprout::enabler_if::value && std::is_integral::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR To ifloor(IntType x) { return sprout::math::detail::ifloor(static_cast(x)); } } // namespace detail using sprout::math::detail::ifloor; } // namespace math using sprout::math::ifloor; } // namespace sprout #endif // #ifndef SPROUT_MATH_IFLOOR_HPP