diff --git a/include/boost/math/ccmath/floor.hpp b/include/boost/math/ccmath/floor.hpp index fa071e24ba..fb1dea34db 100644 --- a/include/boost/math/ccmath/floor.hpp +++ b/include/boost/math/ccmath/floor.hpp @@ -15,6 +15,7 @@ #include #include #include +#include namespace boost::math::ccmath { @@ -23,6 +24,13 @@ namespace detail { template inline constexpr T floor_pos_impl(T arg) noexcept { + constexpr auto max_comp_val = T(1) / std::numeric_limits::epsilon(); + + if (arg >= max_comp_val) + { + return arg; + } + T result = 1; if(result < arg) diff --git a/test/ccmath_ceil_test.cpp b/test/ccmath_ceil_test.cpp index 9540ea99d6..79c92bffd8 100644 --- a/test/ccmath_ceil_test.cpp +++ b/test/ccmath_ceil_test.cpp @@ -37,6 +37,20 @@ constexpr void test() static_assert(boost::math::ccmath::ceil(T(2.9)) == T(3)); static_assert(boost::math::ccmath::ceil(T(-2.7)) == T(-2)); static_assert(boost::math::ccmath::ceil(T(-2)) == T(-2)); + + using std::ceil; + + constexpr T half_max_ceil = boost::math::ccmath::ceil(T((std::numeric_limits::max)() / 2)); + static_assert(half_max_ceil == (std::numeric_limits::max)() / 2); + BOOST_MATH_ASSERT(half_max_ceil == ceil((std::numeric_limits::max)() / 2)); + + constexpr T third_max_ceil = boost::math::ccmath::ceil(T((std::numeric_limits::max)() / 3)); + static_assert(third_max_ceil == (std::numeric_limits::max)() / 3); + BOOST_MATH_ASSERT(third_max_ceil == ceil((std::numeric_limits::max)() / 3)); + + constexpr T one_over_eps = boost::math::ccmath::ceil(1 / T(std::numeric_limits::epsilon())); + static_assert(one_over_eps == 1 / T(std::numeric_limits::epsilon())); + BOOST_MATH_ASSERT(one_over_eps == ceil(1 / T(std::numeric_limits::epsilon()))); } #if !defined(BOOST_MATH_NO_CONSTEXPR_DETECTION) && !defined(BOOST_MATH_USING_BUILTIN_CONSTANT_P) diff --git a/test/ccmath_floor_test.cpp b/test/ccmath_floor_test.cpp index aa907fab11..ddd0a53e9d 100644 --- a/test/ccmath_floor_test.cpp +++ b/test/ccmath_floor_test.cpp @@ -37,6 +37,20 @@ constexpr void test() static_assert(boost::math::ccmath::floor(T(2.9)) == T(2)); static_assert(boost::math::ccmath::floor(T(-2.7)) == T(-3)); static_assert(boost::math::ccmath::floor(T(-2)) == T(-2)); + + using std::floor; + + constexpr T half_max_floor = boost::math::ccmath::floor(T((std::numeric_limits::max)() / 2)); + static_assert(half_max_floor == (std::numeric_limits::max)() / 2); + BOOST_MATH_ASSERT(half_max_floor == floor((std::numeric_limits::max)() / 2)); + + constexpr T third_max_floor = boost::math::ccmath::floor(T((std::numeric_limits::max)() / 3)); + static_assert(third_max_floor == (std::numeric_limits::max)() / 3); + BOOST_MATH_ASSERT(third_max_floor == floor((std::numeric_limits::max)() / 3)); + + constexpr T one_over_eps = boost::math::ccmath::floor(1 / T(std::numeric_limits::epsilon())); + static_assert(one_over_eps == 1 / T(std::numeric_limits::epsilon())); + BOOST_MATH_ASSERT(one_over_eps == floor(1 / T(std::numeric_limits::epsilon()))); } #if !defined(BOOST_MATH_NO_CONSTEXPR_DETECTION) && !defined(BOOST_MATH_USING_BUILTIN_CONSTANT_P)