Skip to content

Commit 7a903b0

Browse files
committed
Optimize implementation of addition
1 parent 06b06c1 commit 7a903b0

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

include/boost/decimal/detail/add_impl.hpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -220,24 +220,23 @@ constexpr auto d128_add_impl(T1 lhs_sig, std::int32_t lhs_exp, bool lhs_sign,
220220
{
221221
lhs_sig *= detail::pow10(static_cast<detail::uint128>(delta_exp));
222222
lhs_exp -= delta_exp;
223-
delta_exp = 0;
224223
}
225224
else
226225
{
227226
lhs_sig *= 1000;
228227
delta_exp -= 3;
229228
lhs_exp -= 3;
230-
}
231229

232-
while (delta_exp > 1)
233-
{
234-
rhs_sig /= detail::pow10(static_cast<detail::uint128>(delta_exp - 1));
235-
delta_exp = 1;
236-
}
230+
if (delta_exp > 1)
231+
{
232+
rhs_sig /= pow10(static_cast<uint128>(delta_exp - 1));
233+
delta_exp = 1;
234+
}
237235

238-
if (delta_exp == 1)
239-
{
240-
detail::fenv_round<decimal128>(rhs_sig, rhs_sign);
236+
if (delta_exp == 1)
237+
{
238+
detail::fenv_round<decimal128>(rhs_sig, rhs_sign);
239+
}
241240
}
242241

243242
const auto new_sig {static_cast<typename ReturnType::sig_type>(lhs_sig) +

0 commit comments

Comments
 (0)