Skip to content

Commit 8be21d1

Browse files
committed
Add additional step in 32 and 64 bit cases
1 parent 9a35fa2 commit 8be21d1

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

include/boost/decimal/detail/remove_trailing_zeros.hpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,13 @@ constexpr auto remove_trailing_zeros(std::uint32_t n) noexcept -> remove_trailin
4040
{
4141
std::size_t s {};
4242

43-
auto r = rotr<32>(n * UINT32_C(184254097), 4);
44-
auto b = r < UINT32_C(429497);
43+
auto r = rotr<32>(n * UINT32_C(15273505), 8);
44+
auto b = r < UINT32_C(43);
45+
s = s * 2U + static_cast<std::size_t>(b);
46+
n = b ? r : n;
47+
48+
r = rotr<32>(n * UINT32_C(184254097), 4);
49+
b = r < UINT32_C(429497);
4550
s = s * 2U + static_cast<std::size_t>(b);
4651
n = b ? r : n;
4752

@@ -62,8 +67,13 @@ constexpr auto remove_trailing_zeros(std::uint64_t n) noexcept -> remove_trailin
6267
{
6368
std::size_t s {};
6469

65-
auto r = rotr<64>(n * UINT64_C(28999941890838049), 8);
66-
auto b = r < UINT64_C(184467440738);
70+
auto r = rotr<64>(n * UINT64_C(230079197716545), 16);
71+
auto b = r < UINT64_C(1845);
72+
s = s * 2U + static_cast<std::size_t>(b);
73+
n = b ? r : n;
74+
75+
r = rotr<64>(n * UINT64_C(28999941890838049), 8);
76+
b = r < UINT64_C(184467440738);
6777
s = s * 2U + static_cast<std::size_t>(b);
6878
n = b ? r : n;
6979

0 commit comments

Comments
 (0)