Skip to content

Commit 58037a9

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

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

include/boost/decimal/decimal64_fast.hpp

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -905,17 +905,18 @@ constexpr auto operator+(decimal64_fast lhs, decimal64_fast rhs) noexcept -> dec
905905
return lhs - abs(rhs);
906906
}
907907

908-
return {detail::d64_add_impl<decimal64_fast>(
908+
return detail::d64_add_impl<decimal64_fast>(
909909
lhs.significand_, lhs.biased_exponent(), lhs.sign_,
910910
rhs.significand_, rhs.biased_exponent(), rhs.sign_
911-
)};
911+
);
912912
}
913913

914914
template <typename Integer>
915915
constexpr auto operator+(decimal64_fast lhs, Integer rhs) noexcept
916916
BOOST_DECIMAL_REQUIRES_RETURN(detail::is_integral_v, Integer, decimal64_fast)
917917
{
918918
using promoted_significand_type = detail::promote_significand_t<decimal64_fast, Integer>;
919+
using exp_type = decimal64_fast::biased_exponent_type;
919920

920921
#ifndef BOOST_DECIMAL_FAST_MATH
921922
if (isnan(lhs) || isinf(lhs))
@@ -934,7 +935,7 @@ constexpr auto operator+(decimal64_fast lhs, Integer rhs) noexcept
934935

935936
auto lhs_components {detail::decimal64_fast_components{lhs.significand_, lhs.biased_exponent(), lhs.isneg()}};
936937

937-
decimal64_fast::biased_exponent_type exp_rhs {0};
938+
exp_type exp_rhs {0};
938939
detail::normalize<decimal64>(sig_rhs, exp_rhs);
939940
auto unsigned_sig_rhs {static_cast<detail::decimal64_fast_components::significand_type>(sig_rhs)};
940941
auto rhs_components {detail::decimal64_fast_components{unsigned_sig_rhs, exp_rhs, (rhs < 0)}};
@@ -991,18 +992,19 @@ constexpr auto operator-(decimal64_fast lhs, decimal64_fast rhs) noexcept -> dec
991992

992993
const bool abs_lhs_bigger {abs(lhs) > abs(rhs)};
993994

994-
return {detail::d64_sub_impl<decimal64_fast>(
995+
return detail::d64_sub_impl<decimal64_fast>(
995996
lhs.significand_, lhs.biased_exponent(), lhs.sign_,
996997
rhs.significand_, rhs.biased_exponent(), rhs.sign_,
997998
abs_lhs_bigger
998-
)};
999+
);
9991000
}
10001001

10011002
template <typename Integer>
10021003
constexpr auto operator-(decimal64_fast lhs, Integer rhs) noexcept
10031004
BOOST_DECIMAL_REQUIRES_RETURN(detail::is_integral_v, Integer, decimal64_fast)
10041005
{
10051006
using promoted_significand_type = detail::promote_significand_t<decimal64_fast, Integer>;
1007+
using exp_type = decimal64_fast::biased_exponent_type;
10061008

10071009
#ifndef BOOST_DECIMAL_FAST_MATH
10081010
if (isinf(lhs) || isnan(lhs))
@@ -1019,20 +1021,21 @@ constexpr auto operator-(decimal64_fast lhs, Integer rhs) noexcept
10191021
auto sig_rhs {static_cast<promoted_significand_type>(detail::make_positive_unsigned(rhs))};
10201022
const bool abs_lhs_bigger {abs(lhs) > detail::make_positive_unsigned(rhs)};
10211023

1022-
decimal64_fast::biased_exponent_type exp_rhs {0};
1024+
exp_type exp_rhs {0};
10231025
detail::normalize<decimal64>(sig_rhs, exp_rhs);
10241026
const auto final_sig_rhs {static_cast<decimal64_fast::significand_type>(sig_rhs)};
10251027

1026-
return {detail::d64_sub_impl<decimal64_fast>(lhs.significand_, lhs.biased_exponent(), lhs.sign_,
1028+
return detail::d64_sub_impl<decimal64_fast>(lhs.significand_, lhs.biased_exponent(), lhs.sign_,
10271029
final_sig_rhs, exp_rhs, (rhs < 0),
1028-
abs_lhs_bigger)};
1030+
abs_lhs_bigger);
10291031
}
10301032

10311033
template <typename Integer>
10321034
constexpr auto operator-(Integer lhs, decimal64_fast rhs) noexcept
10331035
BOOST_DECIMAL_REQUIRES_RETURN(detail::is_integral_v, Integer, decimal64_fast)
10341036
{
10351037
using promoted_significand_type = detail::promote_significand_t<decimal64_fast, Integer>;
1038+
using exp_type = decimal64_fast::biased_exponent_type;
10361039

10371040
#ifndef BOOST_DECIMAL_FAST_MATH
10381041
if (isinf(rhs) || isnan(rhs))
@@ -1049,13 +1052,13 @@ constexpr auto operator-(Integer lhs, decimal64_fast rhs) noexcept
10491052
auto sig_lhs {static_cast<promoted_significand_type>(detail::make_positive_unsigned(lhs))};
10501053
const bool abs_lhs_bigger {sig_lhs > abs(rhs)};
10511054

1052-
decimal64_fast::biased_exponent_type exp_lhs {0};
1055+
exp_type exp_lhs {0};
10531056
detail::normalize<decimal64>(sig_lhs, exp_lhs);
10541057
const auto final_sig_lhs {static_cast<decimal64_fast::significand_type>(sig_lhs)};
10551058

1056-
return {detail::d64_sub_impl<decimal64_fast>(final_sig_lhs, exp_lhs, (lhs < 0),
1059+
return detail::d64_sub_impl<decimal64_fast>(final_sig_lhs, exp_lhs, (lhs < 0),
10571060
rhs.significand_, rhs.biased_exponent(), rhs.sign_,
1058-
abs_lhs_bigger)};
1061+
abs_lhs_bigger);
10591062
}
10601063

10611064
constexpr auto operator*(decimal64_fast lhs, decimal64_fast rhs) noexcept -> decimal64_fast
@@ -1090,6 +1093,8 @@ constexpr auto operator*(decimal64_fast lhs, decimal64_fast rhs) noexcept -> dec
10901093

10911094
auto res_sig {static_cast<unsigned_int128_type>(lhs.significand_) * static_cast<unsigned_int128_type>(rhs.significand_)};
10921095

1096+
// TODO(mborland): Insert division trick to get this into uint_fast64_t rather than u128 of sorts
1097+
10931098
auto res_exp {lhs.biased_exponent() + rhs.biased_exponent()};
10941099
bool sign {lhs.sign_ != rhs.sign_};
10951100

@@ -1103,6 +1108,7 @@ constexpr auto operator*(decimal64_fast lhs, Integer rhs) noexcept
11031108
BOOST_DECIMAL_REQUIRES_RETURN(detail::is_integral_v, Integer, decimal64_fast)
11041109
{
11051110
using promoted_significand_type = detail::promote_significand_t<decimal64, Integer>;
1111+
using exp_type = decimal64_fast::biased_exponent_type;
11061112

11071113
#ifndef BOOST_DECIMAL_FAST_MATH
11081114
if (isnan(lhs) || isinf(lhs))
@@ -1112,14 +1118,14 @@ constexpr auto operator*(decimal64_fast lhs, Integer rhs) noexcept
11121118
#endif
11131119

11141120
auto rhs_sig {static_cast<promoted_significand_type>(detail::make_positive_unsigned(rhs))};
1115-
decimal64_fast::biased_exponent_type rhs_exp {0};
1121+
exp_type rhs_exp {0};
11161122
detail::normalize<decimal64>(rhs_sig, rhs_exp);
11171123
auto final_rhs_sig {static_cast<decimal64_fast::significand_type>(rhs_sig)};
11181124

1119-
return {detail::d64_mul_impl<decimal64_fast>(
1125+
return detail::d64_mul_impl<decimal64_fast>(
11201126
lhs.significand_, lhs.biased_exponent(), lhs.sign_,
11211127
final_rhs_sig, rhs_exp, (rhs < 0)
1122-
)};
1128+
);
11231129
}
11241130

11251131
template <typename Integer>

0 commit comments

Comments
 (0)