Simplify to_decimal

This commit is contained in:
Victor Zverovich
2022-02-20 08:46:09 -08:00
parent 70dc3de053
commit cf940ae82e

View File

@ -2043,28 +2043,22 @@ small_divisor_case_label:
// Add dist / 10^kappa to the significand. // Add dist / 10^kappa to the significand.
ret_value.significand += dist; ret_value.significand += dist;
if (divisible_by_small_divisor) { if (!divisible_by_small_divisor) return ret_value;
// Check z^(f) >= epsilon^(f).
// 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
// is an even number.
const typename cache_accessor<T>::compute_mul_parity_result y_mul =
cache_accessor<T>::compute_mul_parity(two_fc, cache, beta);
if (y_mul.parity != approx_y_parity) { // Check z^(f) >= epsilon^(f).
--ret_value.significand; // We have either yi == zi - epsiloni or yi == (zi - epsiloni) - 1,
} else { // where yi == zi - epsiloni if and only if z^(f) >= epsilon^(f).
// If z^(f) >= epsilon^(f), we might have a tie // Since there are only 2 possibilities, we only need to care about the
// when z^(f) == epsilon^(f), or equivalently, when y is an integer // parity. Also, zi and r should have the same parity since the divisor
if (y_mul.is_integer) { // is an even number.
ret_value.significand = ret_value.significand % 2 == 0 const auto y_mul = cache_accessor<T>::compute_mul_parity(two_fc, cache, beta);
? ret_value.significand
: ret_value.significand - 1; // If z^(f) >= epsilon^(f), we might have a tie when z^(f) == epsilon^(f),
} // 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)
--ret_value.significand;
return ret_value; return ret_value;
} }
} // namespace dragonbox } // namespace dragonbox