Test that max_k is correctly defined

This commit is contained in:
Victor Zverovich 2020-09-23 15:12:03 -07:00
parent 51f8d0cc21
commit 6c025520aa
2 changed files with 18 additions and 4 deletions

View File

@ -1198,10 +1198,11 @@ inline fp operator*(fp x, fp y) { return {multiply(x.f, y.f), x.e + y.e + 64}; }
// (binary) exponent satisfies `min_exponent <= c_k.e <= min_exponent + 28`.
inline fp get_cached_power(int min_exponent, int& pow10_exponent) {
const int shift = 32;
int index = static_cast<int>(((min_exponent + fp::significand_size - 1) *
(data::log10_2_significand >> shift) +
((int64_t(1) << shift) - 1)) // ceil
>> 32 // arithmetic shift
const auto significand = static_cast<int64_t>(data::log10_2_significand);
int index = static_cast<int>(
((min_exponent + fp::significand_size - 1) * (significand >> shift) +
((int64_t(1) << shift) - 1)) // ceil
>> 32 // arithmetic shift
);
// Decimal exponent of the first (smallest) cached power of 10.
const int first_dec_exp = -348;

View File

@ -220,6 +220,19 @@ TEST(FPTest, GetCachedPower) {
}
}
TEST(FPTest, DragonboxMaxK) {
using fmt::detail::dragonbox::floor_log10_pow2;
using float_info = fmt::detail::dragonbox::float_info<float>;
EXPECT_EQ(fmt::detail::const_check(float_info::max_k),
float_info::kappa - floor_log10_pow2(float_info::min_exponent -
float_info::significand_bits));
using double_info = fmt::detail::dragonbox::float_info<double>;
EXPECT_EQ(
fmt::detail::const_check(double_info::max_k),
double_info::kappa - floor_log10_pow2(double_info::min_exponent -
double_info::significand_bits));
}
TEST(FPTest, GetRoundDirection) {
using fmt::detail::get_round_direction;
using fmt::detail::round_direction;