Skip to content

Commit 4bbb42f

Browse files
authored
Merge pull request #583 from cppalliance/582
2 parents de632a2 + 7a80fbe commit 4bbb42f

File tree

4 files changed

+48
-56
lines changed

4 files changed

+48
-56
lines changed

include/boost/decimal/decimal128.hpp

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -627,17 +627,17 @@ constexpr auto decimal128::unbiased_exponent() const noexcept -> std::uint64_t
627627

628628
const auto exp_comb_bits {(bits_.high & detail::d128_comb_11_mask.high)};
629629

630-
if (exp_comb_bits == detail::d128_comb_11_mask.high)
630+
switch (exp_comb_bits)
631631
{
632-
expval = (bits_.high & detail::d128_comb_11_mask.high) >> (high_word_significand_bits + 1);
633-
}
634-
else if (exp_comb_bits == detail::d128_comb_10_mask.high)
635-
{
636-
expval = UINT64_C(0b10000000000000);
637-
}
638-
else if (exp_comb_bits == detail::d128_comb_01_mask.high)
639-
{
640-
expval = UINT64_C(0b01000000000000);
632+
case detail::d128_comb_11_mask.high:
633+
expval = (bits_.high & detail::d128_comb_11_mask.high) >> (high_word_significand_bits + 1);
634+
break;
635+
case detail::d128_comb_10_mask.high:
636+
expval = UINT64_C(0b10000000000000);
637+
break;
638+
case detail::d128_comb_01_mask.high:
639+
expval = UINT64_C(0b01000000000000);
640+
break;
641641
}
642642

643643
expval |= (bits_.high & detail::d128_exponent_mask.high) >> high_word_significand_bits;
@@ -657,14 +657,9 @@ constexpr auto decimal128::full_significand() const noexcept -> detail::uint128
657657
if ((bits_.high & detail::d128_comb_11_mask.high) == detail::d128_comb_11_mask.high)
658658
{
659659
// Only need the one bit of T because the other 3 are implied 0s
660-
if ((bits_.high & detail::d128_comb_11_significand_bits.high) == detail::d128_comb_11_significand_bits.high)
661-
{
662-
significand = detail::uint128{0b10010000000000000000000000000000000000000000000000,0};
663-
}
664-
else
665-
{
666-
significand = detail::uint128{0b10000000000000000000000000000000000000000000000000,0};
667-
}
660+
significand = (bits_.high & detail::d128_comb_11_significand_bits.high) == detail::d128_comb_11_significand_bits.high ?
661+
detail::uint128{0b10010000000000000000000000000000000000000000000000,0} :
662+
detail::uint128{0b10000000000000000000000000000000000000000000000000,0};
668663
}
669664
else
670665
{

include/boost/decimal/decimal32.hpp

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,18 +1348,18 @@ constexpr auto decimal32::unbiased_exponent() const noexcept -> std::uint32_t
13481348

13491349
const auto exp_comb_bits {(bits_ & detail::d32_comb_11_mask)};
13501350

1351-
if (exp_comb_bits == detail::d32_comb_11_mask)
1351+
switch (exp_comb_bits)
13521352
{
1353-
// bits 2 and 3 are the exp part of the combination field
1354-
expval = (bits_ & detail::d32_comb_11_exp_bits) >> (detail::d32_significand_bits + 1);
1355-
}
1356-
else if (exp_comb_bits == detail::d32_comb_10_mask)
1357-
{
1358-
expval = UINT32_C(0b10000000);
1359-
}
1360-
else if (exp_comb_bits == detail::d32_comb_01_mask)
1361-
{
1362-
expval = UINT32_C(0b01000000);
1353+
case detail::d32_comb_11_mask:
1354+
// bits 2 and 3 are the exp part of the combination field
1355+
expval = (bits_ & detail::d32_comb_11_exp_bits) >> (detail::d32_significand_bits + 1);
1356+
break;
1357+
case detail::d32_comb_10_mask:
1358+
expval = UINT32_C(0b10000000);
1359+
break;
1360+
case detail::d32_comb_01_mask:
1361+
expval = UINT32_C(0b01000000);
1362+
break;
13631363
}
13641364

13651365
expval |= (bits_ & detail::d32_exponent_mask) >> detail::d32_significand_bits;
@@ -1386,14 +1386,9 @@ constexpr auto decimal32::full_significand() const noexcept -> std::uint32_t
13861386
if ((bits_ & detail::d32_comb_11_mask) == detail::d32_comb_11_mask)
13871387
{
13881388
// Only need the one bit of T because the other 3 are implied
1389-
if ((bits_ & detail::d32_comb_11_significand_bits) == detail::d32_comb_11_significand_bits)
1390-
{
1391-
significand = UINT32_C(0b1001'0000000000'0000000000);
1392-
}
1393-
else
1394-
{
1395-
significand = UINT32_C(0b1000'0000000000'0000000000);
1396-
}
1389+
significand = (bits_ & detail::d32_comb_11_significand_bits) == detail::d32_comb_11_significand_bits ?
1390+
UINT32_C(0b1001'0000000000'0000000000) :
1391+
UINT32_C(0b1000'0000000000'0000000000);
13971392
}
13981393
else
13991394
{

include/boost/decimal/decimal64.hpp

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -991,18 +991,17 @@ constexpr auto decimal64::unbiased_exponent() const noexcept -> std::uint64_t
991991

992992
const auto exp_comb_bits {(bits_ & detail::d64_comb_11_mask)};
993993

994-
if (exp_comb_bits == detail::d64_comb_11_mask)
994+
switch (exp_comb_bits)
995995
{
996-
// bits 2 and 3 are the exp part of the combination field
997-
expval = (bits_ & detail::d64_comb_11_exp_bits) >> (detail::d64_significand_bits + 1);
998-
}
999-
else if (exp_comb_bits == detail::d64_comb_10_mask)
1000-
{
1001-
expval = UINT64_C(0b1000000000);
1002-
}
1003-
else if (exp_comb_bits == detail::d64_comb_01_mask)
1004-
{
1005-
expval = UINT64_C(0b0100000000);
996+
case detail::d64_comb_11_mask:
997+
expval = (bits_ & detail::d64_comb_11_exp_bits) >> (detail::d64_significand_bits + 1);
998+
break;
999+
case detail::d64_comb_10_mask:
1000+
expval = UINT64_C(0b1000000000);
1001+
break;
1002+
case detail::d64_comb_01_mask:
1003+
expval = UINT64_C(0b0100000000);
1004+
break;
10061005
}
10071006

10081007
expval |= (bits_ & detail::d64_exponent_mask) >> detail::d64_significand_bits;
@@ -1022,14 +1021,9 @@ constexpr auto decimal64::full_significand() const noexcept -> std::uint64_t
10221021
if ((bits_ & detail::d64_comb_11_mask) == detail::d64_comb_11_mask)
10231022
{
10241023
// Only need the one bit of T because the other 3 are implied
1025-
if ((bits_ & detail::d64_comb_11_significand_bits) == detail::d64_comb_11_significand_bits)
1026-
{
1027-
significand = UINT64_C(0b1001'0000000000'0000000000'0000000000'0000000000'0000000000);
1028-
}
1029-
else
1030-
{
1031-
significand = UINT64_C(0b1000'0000000000'0000000000'0000000000'0000000000'0000000000);
1032-
}
1024+
significand = (bits_ & detail::d64_comb_11_significand_bits) == detail::d64_comb_11_significand_bits ?
1025+
UINT64_C(0b1001'0000000000'0000000000'0000000000'0000000000'0000000000) :
1026+
UINT64_C(0b1000'0000000000'0000000000'0000000000'0000000000'0000000000);
10331027
}
10341028
else
10351029
{

include/boost/decimal/detail/config.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,4 +276,12 @@ typedef unsigned __int128 uint128_t;
276276
# define BOOST_DECIMAL_INLINE_VARIABLE static
277277
#endif
278278

279+
#if defined(__GNUC__) || defined(__clang__)
280+
# define BOOST_DECIMAL_UNREACHABLE __builtin_unreachable()
281+
#elif defined(_MSC_VER)
282+
# define BOOST_DECIMAL_UNREACHABLE __assume(0)
283+
#else
284+
# define BOOST_DECIMAL_UNREACHABLE std::abort()
285+
#endif
286+
279287
#endif // BOOST_DECIMAL_DETAIL_CONFIG_HPP

0 commit comments

Comments
 (0)