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) { 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..dc5af98f2 --- /dev/null +++ b/test/github_issue_1260.cpp @@ -0,0 +1,35 @@ +// 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); + + const T sub_val {lhs - boost::decimal::abs(rhs)}; + BOOST_TEST_EQ(sub_val, res); +} + +int main() +{ + // TODO(mborland): GCC 12+ in 32 bit compilations only with release mode fail + #ifndef __i386__ + + test(); + test(); + + #endif + + return boost::report_errors(); +}