Skip to content

Commit 471ebb2

Browse files
committed
Trim trailing zeros for dec128_fast mul
1 parent a1db020 commit 471ebb2

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

include/boost/decimal/decimal128_fast.hpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -909,9 +909,21 @@ constexpr auto operator*(decimal128_fast lhs, decimal128_fast rhs) noexcept -> d
909909
}
910910
#endif
911911

912-
return detail::d128_fast_mul_impl<decimal128_fast>(
913-
lhs.significand_, lhs.biased_exponent(), lhs.sign_,
914-
rhs.significand_, rhs.biased_exponent(), rhs.sign_);
912+
auto lhs_sig {lhs.full_significand()};
913+
auto lhs_exp {lhs.biased_exponent()};
914+
const auto lhs_zeros {detail::remove_trailing_zeros(lhs_sig)};
915+
lhs_sig = lhs_zeros.trimmed_number;
916+
lhs_exp += static_cast<std::int32_t>(lhs_zeros.number_of_removed_zeros);
917+
918+
auto rhs_sig {rhs.full_significand()};
919+
auto rhs_exp {rhs.biased_exponent()};
920+
const auto rhs_zeros {detail::remove_trailing_zeros(rhs_sig)};
921+
rhs_sig = rhs_zeros.trimmed_number;
922+
rhs_exp += static_cast<std::int32_t>(rhs_zeros.number_of_removed_zeros);
923+
924+
return detail::d128_mul_impl<decimal128_fast>(
925+
lhs_sig, lhs_exp, lhs.sign_,
926+
rhs_sig, rhs_exp, rhs.sign_);
915927
}
916928

917929
template <typename Integer>

0 commit comments

Comments
 (0)