mirror of
https://github.com/fmtlib/fmt.git
synced 2025-08-01 19:54:46 +02:00
Test that max_k is correctly defined
This commit is contained in:
@@ -1198,8 +1198,9 @@ 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`.
|
// (binary) exponent satisfies `min_exponent <= c_k.e <= min_exponent + 28`.
|
||||||
inline fp get_cached_power(int min_exponent, int& pow10_exponent) {
|
inline fp get_cached_power(int min_exponent, int& pow10_exponent) {
|
||||||
const int shift = 32;
|
const int shift = 32;
|
||||||
int index = static_cast<int>(((min_exponent + fp::significand_size - 1) *
|
const auto significand = static_cast<int64_t>(data::log10_2_significand);
|
||||||
(data::log10_2_significand >> shift) +
|
int index = static_cast<int>(
|
||||||
|
((min_exponent + fp::significand_size - 1) * (significand >> shift) +
|
||||||
((int64_t(1) << shift) - 1)) // ceil
|
((int64_t(1) << shift) - 1)) // ceil
|
||||||
>> 32 // arithmetic shift
|
>> 32 // arithmetic shift
|
||||||
);
|
);
|
||||||
|
@@ -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) {
|
TEST(FPTest, GetRoundDirection) {
|
||||||
using fmt::detail::get_round_direction;
|
using fmt::detail::get_round_direction;
|
||||||
using fmt::detail::round_direction;
|
using fmt::detail::round_direction;
|
||||||
|
Reference in New Issue
Block a user