21 if (n <= threshold || threshold <= 0) {
28 const int64_t lo = std::max<int64_t>(2, threshold / 2);
29 const int64_t hi = threshold;
30 double best_score = std::numeric_limits<double>::max();
31 for (int32_t L = 1; L <= 24; ++L) {
32 const int64_t k = int64_t(1) << L;
34 const int64_t leaf = (n + k - 1) / k;
35 if (leaf > hi)
continue;
37 const int64_t N = leaf * k;
38 const double score =
static_cast<double>(N - n) /
static_cast<double>(n)
39 + 1e-3 * std::abs(
static_cast<double>(leaf - threshold)) /
static_cast<double>(threshold);
40 if (score < best_score) {