Repository: fmtlib/fmt
File: include/fmt/format.h (C/C++)

Code before:

  buf.push_back(specs.upper ? 'P' : 'p');

  uint32_t abs_e;
  if (f.e < 0) {
    buf.push_back('-');
    abs_e = static_cast<uint32_t>(-f.e);
  } else {
    buf.push_back('+');
    abs_e = static_cast<uint32_t>(f.e);
  }
  format_decimal<char>(appender(buf), abs_e, detail::count_digits(abs_e));
}

template <typename Float, FMT_ENABLE_IF(is_double_double<Float>::value)>
FMT_CONSTEXPR20 void format_hexfloat(Float value, int precision,
                                     float_specs specs, buffer<char>& buf) {
  format_hexfloat(static_cast<double>(value), precision, specs, buf);
}

template <typename Float> FMT_CONSTEXPR auto iceil(Float value) -> int {
  auto min = (std::numeric_limits<int>::min)();
  auto max = (std::numeric_limits<int>::max)();
  ignore_unused(min, max);
  FMT_ASSERT(value >= min && value <= max, "value not in int range");
  if (is_constant_evaluated()) {
    do {
      auto mid = min + static_cast<int>((static_cast<unsigned>(max) -
                                         static_cast<unsigned>(min)) /
                                        2);
      if (mid < value)
        min = mid;
      else
        max = mid;
    } while (min + 1 != max);
    return max;
  }
  return static_cast<int>(std::ceil(value));
}

template <typename Float>
FMT_CONSTEXPR20 auto format_float(Float value, int precision, float_specs specs,
                                  buffer<char>& buf) -> int {
  // float is passed as double to reduce the number of instantiations.
  static_assert(!std::is_same<Float, float>::value, "");
  FMT_ASSERT(value >= 0, "value is negative");
  auto converted_value = convert_float(value);

  const bool fixed = specs.format == float_format::fixed;
  if (value <= 0) {  // <= instead of == to silence a warning.
    if (precision <= 0 || !fixed) {

Review comment (suggestion):
On a second thought, I don't think we need this check at all because `iceil` is not called at runtime except in tests.

Code after:

  buf.push_back(specs.upper ? 'P' : 'p');

  uint32_t abs_e;
  if (f.e < 0) {
    buf.push_back('-');
    abs_e = static_cast<uint32_t>(-f.e);
  } else {
    buf.push_back('+');
    abs_e = static_cast<uint32_t>(f.e);
  }
  format_decimal<char>(appender(buf), abs_e, detail::count_digits(abs_e));
}

template <typename Float, FMT_ENABLE_IF(is_double_double<Float>::value)>
FMT_CONSTEXPR20 void format_hexfloat(Float value, int precision,
                                     float_specs specs, buffer<char>& buf) {
  format_hexfloat(static_cast<double>(value), precision, specs, buf);
}

template <typename Float> FMT_CONSTEXPR auto iceil(Float value) -> int {
  auto min = (std::numeric_limits<int>::min)();
  auto max = (std::numeric_limits<int>::max)();
  ignore_unused(min, max);
  FMT_ASSERT(value >= min && value <= max, "value not in int range");
  do {
    auto mid = min + static_cast<int>((static_cast<unsigned>(max) -
                                       static_cast<unsigned>(min)) /
                                      2);
    if (mid < value)
      min = mid;
    else
      max = mid;
  } while (min + 1 != max);
  return max;
}

template <typename Float>
FMT_CONSTEXPR20 auto format_float(Float value, int precision, float_specs specs,
                                  buffer<char>& buf) -> int {
  // float is passed as double to reduce the number of instantiations.
  static_assert(!std::is_same<Float, float>::value, "");
  FMT_ASSERT(value >= 0, "value is negative");
  auto converted_value = convert_float(value);

  const bool fixed = specs.format == float_format::fixed;
  if (value <= 0) {  // <= instead of == to silence a warning.
    if (precision <= 0 || !fixed) {
      buf.push_back('0');
      return 0;
    }