Skip to content

Commit 91e935d

Browse files
committed
Avoid copies and improve readability
1 parent ced54d4 commit 91e935d

File tree

1 file changed

+26
-20
lines changed

1 file changed

+26
-20
lines changed

include/boost/decimal/decimal64.hpp

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,15 +1219,16 @@ constexpr auto operator+(decimal64 lhs, decimal64 rhs) noexcept -> decimal64
12191219
auto rhs_exp {rhs.biased_exponent()};
12201220
detail::normalize<decimal64>(rhs_sig, rhs_exp);
12211221

1222-
return {detail::d64_add_impl<decimal64>(lhs_sig, lhs_exp, lhs.isneg(),
1223-
rhs_sig, rhs_exp, rhs.isneg())};
1222+
return detail::d64_add_impl<decimal64>(lhs_sig, lhs_exp, lhs.isneg(),
1223+
rhs_sig, rhs_exp, rhs.isneg());
12241224
}
12251225

12261226
template <typename Integer>
12271227
constexpr auto operator+(decimal64 lhs, Integer rhs) noexcept
12281228
BOOST_DECIMAL_REQUIRES_RETURN(detail::is_integral_v, Integer, decimal64)
12291229
{
12301230
using promoted_significand_type = detail::promote_significand_t<decimal64, Integer>;
1231+
using exp_type = decimal64::biased_exponent_type;
12311232

12321233
#ifndef BOOST_DECIMAL_FAST_MATH
12331234
if (isnan(lhs) || isinf(lhs))
@@ -1250,7 +1251,7 @@ constexpr auto operator+(decimal64 lhs, Integer rhs) noexcept
12501251
detail::normalize<decimal64>(sig_lhs, exp_lhs);
12511252
auto lhs_components {detail::decimal64_components{sig_lhs, exp_lhs, lhs.isneg()}};
12521253

1253-
decimal64::biased_exponent_type exp_rhs {0};
1254+
exp_type exp_rhs {0};
12541255
detail::normalize<decimal64>(sig_rhs, exp_rhs);
12551256
const auto final_sig_rhs {static_cast<detail::decimal64_components::significand_type>(sig_rhs)};
12561257
auto rhs_components {detail::decimal64_components{final_sig_rhs, exp_rhs, (rhs < 0)}};
@@ -1316,16 +1317,17 @@ constexpr auto operator-(decimal64 lhs, decimal64 rhs) noexcept -> decimal64
13161317
auto exp_rhs {rhs.biased_exponent()};
13171318
detail::normalize<decimal64>(sig_rhs, exp_rhs);
13181319

1319-
return {detail::d64_sub_impl<decimal64>(sig_lhs, exp_lhs, lhs.isneg(),
1320-
sig_rhs, exp_rhs, rhs.isneg(),
1321-
abs_lhs_bigger)};
1320+
return detail::d64_sub_impl<decimal64>(sig_lhs, exp_lhs, lhs.isneg(),
1321+
sig_rhs, exp_rhs, rhs.isneg(),
1322+
abs_lhs_bigger);
13221323
}
13231324

13241325
template <typename Integer>
13251326
constexpr auto operator-(decimal64 lhs, Integer rhs) noexcept
13261327
BOOST_DECIMAL_REQUIRES_RETURN(detail::is_integral_v, Integer, decimal64)
13271328
{
13281329
using promoted_significand_type = detail::promote_significand_t<decimal64, Integer>;
1330+
using exp_type = decimal64::biased_exponent_type;
13291331

13301332
#ifndef BOOST_DECIMAL_FAST_MATH
13311333
if (isinf(lhs) || isnan(lhs))
@@ -1346,20 +1348,21 @@ constexpr auto operator-(decimal64 lhs, Integer rhs) noexcept
13461348
auto exp_lhs {lhs.biased_exponent()};
13471349
detail::normalize<decimal64>(sig_lhs, exp_lhs);
13481350

1349-
decimal64::biased_exponent_type exp_rhs {0};
1351+
exp_type exp_rhs {0};
13501352
detail::normalize<decimal64>(sig_rhs, exp_rhs);
13511353
const auto final_sig_rhs {static_cast<decimal64::significand_type>(sig_rhs)};
13521354

1353-
return {detail::d64_sub_impl<decimal64>(sig_lhs, exp_lhs, lhs.isneg(),
1354-
final_sig_rhs, exp_rhs, (rhs < 0),
1355-
abs_lhs_bigger)};
1355+
return detail::d64_sub_impl<decimal64>(sig_lhs, exp_lhs, lhs.isneg(),
1356+
final_sig_rhs, exp_rhs, (rhs < 0),
1357+
abs_lhs_bigger);
13561358
}
13571359

13581360
template <typename Integer>
13591361
constexpr auto operator-(Integer lhs, decimal64 rhs) noexcept
13601362
BOOST_DECIMAL_REQUIRES_RETURN(detail::is_integral_v, Integer, decimal64)
13611363
{
13621364
using promoted_significand_type = detail::promote_significand_t<decimal64, Integer>;
1365+
using exp_type = decimal64::biased_exponent_type;
13631366

13641367
#ifndef BOOST_DECIMAL_FAST_MATH
13651368
if (isinf(rhs) || isnan(rhs))
@@ -1376,17 +1379,17 @@ constexpr auto operator-(Integer lhs, decimal64 rhs) noexcept
13761379
auto sig_lhs {static_cast<promoted_significand_type>(detail::make_positive_unsigned(lhs))};
13771380
const bool abs_lhs_bigger {sig_lhs > abs(rhs)};
13781381

1379-
decimal64::biased_exponent_type exp_lhs {0};
1382+
exp_type exp_lhs {0};
13801383
detail::normalize<decimal64>(sig_lhs, exp_lhs);
13811384
const auto final_sig_lhs {static_cast<decimal64::significand_type>(detail::make_positive_unsigned(sig_lhs))};
13821385

13831386
auto sig_rhs {rhs.full_significand()};
13841387
auto exp_rhs {rhs.biased_exponent()};
13851388
detail::normalize<decimal64>(sig_rhs, exp_rhs);
13861389

1387-
return {detail::d64_sub_impl<decimal64>(final_sig_lhs, exp_lhs, (lhs < 0),
1388-
sig_rhs, exp_rhs, rhs.isneg(),
1389-
abs_lhs_bigger)};
1390+
return detail::d64_sub_impl<decimal64>(final_sig_lhs, exp_lhs, (lhs < 0),
1391+
sig_rhs, exp_rhs, rhs.isneg(),
1392+
abs_lhs_bigger);
13901393
}
13911394

13921395
constexpr auto operator*(decimal64 lhs, decimal64 rhs) noexcept -> decimal64
@@ -1409,15 +1412,16 @@ constexpr auto operator*(decimal64 lhs, decimal64 rhs) noexcept -> decimal64
14091412
auto rhs_exp {rhs.biased_exponent()};
14101413
detail::normalize<decimal64>(rhs_sig, rhs_exp);
14111414

1412-
return {detail::d64_mul_impl<decimal64>(lhs_sig, lhs_exp, lhs.isneg(),
1413-
rhs_sig, rhs_exp, rhs.isneg())};
1415+
return detail::d64_mul_impl<decimal64>(lhs_sig, lhs_exp, lhs.isneg(),
1416+
rhs_sig, rhs_exp, rhs.isneg());
14141417
}
14151418

14161419
template <typename Integer>
14171420
constexpr auto operator*(decimal64 lhs, Integer rhs) noexcept
14181421
BOOST_DECIMAL_REQUIRES_RETURN(detail::is_integral_v, Integer, decimal64)
14191422
{
14201423
using promoted_significand_type = detail::promote_significand_t<decimal64, Integer>;
1424+
using exp_type = decimal64::biased_exponent_type;
14211425

14221426
#ifndef BOOST_DECIMAL_FAST_MATH
14231427
if (isnan(lhs) || isinf(lhs))
@@ -1431,12 +1435,12 @@ constexpr auto operator*(decimal64 lhs, Integer rhs) noexcept
14311435
detail::normalize<decimal64>(lhs_sig, lhs_exp);
14321436

14331437
auto rhs_sig {static_cast<promoted_significand_type>(detail::make_positive_unsigned(rhs))};
1434-
decimal64::biased_exponent_type rhs_exp {0};
1438+
exp_type rhs_exp {0};
14351439
detail::normalize<decimal64>(rhs_sig, rhs_exp);
14361440
const auto final_rhs_sig {static_cast<decimal64::significand_type>(rhs_sig)};
14371441

1438-
return {detail::d64_mul_impl<decimal64>(lhs_sig, lhs_exp, lhs.isneg(),
1439-
final_rhs_sig, rhs_exp, (rhs < 0))};
1442+
return detail::d64_mul_impl<decimal64>(lhs_sig, lhs_exp, lhs.isneg(),
1443+
final_rhs_sig, rhs_exp, (rhs < 0));
14401444
}
14411445

14421446
template <typename Integer>
@@ -1459,6 +1463,8 @@ template <typename Integer>
14591463
constexpr auto operator/(decimal64 lhs, Integer rhs) noexcept
14601464
BOOST_DECIMAL_REQUIRES_RETURN(detail::is_integral_v, Integer, decimal64)
14611465
{
1466+
using exp_type = decimal64::biased_exponent_type;
1467+
14621468
#ifndef BOOST_DECIMAL_FAST_MATH
14631469
// Check pre-conditions
14641470
constexpr decimal64 zero {0, 0};
@@ -1494,7 +1500,7 @@ constexpr auto operator/(decimal64 lhs, Integer rhs) noexcept
14941500
detail::decimal64_components lhs_components {lhs_sig, lhs_exp, lhs.isneg()};
14951501

14961502
auto rhs_sig {static_cast<std::uint64_t>(detail::make_positive_unsigned(rhs))};
1497-
std::int32_t rhs_exp {};
1503+
exp_type rhs_exp {};
14981504
detail::decimal64_components rhs_components {detail::shrink_significand<std::uint64_t>(rhs_sig, rhs_exp), rhs_exp, rhs < 0};
14991505

15001506
return detail::d64_generic_div_impl<decimal64>(lhs_components, rhs_components);

0 commit comments

Comments
 (0)