#ifndef SPROUT_MATH_FLOOR_HPP #define SPROUT_MATH_FLOOR_HPP #include #include #include #include #include #include #include #include namespace sprout { namespace math { namespace detail { template inline SPROUT_CONSTEXPR FloatType floor_impl(FloatType x, FloatType x0) { return sprout::math::equal_to(x, x0) ? x0 : x0 - 1 ; } template< typename FloatType, typename sprout::enabler_if::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR FloatType floor(FloatType x) { return x == 0 ? FloatType(0) : x == std::numeric_limits::infinity() ? std::numeric_limits::infinity() : x == -std::numeric_limits::infinity() ? -std::numeric_limits::infinity() : std::numeric_limits::max() < x || std::numeric_limits::max() < -x ? SPROUT_MATH_THROW_LARGE_FLOAT_ROUNDING(std::domain_error("floor: large float rounding."), x) : x < 0 ? sprout::math::detail::floor_impl(x, -static_cast(static_cast(-x))) : static_cast(static_cast(x)) ; } template< typename IntType, typename sprout::enabler_if::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR double floor(IntType x) { return sprout::math::detail::floor(static_cast(x)); } } // namespace detail using NS_SPROUT_MATH_DETAIL::floor; } // namespace math using sprout::math::floor; } // namespace sprout #endif // #ifndef SPROUT_MATH_FLOOR_HPP