From 7f882918eba6430a0509b5e8547de21611264c5c Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Sun, 12 Mar 2023 16:34:19 +0000 Subject: [PATCH] `write_floating_seconds`: Fall back to `::round` (#3343) On some toolchains, `std::round` is not available. Fixes #3342 --- include/fmt/chrono.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index 8712c27c..0185bb81 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -1168,10 +1168,13 @@ void write_floating_seconds(memory_buffer& buf, Duration duration, auto val = duration.count(); if (num_fractional_digits < 0) { + // For `std::round` with fallback to `round`: + // On some toolchains `std::round` is not available (e.g. GCC 6). + using namespace std; num_fractional_digits = count_fractional_digits::value; - if (num_fractional_digits < 6 && static_cast(std::round(val)) != val) + if (num_fractional_digits < 6 && static_cast(round(val)) != val) num_fractional_digits = 6; }