From 9ff91b18cd2a3e012d8e91c9dcec4903ed8faa1a Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 9 Jan 2022 14:16:32 -0800 Subject: [PATCH] Simplify write_fractional_seconds --- include/fmt/chrono.h | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index c51aa8a0..775dc17d 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -1664,6 +1664,7 @@ struct chrono_formatter { } template void write_fractional_seconds(Duration d) { + FMT_ASSERT(!std::is_floating_point::value, ""); constexpr auto num_fractional_digits = count_fractional_digits(Duration::period::num, Duration::period::den); @@ -1674,12 +1675,9 @@ struct chrono_formatter { if (std::ratio_less::value) { *out++ = '.'; - // Don't convert long double to integer seconds to avoid overflow. - using sec = conditional_t< - std::is_same::value, - std::chrono::duration, std::chrono::seconds>; - auto fractional = detail::abs(d) - std::chrono::duration_cast(d); - const auto subseconds = + auto fractional = + detail::abs(d) - std::chrono::duration_cast(d); + auto subseconds = std::chrono::treat_as_floating_point< typename subsecond_precision::rep>::value ? fractional.count()