From a1d15964db6ec55a60e1170e10b3514d7e914532 Mon Sep 17 00:00:00 2001 From: Junekey Jeon Date: Tue, 12 Jul 2022 16:26:05 -0700 Subject: [PATCH 1/3] Simplify Dragonbox implementation --- include/fmt/format-inl.h | 25 +++++-------------------- include/fmt/format.h | 2 -- 2 files changed, 5 insertions(+), 22 deletions(-) diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index f44df01c5d0c..a293287dae30 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -1346,26 +1346,11 @@ template decimal_fp to_decimal(T x) noexcept { goto small_divisor_case_label; } else { // r == deltai; compare fractional parts. - const carrier_uint two_fl = two_fc - 1; - - if (!include_left_endpoint || - exponent < float_info::case_fc_pm_half_lower_threshold || - exponent > float_info::divisibility_check_by_5_threshold) { - // If the left endpoint is not included, the condition for - // success is z^(f) < delta^(f) (odd parity). - // Otherwise, the inequalities on exponent ensure that - // x is not an integer, so if z^(f) >= delta^(f) (even parity), we in fact - // have strict inequality. - if (!cache_accessor::compute_mul_parity(two_fl, cache, beta).parity) { - goto small_divisor_case_label; - } - } else { - const typename cache_accessor::compute_mul_parity_result x_mul = - cache_accessor::compute_mul_parity(two_fl, cache, beta); - if (!x_mul.parity && !x_mul.is_integer) { - goto small_divisor_case_label; - } - } + const typename cache_accessor::compute_mul_parity_result x_mul = + cache_accessor::compute_mul_parity(two_fc - 1, cache, beta); + + if (!(x_mul.parity | (x_mul.is_integer & include_left_endpoint))) + goto small_divisor_case_label; } ret_value.exponent = minus_k + float_info::kappa + 1; diff --git a/include/fmt/format.h b/include/fmt/format.h index 6516975e2f92..e2397780c87d 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -1276,8 +1276,6 @@ template <> struct float_info { static const int small_divisor = 10; static const int min_k = -31; static const int max_k = 46; - static const int divisibility_check_by_5_threshold = 39; - static const int case_fc_pm_half_lower_threshold = -1; static const int shorter_interval_tie_lower_threshold = -35; static const int shorter_interval_tie_upper_threshold = -35; }; From 60a7608710a6f231e79e7ddabdcfb2bbebc00742 Mon Sep 17 00:00:00 2001 From: Junekey Jeon Date: Tue, 12 Jul 2022 16:27:05 -0700 Subject: [PATCH 2/3] Remove some branches --- include/fmt/format-inl.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index a293287dae30..8391aa9b7414 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -1337,7 +1337,7 @@ template decimal_fp to_decimal(T x) noexcept { if (r < deltai) { // Exclude the right endpoint if necessary. - if (r == 0 && z_mul.is_integer && !include_right_endpoint) { + if (r == 0 && (z_mul.is_integer & !include_right_endpoint)) { --ret_value.significand; r = float_info::big_divisor; goto small_divisor_case_label; @@ -1389,7 +1389,7 @@ template decimal_fp to_decimal(T x) noexcept { // or equivalently, when y is an integer. if (y_mul.parity != approx_y_parity) --ret_value.significand; - else if (y_mul.is_integer && ret_value.significand % 2 != 0) + else if (y_mul.is_integer & (ret_value.significand % 2 != 0)) --ret_value.significand; return ret_value; } From 916555711c12813d6f0cc400db1bbd1b4b2d86c4 Mon Sep 17 00:00:00 2001 From: Junekey Jeon Date: Thu, 14 Jul 2022 14:58:35 -0700 Subject: [PATCH 3/3] Remove unused constants. --- include/fmt/format.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index e2397780c87d..dad643c624e2 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -1288,8 +1288,6 @@ template <> struct float_info { static const int small_divisor = 100; static const int min_k = -292; static const int max_k = 326; - static const int divisibility_check_by_5_threshold = 86; - static const int case_fc_pm_half_lower_threshold = -2; static const int shorter_interval_tie_lower_threshold = -77; static const int shorter_interval_tie_upper_threshold = -77; };