From adaf1bfd0626734e2ff2d7fdb58ce18e54bc59f0 Mon Sep 17 00:00:00 2001 From: Youssef LAKHAL Date: Sun, 12 Jan 2025 15:54:47 +0100 Subject: [PATCH] Fix constexpr cmath floor of 1 returning 0 #1232 --- include/boost/math/ccmath/floor.hpp | 2 +- test/ccmath_floor_test.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/boost/math/ccmath/floor.hpp b/include/boost/math/ccmath/floor.hpp index fb1dea34db..5afed7d0ca 100644 --- a/include/boost/math/ccmath/floor.hpp +++ b/include/boost/math/ccmath/floor.hpp @@ -33,7 +33,7 @@ inline constexpr T floor_pos_impl(T arg) noexcept T result = 1; - if(result < arg) + if(result <= arg) { while(result < arg) { diff --git a/test/ccmath_floor_test.cpp b/test/ccmath_floor_test.cpp index ddd0a53e9d..bcc9cc1790 100644 --- a/test/ccmath_floor_test.cpp +++ b/test/ccmath_floor_test.cpp @@ -32,6 +32,7 @@ constexpr void test() static_assert(boost::math::ccmath::isinf(boost::math::ccmath::floor(-std::numeric_limits::infinity())), "If x is +- inf, it is returned, unmodified"); + static_assert(boost::math::ccmath::floor(T(1.0)) == T(1.0)); static_assert(boost::math::ccmath::floor(T(2)) == T(2)); static_assert(boost::math::ccmath::floor(T(2.4)) == T(2)); static_assert(boost::math::ccmath::floor(T(2.9)) == T(2));