From 506871651e809818bce6fdb02b6becabe50b5c4f Mon Sep 17 00:00:00 2001 From: Matt Borland Date: Mon, 12 Jan 2026 09:16:59 -0500 Subject: [PATCH 1/3] Add expanded reproducer test set --- test/Jamfile | 1 + test/github_issue_1294.cpp | 40 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 test/github_issue_1294.cpp diff --git a/test/Jamfile b/test/Jamfile index 4d353e375..e318db689 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -82,6 +82,7 @@ run github_issue_1110.cpp ; run github_issue_1112.cpp ; run github_issue_1174.cpp ; run github_issue_1260.cpp ; +run github_issue_1294.cpp ; run link_1.cpp link_2.cpp link_3.cpp ; run quick.cpp ; diff --git a/test/github_issue_1294.cpp b/test/github_issue_1294.cpp new file mode 100644 index 000000000..93b3e56b9 --- /dev/null +++ b/test/github_issue_1294.cpp @@ -0,0 +1,40 @@ +// Copyright 2025 Matt Borland +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt +// +// See: https://github.com/cppalliance/decimal/issues/1294 + +#include +#include + +using namespace boost::decimal; + +template +void test() +{ + const T val {"0.999"}; + constexpr T ref_1 {1}; + constexpr T ref_0 {0}; + + BOOST_TEST_EQ(ceil(val), ref_1); + BOOST_TEST_EQ(floor(val), ref_0); + BOOST_TEST_EQ(trunc(val), ref_0); + BOOST_TEST_EQ(round(val), ref_1); + BOOST_TEST_EQ(lround(val), 1L); + BOOST_TEST_EQ(nearbyint(val), 1); + BOOST_TEST_EQ(lrint(val), 1L); + BOOST_TEST_EQ(llrint(val), 1LL); +} + +int main() +{ + test(); + test(); + test(); + + test(); + test(); + test(); + + return boost::report_errors(); +} From c0067b0d803fbb3816e263bbd9f97f12b6f9fe2d Mon Sep 17 00:00:00 2001 From: Matt Borland Date: Mon, 12 Jan 2026 09:33:10 -0500 Subject: [PATCH 2/3] Fix conditional logic --- include/boost/decimal/detail/cmath/round.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/boost/decimal/detail/cmath/round.hpp b/include/boost/decimal/detail/cmath/round.hpp index 0ed3fc16f..bbb478306 100644 --- a/include/boost/decimal/detail/cmath/round.hpp +++ b/include/boost/decimal/detail/cmath/round.hpp @@ -43,11 +43,11 @@ constexpr auto round(const T num) noexcept T iptr {}; const auto x {modf(num, &iptr)}; - if (x >= half && iptr > 0) + if (x >= half) { ++iptr; } - else if (abs(x) >= half && iptr < 0) + else if (x <= -half) { --iptr; } From b6954c244825a27502e922cb539cfd715f2a678b Mon Sep 17 00:00:00 2001 From: Matt Borland Date: Mon, 12 Jan 2026 09:33:21 -0500 Subject: [PATCH 3/3] Add additional edge case test value --- test/github_issue_1294.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/github_issue_1294.cpp b/test/github_issue_1294.cpp index 93b3e56b9..f1b872d27 100644 --- a/test/github_issue_1294.cpp +++ b/test/github_issue_1294.cpp @@ -9,6 +9,23 @@ using namespace boost::decimal; +template +void test_round_down() +{ + const T val {"0.499"}; + constexpr T ref_1 {1}; + constexpr T ref_0 {0}; + + BOOST_TEST_EQ(ceil(val), ref_1); + BOOST_TEST_EQ(floor(val), ref_0); + BOOST_TEST_EQ(trunc(val), ref_0); + BOOST_TEST_EQ(round(val), ref_0); + BOOST_TEST_EQ(lround(val), 0L); + BOOST_TEST_EQ(nearbyint(val), 0); + BOOST_TEST_EQ(lrint(val), 0L); + BOOST_TEST_EQ(llrint(val), 0LL); +} + template void test() { @@ -24,6 +41,8 @@ void test() BOOST_TEST_EQ(nearbyint(val), 1); BOOST_TEST_EQ(lrint(val), 1L); BOOST_TEST_EQ(llrint(val), 1LL); + + test_round_down(); } int main()