Skip to content

Commit

Permalink
write_floating_seconds: Fall back to ::round (#3343)
Browse files Browse the repository at this point in the history
On some toolchains, `std::round` is not available.

Fixes #3342
  • Loading branch information
glebm committed Mar 12, 2023
1 parent cbc7b8d commit 7f88291
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion include/fmt/chrono.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 7f88291

Please sign in to comment.