Skip to content

Commit

Permalink
Make compressed cache recovery leverage the bound on the decimal expo…
Browse files Browse the repository at this point in the history
…nent; make static_assert C++11-compatible; add another static_assert for validation
  • Loading branch information
jk-jeon committed May 4, 2024
1 parent d0e3634 commit 7ce54f7
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions include/dragonbox/dragonbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -2094,9 +2094,13 @@ namespace jkj {
static JKJ_CONSTEXPR20 cache_entry_type get_cache(DecimalExponent k) noexcept {
// Compute the base index.
// Supposed to compute (k - min_k) / compression_ratio.
static_assert(max_k - min_k <= 89 && compression_ratio == 13);
auto const cache_index = DecimalExponent(
(detail::stdr::uint_fast16_t(k - min_k) * detail::stdr::uint_fast16_t(79)) >> 10);
static_assert(max_k - min_k <= 89 && compression_ratio == 13, "");
static_assert(max_k - min_k <= detail::stdr::numeric_limits<DecimalExponent>::max(),
"");
auto const cache_index =
DecimalExponent(detail::stdr::uint_fast16_t(DecimalExponent(k - min_k) *
detail::stdr::int_fast16_t(79)) >>
10);
auto const kb = DecimalExponent(cache_index * compression_ratio + min_k);
auto const offset = DecimalExponent(k - kb);

Expand Down Expand Up @@ -2192,9 +2196,13 @@ namespace jkj {
static JKJ_CONSTEXPR20 cache_entry_type get_cache(DecimalExponent k) noexcept {
// Compute the base index.
// Supposed to compute (k - min_k) / compression_ratio.
static_assert(max_k - min_k <= 619 && compression_ratio == 27);
auto const cache_index = DecimalExponent(
(detail::stdr::uint_fast32_t(k - min_k) * detail::stdr::uint_fast32_t(607)) >> 14);
static_assert(max_k - min_k <= 619 && compression_ratio == 27, "");
static_assert(max_k - min_k <= detail::stdr::numeric_limits<DecimalExponent>::max(),
"");
auto const cache_index =
DecimalExponent(detail::stdr::uint_fast32_t(DecimalExponent(k - min_k) *
detail::stdr::int_fast32_t(607)) >>
14);
auto const kb = DecimalExponent(cache_index * compression_ratio + min_k);
auto const offset = DecimalExponent(k - kb);

Expand Down

0 comments on commit 7ce54f7

Please sign in to comment.