From 7eb5e3f5835191d959df0b8eab1e8322365ad007 Mon Sep 17 00:00:00 2001 From: andargunov Date: Tue, 6 Oct 2020 17:19:54 +0300 Subject: [PATCH] Added an if expression for the individual case described in fmtlib/fmt/issues/1917. Adjusts the length of the number to match the precision for the exponential number format. --- include/fmt/format-inl.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index 80e0f8f4..dfeff767 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -2468,6 +2468,15 @@ int format_float(T value, int precision, float_specs specs, buffer& buf) { } else { exp -= cached_exp10; buf.try_resize(to_unsigned(handler.size)); + if ((specs.format == detail::float_format::exp) && (buf.size() > precision)) { + if (exp < 0) { + exp += (buf.size() - precision); + } + else { + exp -= (buf.size() - precision); + } + buf.try_resize(to_unsigned(precision)); + } } if (!fixed && !specs.showpoint) { // Remove trailing zeros.