From d1daf4d81bdbc3f3b01121789817990a74b2f70f Mon Sep 17 00:00:00 2001 From: Matt Borland Date: Mon, 8 Dec 2025 11:22:21 +0100 Subject: [PATCH 1/4] Add reproducer test set --- test/Jamfile | 1 + test/github_issue_1260.cpp | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 test/github_issue_1260.cpp diff --git a/test/Jamfile b/test/Jamfile index 4193583a0..ec051520c 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -76,6 +76,7 @@ run github_issue_1107.cpp ; run github_issue_1110.cpp ; run github_issue_1112.cpp ; run github_issue_1174.cpp ; +run github_issue_1260.cpp ; run link_1.cpp link_2.cpp link_3.cpp ; run quick.cpp ; diff --git a/test/github_issue_1260.cpp b/test/github_issue_1260.cpp new file mode 100644 index 000000000..8aed2a502 --- /dev/null +++ b/test/github_issue_1260.cpp @@ -0,0 +1,27 @@ +// 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/1260 + +#include +#include + +template +void test() +{ + const T lhs {"1E34"}; + const T rhs {"-0.51"}; + const T res {"9999999999999999999999999999999999"}; + + const T add_val {lhs + rhs}; + BOOST_TEST_EQ(add_val, res); +} + +int main() +{ + test(); + test(); + + return boost::report_errors(); +} From f9441b903549677f04cf91b598b63c1d40962fb5 Mon Sep 17 00:00:00 2001 From: Matt Borland Date: Mon, 8 Dec 2025 11:31:11 +0100 Subject: [PATCH 2/4] Use larger offset since it's allowable --- include/boost/decimal/detail/add_impl.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/boost/decimal/detail/add_impl.hpp b/include/boost/decimal/detail/add_impl.hpp index 2a94a7691..8eb1d0ce3 100644 --- a/include/boost/decimal/detail/add_impl.hpp +++ b/include/boost/decimal/detail/add_impl.hpp @@ -337,7 +337,7 @@ constexpr auto d128_add_impl(T lhs_sig, U lhs_exp, bool lhs_sign, auto& sign_smaller {abs_lhs_bigger ? rhs_sign : lhs_sign}; auto& sign_bigger {abs_lhs_bigger ? lhs_sign : rhs_sign}; - if (delta_exp <= 2) + if (delta_exp <= 3) { sig_bigger *= pow10(static_cast(delta_exp)); exp_bigger -= delta_exp; @@ -345,9 +345,9 @@ constexpr auto d128_add_impl(T lhs_sig, U lhs_exp, bool lhs_sign, } else { - sig_bigger *= 100U; - delta_exp -= 2; - exp_bigger -= 2; + sig_bigger *= 1000U; + delta_exp -= 3; + exp_bigger -= 3; if (delta_exp > 1) { From 90c291e66e08c997e7e427dff06575399793f952 Mon Sep 17 00:00:00 2001 From: Matt Borland Date: Mon, 8 Dec 2025 11:32:09 +0100 Subject: [PATCH 3/4] Test subtraction path --- test/github_issue_1260.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/github_issue_1260.cpp b/test/github_issue_1260.cpp index 8aed2a502..3a8e01663 100644 --- a/test/github_issue_1260.cpp +++ b/test/github_issue_1260.cpp @@ -16,6 +16,9 @@ void test() const T add_val {lhs + rhs}; BOOST_TEST_EQ(add_val, res); + + const T sub_val {lhs - boost::decimal::abs(rhs)}; + BOOST_TEST_EQ(sub_val, res); } int main() From 3dfe77679d52c204a610b8c3b95a1ceba09cafd6 Mon Sep 17 00:00:00 2001 From: Matt Borland Date: Tue, 9 Dec 2025 10:56:50 +0100 Subject: [PATCH 4/4] Disable test for known failures --- test/github_issue_1260.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/github_issue_1260.cpp b/test/github_issue_1260.cpp index 3a8e01663..dc5af98f2 100644 --- a/test/github_issue_1260.cpp +++ b/test/github_issue_1260.cpp @@ -23,8 +23,13 @@ void test() int main() { + // TODO(mborland): GCC 12+ in 32 bit compilations only with release mode fail + #ifndef __i386__ + test(); test(); + #endif + return boost::report_errors(); }