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

Code before:
    std::chrono::duration<Rep, Period> d) {
  return d;
}

constexpr long long pow10(std::uint32_t n) {
  return n == 0 ? 1 : 10 * pow10(n - 1);
}

// Counts the number of fractional digits in the range [0, 18] according to the
// C++20 spec. If more than 18 fractional digits are required then returns 6 for
// microseconds precision.
template <long long Num, long long Den, int N = 0,
          bool Enabled = (N < 19) && (Num <= max_value<long long>() / 10)>
struct count_fractional_digits {
  static constexpr int value =
      Num % Den == 0 ? N : count_fractional_digits<Num * 10, Den, N + 1>::value;
};

// Base case that doesn't instantiate any more templates
// in order to avoid overflow.
template <long long Num, long long Den, int N>
struct count_fractional_digits<Num, Den, N, false> {
  static constexpr int value = (Num % Den == 0) ? N : 6;
};

// Format non-fractional subseconds with an appriate number of digits.
template <typename OutputIt, typename Duration, typename char_type>
void write_sub_sec(OutputIt& out, Duration d) {
  FMT_ASSERT(!std::is_floating_point<typename Duration::rep>::value, "");
  constexpr auto num_fractional_digits =
      count_fractional_digits<Duration::period::num,
                              Duration::period::den>::value;

  using subsecond_precision = std::chrono::duration<
      typename std::common_type<typename Duration::rep,
                                std::chrono::seconds::rep>::type,
      std::ratio<1, detail::pow10(num_fractional_digits)>>;
  if (std::ratio_less<typename subsecond_precision::period,
                      std::chrono::seconds::period>::value) {
    *out++ = '.';
    auto fractional =
        detail::abs(d) - std::chrono::duration_cast<std::chrono::seconds>(d);
    auto subseconds =
        std::chrono::treat_as_floating_point<
            typename subsecond_precision::rep>::value
            ? fractional.count()
            : std::chrono::duration_cast<subsecond_precision>(fractional)
                  .count();
    uint32_or_64_or_128_t<long long> n =
        to_unsigned(to_nonnegative_int(subseconds, max_value<long long>()));
    int num_digits = detail::count_digits(n);

Review comment (suggestion):
appriate -> appropriate

Also please keep the old name, `write_fractional_seconds`, and remove or update misleading comment.

Code after:
    std::chrono::duration<Rep, Period> d) {
  return d;
}

constexpr long long pow10(std::uint32_t n) {
  return n == 0 ? 1 : 10 * pow10(n - 1);
}

// Counts the number of fractional digits in the range [0, 18] according to the
// C++20 spec. If more than 18 fractional digits are required then returns 6 for
// microseconds precision.
template <long long Num, long long Den, int N = 0,
          bool Enabled = (N < 19) && (Num <= max_value<long long>() / 10)>
struct count_fractional_digits {
  static constexpr int value =
      Num % Den == 0 ? N : count_fractional_digits<Num * 10, Den, N + 1>::value;
};

// Base case that doesn't instantiate any more templates
// in order to avoid overflow.
template <long long Num, long long Den, int N>
struct count_fractional_digits<Num, Den, N, false> {
  static constexpr int value = (Num % Den == 0) ? N : 6;
};

// Format subseconds which are given as an integer type with an appropriate
// number of digits.
template <typename Char, typename OutputIt, typename Duration>
void write_fractional_seconds(OutputIt& out, Duration d) {
  FMT_ASSERT(!std::is_floating_point<typename Duration::rep>::value, "");
  constexpr auto num_fractional_digits =
      count_fractional_digits<Duration::period::num,
                              Duration::period::den>::value;

  using subsecond_precision = std::chrono::duration<
      typename std::common_type<typename Duration::rep,
                                std::chrono::seconds::rep>::type,
      std::ratio<1, detail::pow10(num_fractional_digits)>>;
  if (std::ratio_less<typename subsecond_precision::period,
                      std::chrono::seconds::period>::value) {
    *out++ = '.';
    auto fractional =
        detail::abs(d) - std::chrono::duration_cast<std::chrono::seconds>(d);
    auto subseconds =
        std::chrono::treat_as_floating_point<
            typename subsecond_precision::rep>::value
            ? fractional.count()
            : std::chrono::duration_cast<subsecond_precision>(fractional)
                  .count();
    uint32_or_64_or_128_t<long long> n =
        to_unsigned(to_nonnegative_int(subseconds, max_value<long long>()));