Skip to content

Commit e50c56e

Browse files
committed
Fix constexprness
1 parent 3604ce5 commit e50c56e

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

include/boost/decimal/detail/power_tables.hpp

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,24 @@
99
#include <boost/decimal/detail/type_traits.hpp>
1010

1111
#ifndef BOOST_DECIMAL_BUILD_MODULE
12-
#include <array>
1312
#include <cstdint>
1413
#endif
1514

1615
namespace boost {
1716
namespace decimal {
1817
namespace detail {
1918

20-
BOOST_DECIMAL_CONSTEXPR_VARIABLE std::array<std::uint64_t, 20> powers_of_10 =
21-
{{
19+
BOOST_DECIMAL_CONSTEXPR_VARIABLE std::uint64_t powers_of_10[20] =
20+
{
2221
UINT64_C(1), UINT64_C(10), UINT64_C(100), UINT64_C(1000), UINT64_C(10000), UINT64_C(100000), UINT64_C(1000000),
2322
UINT64_C(10000000), UINT64_C(100000000), UINT64_C(1000000000), UINT64_C(10000000000), UINT64_C(100000000000),
2423
UINT64_C(1000000000000), UINT64_C(10000000000000), UINT64_C(100000000000000), UINT64_C(1000000000000000),
2524
UINT64_C(10000000000000000), UINT64_C(100000000000000000), UINT64_C(1000000000000000000), UINT64_C(10000000000000000000)
26-
}};
25+
};
2726

2827
template <typename T>
2928
constexpr auto pow10(T n) noexcept -> T
3029
{
31-
BOOST_DECIMAL_IF_CONSTEXPR (detail::is_signed_v<T>)
32-
{
33-
BOOST_DECIMAL_ASSERT(n >= 0);
34-
}
35-
BOOST_DECIMAL_ASSERT(n <= 19);
36-
3730
return static_cast<T>(powers_of_10[static_cast<std::size_t>(n)]);
3831
}
3932

@@ -54,6 +47,27 @@ constexpr auto pow10(detail::uint128 n) noexcept -> detail::uint128
5447
return res;
5548
}
5649

50+
#ifdef BOOST_DECIMAL_HAS_INT128
51+
52+
template <>
53+
constexpr auto pow10(detail::uint128_t n) noexcept -> detail::uint128_t
54+
{
55+
detail::uint128_t res {1};
56+
if (n <= 19)
57+
{
58+
res = powers_of_10[static_cast<std::size_t>(n)];
59+
}
60+
else
61+
{
62+
res = powers_of_10[static_cast<std::size_t>(19)];
63+
res *= powers_of_10[static_cast<std::size_t>(n - 19)];
64+
}
65+
66+
return res;
67+
}
68+
69+
#endif
70+
5771
} // namespace detail
5872
} // namespace decimal
5973
} // namespace boost

0 commit comments

Comments
 (0)