diff options
Diffstat (limited to 'src/common/Formatter.cc')
-rw-r--r-- | src/common/Formatter.cc | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/common/Formatter.cc b/src/common/Formatter.cc index f68f87f4645..fd3b2be0221 100644 --- a/src/common/Formatter.cc +++ b/src/common/Formatter.cc @@ -296,6 +296,17 @@ void JSONFormatter::finish_pending_string() } } +void JSONFormatter::add_value(std::string_view name, double val) { + CachedStackStringStream css; + if (!std::isfinite(val) || std::isnan(val)) { + *css << "null"; + } else { + css->precision(std::numeric_limits<double>::max_digits10); + *css << val; + } + add_value(name, css->strv(), false); +} + template <class T> void JSONFormatter::add_value(std::string_view name, T val) { |