Skip to content

Commit cbde558

Browse files
committed
Using std::uint_fastXX_t instead of std::uintXX_t for internal storage
1 parent 31f87e3 commit cbde558

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

include/boost/decimal/decimal32_fast.hpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,36 +19,37 @@ namespace decimal {
1919

2020
namespace detail {
2121

22-
BOOST_DECIMAL_CONSTEXPR_VARIABLE auto d32_fast_inf = std::numeric_limits<std::uint32_t>::max();
23-
BOOST_DECIMAL_CONSTEXPR_VARIABLE auto d32_fast_qnan = std::numeric_limits<std::uint32_t>::max() - 1;
24-
BOOST_DECIMAL_CONSTEXPR_VARIABLE auto d32_fast_snan = std::numeric_limits<std::uint32_t>::max() - 2;
22+
BOOST_DECIMAL_CONSTEXPR_VARIABLE auto d32_fast_inf = std::numeric_limits<std::uint_fast32_t>::max();
23+
BOOST_DECIMAL_CONSTEXPR_VARIABLE auto d32_fast_qnan = std::numeric_limits<std::uint_fast32_t>::max() - 1;
24+
BOOST_DECIMAL_CONSTEXPR_VARIABLE auto d32_fast_snan = std::numeric_limits<std::uint_fast32_t>::max() - 2;
2525

2626
}
2727

2828
class decimal32_fast final
2929
{
3030
public:
31-
using significand_type = std::uint32_t;
31+
using significand_type = std::uint_fast32_t;
3232

3333
private:
3434
// In regular decimal32 we have to decode the 24 bits of the significand and the 8 bits of the exp
35-
// Here we just use them directly at the cost of 2 extra bytes of internal state
35+
// Here we just use them directly at the cost of at least 2 extra bytes of internal state
36+
// since the fast integer types will be at least 32 and 8 bits respectively
3637

37-
std::uint32_t significand_ {};
38-
std::uint8_t exponent_ {};
38+
std::uint_fast32_t significand_ {};
39+
std::uint_fast8_t exponent_ {};
3940
bool sign_ {};
4041

4142
constexpr auto isneg() const noexcept -> bool
4243
{
4344
return sign_;
4445
}
4546

46-
constexpr auto full_significand() const noexcept -> std::uint32_t
47+
constexpr auto full_significand() const noexcept -> std::uint_fast32_t
4748
{
4849
return significand_;
4950
}
5051

51-
constexpr auto unbiased_exponent() const noexcept -> std::uint8_t
52+
constexpr auto unbiased_exponent() const noexcept -> std::uint_fast8_t
5253
{
5354
return exponent_;
5455
}
@@ -142,7 +143,7 @@ class decimal32_fast final
142143
explicit constexpr operator detail::uint128_t() const noexcept;
143144
#endif
144145

145-
friend constexpr auto direct_init(std::uint32_t significand, std::uint8_t exponent, bool sign) noexcept -> decimal32_fast;
146+
friend constexpr auto direct_init(std::uint_fast32_t significand, std::uint_fast8_t exponent, bool sign) noexcept -> decimal32_fast;
146147
};
147148

148149
template <typename T1, typename T2, std::enable_if_t<detail::is_integral_v<T1> && detail::is_integral_v<T2>, bool>>
@@ -173,27 +174,26 @@ constexpr decimal32_fast::decimal32_fast(T1 coeff, T2 exp, bool sign) noexcept
173174
# pragma GCC diagnostic pop
174175
#endif
175176

176-
exp += static_cast<std::uint8_t>(digits_to_remove);
177+
exp += static_cast<std::uint_fast8_t>(digits_to_remove);
177178
exp += static_cast<T2>(detail::fenv_round(unsigned_coeff, isneg));
178179
}
179180

180-
auto reduced_coeff {static_cast<std::uint32_t>(unsigned_coeff)};
181-
significand_ = static_cast<std::uint32_t>(reduced_coeff);
181+
significand_ = static_cast<std::uint_fast32_t>(unsigned_coeff);
182182

183183
// Normalize the handling of zeros
184184
if (significand_ == UINT32_C(0))
185185
{
186186
exp = 0;
187187
}
188188

189-
auto biased_exp {static_cast<std::uint32_t>(exp + detail::bias)};
189+
auto biased_exp {static_cast<std::uint_fast32_t>(exp + detail::bias)};
190190
if (biased_exp > std::numeric_limits<std::uint8_t>::max())
191191
{
192192
significand_ = detail::d32_fast_inf;
193193
}
194194
else
195195
{
196-
exponent_ = static_cast<std::uint8_t>(biased_exp);
196+
exponent_ = static_cast<std::uint_fast8_t>(biased_exp);
197197
}
198198
}
199199

@@ -236,7 +236,7 @@ BOOST_DECIMAL_CXX20_CONSTEXPR decimal32_fast::decimal32_fast(Float val) noexcept
236236
# pragma GCC diagnostic pop
237237
#endif
238238

239-
constexpr auto direct_init(std::uint32_t significand, std::uint8_t exponent, bool sign = false) noexcept -> decimal32_fast
239+
constexpr auto direct_init(std::uint_fast32_t significand, std::uint_fast8_t exponent, bool sign = false) noexcept -> decimal32_fast
240240
{
241241
decimal32_fast val;
242242
val.significand_ = significand;
@@ -687,7 +687,7 @@ struct numeric_limits<boost::decimal::decimal32_fast>
687687
BOOST_DECIMAL_ATTRIBUTE_UNUSED static constexpr int min_exponent10 = min_exponent;
688688
BOOST_DECIMAL_ATTRIBUTE_UNUSED static constexpr int max_exponent = 96;
689689
BOOST_DECIMAL_ATTRIBUTE_UNUSED static constexpr int max_exponent10 = max_exponent;
690-
BOOST_DECIMAL_ATTRIBUTE_UNUSED static constexpr bool traps = numeric_limits<std::uint32_t>::traps;
690+
BOOST_DECIMAL_ATTRIBUTE_UNUSED static constexpr bool traps = numeric_limits<std::uint_fast32_t>::traps;
691691
BOOST_DECIMAL_ATTRIBUTE_UNUSED static constexpr bool tinyness_before = true;
692692

693693
// Member functions

0 commit comments

Comments
 (0)