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
2 changes: 1 addition & 1 deletion include/boost/decimal/detail/mul_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ constexpr auto d128_mul_impl(T1 lhs_sig, U1 lhs_exp, bool lhs_sign,
const auto rhs_dig {detail::num_digits(rhs_sig)};

// If we can avoid it don't do 256 bit multiplication because it is slow
if (lhs_dig * rhs_dig <= std::numeric_limits<uint128>::digits10)
if (lhs_dig + rhs_dig <= std::numeric_limits<uint128>::digits10)
{
auto res_sig {lhs_sig * rhs_sig};
auto res_exp {lhs_exp + rhs_exp};
Expand Down
1 change: 1 addition & 0 deletions test/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ run github_issue_426.cpp ;
run github_issue_448.cpp ;
run-fail github_issue_519.cpp ;
run github_issue_799.cpp ;
run github_issue_802.cpp ;
run link_1.cpp link_2.cpp link_3.cpp ;
run quick.cpp ;
run random_decimal32_comp.cpp ;
Expand Down
28 changes: 28 additions & 0 deletions test/github_issue_802.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2025 Matt Borland
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt

#include <boost/decimal.hpp>
#include <boost/core/lightweight_test.hpp>
#include <iostream>

void fasting()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure adding this as test is useful.
Result was always correct afaik.
This is hard to test but if you want one way to test this is to introduce detail:: helper that checks if 2 numbers can be multiplied within range of u128, and then test that helper.
Might be an overkill, but it is basically just extracting

    const auto lhs_dig {detail::num_digits(lhs_sig)};
    const auto rhs_dig {detail::num_digits(rhs_sig)};
    return lhs_dig + rhs_dig <= std::numeric_limits<uint128>::digits10;
    

into bool returning helper function.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a good reproducer for using the debugger. I'm not super worried about the test in this case since the special functions test suites will for sure hit both paths.

{
using namespace boost::decimal;
using Dec = decimal128;
const Dec a{100'000,1}; // 6 dec digits significant
const Dec b{2'000'000,1}; // 7 dec digits significant
constexpr Dec ab{2, 13};

// Here we should be able to use the fast path instead of the slow path
// since 2e13 fits in a 128 bit uint
BOOST_TEST((a * b) == ab);
}

int main()
{
fasting();

return boost::report_errors();
}

Loading