From 925b744ae8ea5a62f423d55250302e2b48dd83cf Mon Sep 17 00:00:00 2001 From: Junekey Jeon Date: Sat, 15 Jan 2022 05:05:55 -0800 Subject: [PATCH] Improve comments --- include/fmt/format-inl.h | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index 283b86c3..8c789ca6 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -793,7 +793,8 @@ struct uint128_wrapper { uint64_t low_; constexpr uint128_wrapper(uint64_t high, uint64_t low) FMT_NOEXCEPT - : high_{high}, low_{low} {} + : high_{high}, + low_{low} {} constexpr uint64_t high() const FMT_NOEXCEPT { return high_; } constexpr uint64_t low() const FMT_NOEXCEPT { return low_; } @@ -2008,6 +2009,8 @@ template decimal_fp to_decimal(T x) FMT_NOEXCEPT { exponent += float_info::exponent_bias - float_info::significand_bits; // Shorter interval case; proceed like Schubfach. + // In fact, when exponent == 1 and significand == 0, the interval is + // regular. However, it can be shown that the end-results are anyway same. if (significand == 0) return shorter_interval_case(exponent); significand |= @@ -2030,6 +2033,13 @@ template decimal_fp to_decimal(T x) FMT_NOEXCEPT { // 10^kappa <= deltai < 10^(kappa + 1) const uint32_t deltai = cache_accessor::compute_delta(cache, beta_minus_1); const carrier_uint two_fc = significand << 1; + + // For the case of binary32, the result of integer check is not correct for + // 29711844 * 2^-81, and it is the unique counterexample. However, since + // 29711844 is even, this does not cause any problem for the endpoints; it can + // only cause a problem when we need to perform integer check for the center. + // Fortunately, with the input 297184444 * 2^-81, that branch is never + // executed, so we are fine. const typename cache_accessor::compute_mul_result z_mul = cache_accessor::compute_mul((two_fc | 1) << beta_minus_1, cache); @@ -2039,8 +2049,8 @@ template decimal_fp to_decimal(T x) FMT_NOEXCEPT { // better than the compiler; we are computing zi / big_divisor here. decimal_fp ret_value; ret_value.significand = divide_by_10_to_kappa_plus_1(z_mul.result); - uint32_t r = static_cast( - z_mul.result - float_info::big_divisor * ret_value.significand); + uint32_t r = static_cast(z_mul.result - float_info::big_divisor * + ret_value.significand); if (r > deltai) { goto small_divisor_case_label;