Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions include/boost/decimal/detail/add_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,17 +337,17 @@ 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<boost::int128::uint128_t>(delta_exp));
exp_bigger -= delta_exp;
delta_exp = 0;
}
else
{
sig_bigger *= 100U;
delta_exp -= 2;
exp_bigger -= 2;
sig_bigger *= 1000U;
delta_exp -= 3;
exp_bigger -= 3;

if (delta_exp > 1)
{
Expand Down
1 change: 1 addition & 0 deletions test/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 ;
Expand Down
35 changes: 35 additions & 0 deletions test/github_issue_1260.cpp
Original file line number Diff line number Diff line change
@@ -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 <boost/decimal.hpp>
#include <boost/core/lightweight_test.hpp>

template <typename T>
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<boost::decimal::decimal128_t>();
test<boost::decimal::decimal_fast128_t>();

#endif

return boost::report_errors();
}