mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-30 05:40:06 +00:00
Simplify float_info
This commit is contained in:
parent
f91f61cd13
commit
72f487562d
@ -1788,11 +1788,10 @@ template <> struct cache_accessor<double> {
|
||||
// Various integer checks
|
||||
template <class T>
|
||||
bool is_left_endpoint_integer_shorter_interval(int exponent) noexcept {
|
||||
return exponent >=
|
||||
float_info<
|
||||
T>::case_shorter_interval_left_endpoint_lower_threshold &&
|
||||
exponent <=
|
||||
float_info<T>::case_shorter_interval_left_endpoint_upper_threshold;
|
||||
const int case_shorter_interval_left_endpoint_lower_threshold = 2;
|
||||
const int case_shorter_interval_left_endpoint_upper_threshold = 3;
|
||||
return exponent >= case_shorter_interval_left_endpoint_lower_threshold &&
|
||||
exponent <= case_shorter_interval_left_endpoint_upper_threshold;
|
||||
}
|
||||
|
||||
// Remove trailing zeros from n and return the number of zeros removed (float)
|
||||
@ -1933,7 +1932,8 @@ template <typename T> decimal_fp<T> to_decimal(T x) noexcept {
|
||||
static_cast<int>((br & exponent_mask<T>()) >> num_significand_bits<T>());
|
||||
|
||||
if (exponent != 0) { // Check if normal.
|
||||
exponent += float_info<T>::exponent_bias - num_significand_bits<T>();
|
||||
const int exponent_bias = std::numeric_limits<T>::max_exponent - 1;
|
||||
exponent -= exponent_bias + num_significand_bits<T>();
|
||||
|
||||
// Shorter interval case; proceed like Schubfach.
|
||||
// In fact, when exponent == 1 and significand == 0, the interval is
|
||||
@ -1944,7 +1944,8 @@ template <typename T> decimal_fp<T> to_decimal(T x) noexcept {
|
||||
} else {
|
||||
// Subnormal case; the interval is always regular.
|
||||
if (significand == 0) return {0, 0};
|
||||
exponent = float_info<T>::min_exponent - num_significand_bits<T>();
|
||||
exponent =
|
||||
std::numeric_limits<T>::min_exponent - num_significand_bits<T>() - 1;
|
||||
}
|
||||
|
||||
const bool include_left_endpoint = (significand % 2 == 0);
|
||||
|
@ -1227,45 +1227,29 @@ template <typename T, typename Enable = void> struct float_info;
|
||||
template <> struct float_info<float> {
|
||||
using carrier_uint = uint32_t;
|
||||
static const int exponent_bits = 8;
|
||||
static const int min_exponent = -126;
|
||||
static const int max_exponent = 127;
|
||||
static const int exponent_bias = -127;
|
||||
static const int decimal_digits = 9;
|
||||
static const int kappa = 1;
|
||||
static const int big_divisor = 100;
|
||||
static const int small_divisor = 10;
|
||||
static const int min_k = -31;
|
||||
static const int max_k = 46;
|
||||
static const int cache_bits = 64;
|
||||
static const int divisibility_check_by_5_threshold = 39;
|
||||
static const int case_fc_pm_half_lower_threshold = -1;
|
||||
static const int case_shorter_interval_left_endpoint_lower_threshold = 2;
|
||||
static const int case_shorter_interval_left_endpoint_upper_threshold = 3;
|
||||
static const int shorter_interval_tie_lower_threshold = -35;
|
||||
static const int shorter_interval_tie_upper_threshold = -35;
|
||||
static const int max_trailing_zeros = 7;
|
||||
};
|
||||
|
||||
template <> struct float_info<double> {
|
||||
using carrier_uint = uint64_t;
|
||||
static const int exponent_bits = 11;
|
||||
static const int min_exponent = -1022;
|
||||
static const int max_exponent = 1023;
|
||||
static const int exponent_bias = -1023;
|
||||
static const int decimal_digits = 17;
|
||||
static const int kappa = 2;
|
||||
static const int big_divisor = 1000;
|
||||
static const int small_divisor = 100;
|
||||
static const int min_k = -292;
|
||||
static const int max_k = 326;
|
||||
static const int cache_bits = 128;
|
||||
static const int divisibility_check_by_5_threshold = 86;
|
||||
static const int case_fc_pm_half_lower_threshold = -2;
|
||||
static const int case_shorter_interval_left_endpoint_lower_threshold = 2;
|
||||
static const int case_shorter_interval_left_endpoint_upper_threshold = 3;
|
||||
static const int shorter_interval_tie_lower_threshold = -77;
|
||||
static const int shorter_interval_tie_upper_threshold = -77;
|
||||
static const int max_trailing_zeros = 16;
|
||||
};
|
||||
|
||||
// 80-bit extended precision long double.
|
||||
|
@ -226,15 +226,17 @@ TEST(fp_test, get_cached_power) {
|
||||
TEST(fp_test, dragonbox_max_k) {
|
||||
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),
|
||||
EXPECT_EQ(
|
||||
fmt::detail::const_check(float_info::max_k),
|
||||
float_info::kappa -
|
||||
floor_log10_pow2(float_info::min_exponent -
|
||||
fmt::detail::num_significand_bits<float>()));
|
||||
floor_log10_pow2(std::numeric_limits<float>::min_exponent -
|
||||
fmt::detail::num_significand_bits<float>() - 1));
|
||||
using double_info = fmt::detail::dragonbox::float_info<double>;
|
||||
EXPECT_EQ(fmt::detail::const_check(double_info::max_k),
|
||||
EXPECT_EQ(
|
||||
fmt::detail::const_check(double_info::max_k),
|
||||
double_info::kappa -
|
||||
floor_log10_pow2(double_info::min_exponent -
|
||||
fmt::detail::num_significand_bits<double>()));
|
||||
floor_log10_pow2(std::numeric_limits<double>::min_exponent -
|
||||
fmt::detail::num_significand_bits<double>() - 1));
|
||||
}
|
||||
|
||||
TEST(fp_test, get_round_direction) {
|
||||
|
Loading…
Reference in New Issue
Block a user