diff --git a/include/boost/decimal/detail/mul_impl.hpp b/include/boost/decimal/detail/mul_impl.hpp index 58b013ef1..048a54134 100644 --- a/include/boost/decimal/detail/mul_impl.hpp +++ b/include/boost/decimal/detail/mul_impl.hpp @@ -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::digits10) + if (lhs_dig + rhs_dig <= std::numeric_limits::digits10) { auto res_sig {lhs_sig * rhs_sig}; auto res_exp {lhs_exp + rhs_exp}; diff --git a/test/Jamfile b/test/Jamfile index ee3dccf89..d847de99b 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -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 ; diff --git a/test/github_issue_802.cpp b/test/github_issue_802.cpp new file mode 100644 index 000000000..c3adadf4c --- /dev/null +++ b/test/github_issue_802.cpp @@ -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 +#include +#include + +void fasting() +{ + 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(); +} +