write_floating_seconds: Fall back to ::round (#3343)

On some toolchains, `std::round` is not available.

Fixes #3342
This commit is contained in:
Gleb Mazovetskiy 2023-03-12 16:34:19 +00:00 committed by GitHub
parent cbc7b8d5c1
commit 7f882918eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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<Duration::period::num,
Duration::period::den>::value;
if (num_fractional_digits < 6 && static_cast<rep>(std::round(val)) != val)
if (num_fractional_digits < 6 && static_cast<rep>(round(val)) != val)
num_fractional_digits = 6;
}