Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small improvements on Dragonbox #1887

Merged
merged 1 commit into from
Sep 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions include/fmt/format-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1870,8 +1870,8 @@ template <> struct float_info<float> {
static const int case_fc_upper_threshold = 6;
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_case_tie_lower_threshold = -35;
static const int shorter_interval_case_tie_upper_threshold = -35;
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;
};

Expand All @@ -1896,8 +1896,8 @@ template <> struct float_info<double> {
static const int case_fc_upper_threshold = 9;
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_case_tie_lower_threshold = -77;
static const int shorter_interval_case_tie_upper_threshold = -77;
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;
};

Expand Down Expand Up @@ -2061,9 +2061,10 @@ template <> struct cache_accessor<float> {

static carrier_uint compute_round_up_for_shorter_interval_case(
const cache_entry_type& cache, int beta_minus_1) FMT_NOEXCEPT {
return carrier_uint(((cache >> (64 - float_info<float>::significand_bits -
2 - beta_minus_1)) +
1)) /
return (static_cast<carrier_uint>(
cache >>
(64 - float_info<float>::significand_bits - 2 - beta_minus_1)) +
1) /
2;
}
};
Expand Down Expand Up @@ -2377,8 +2378,8 @@ FMT_ALWAYS_INLINE FMT_SAFEBUFFERS void shorter_interval_case(
ret_value.exponent = minus_k;

// When tie occurs, choose one of them according to the rule
if (exponent >= float_info<T>::shorter_interval_case_tie_lower_threshold &&
exponent <= float_info<T>::shorter_interval_case_tie_upper_threshold) {
if (exponent >= float_info<T>::shorter_interval_tie_lower_threshold &&
exponent <= float_info<T>::shorter_interval_tie_upper_threshold) {
ret_value.significand = ret_value.significand % 2 == 0
? ret_value.significand
: ret_value.significand - 1;
Expand Down Expand Up @@ -2411,7 +2412,7 @@ template <class T> FMT_SAFEBUFFERS decimal_fp<T> to_decimal(T x) FMT_NOEXCEPT {
if (exponent != 0) {
exponent += float_info<T>::exponent_bias - float_info<T>::significand_bits;

// Closer boundary case; proceed like Schubfach
// Shorter interval case; proceed like Schubfach
if (significand == 0) {
shorter_interval_case<T>(ret_value, exponent);
return ret_value;
Expand Down Expand Up @@ -2461,10 +2462,12 @@ template <class T> FMT_SAFEBUFFERS decimal_fp<T> to_decimal(T x) FMT_NOEXCEPT {
}
} else {
// r == deltai; compare fractional parts
// Check conditions in the order different from the paper
// to take advantage of short-circuiting
const carrier_uint two_fl = two_fc - 1;
if (!cache_accessor<T>::compute_mul_parity(two_fl, cache, beta_minus_1) &&
(!include_left_endpoint ||
!is_endpoint_integer<T>(two_fl, exponent, minus_k))) {
if ((!include_left_endpoint ||
!is_endpoint_integer<T>(two_fl, exponent, minus_k)) &&
!cache_accessor<T>::compute_mul_parity(two_fl, cache, beta_minus_1)) {
goto small_divisor_case_label;
}
}
Expand Down Expand Up @@ -2497,7 +2500,7 @@ template <class T> FMT_SAFEBUFFERS decimal_fp<T> to_decimal(T x) FMT_NOEXCEPT {
// We have either yi == zi - epsiloni or yi == (zi - epsiloni) - 1,
// where yi == zi - epsiloni if and only if z^(f) >= epsilon^(f)
// Since there are only 2 possibilities, we only need to care about the
// parity Also, zi and r should have the same parity since the divisor
// parity. Also, zi and r should have the same parity since the divisor
// is an even number
if (cache_accessor<T>::compute_mul_parity(two_fc, cache, beta_minus_1) !=
approx_y_parity) {
Expand Down