From 75108a56f666645e1f56018d75d8a456b8590bd1 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Wed, 20 Nov 2019 12:26:48 -0800 Subject: [PATCH] Don't print % for nan and inf --- include/fmt/format.h | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index 3d90387e..985ed9a7 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -1623,12 +1623,10 @@ template class basic_writer { struct inf_or_nan_writer { sign_t sign; - bool as_percentage; const char* str; size_t size() const { - return static_cast(inf_size + (sign ? 1 : 0) + - (as_percentage ? 1 : 0)); + return static_cast(inf_size + (sign ? 1 : 0)); } size_t width() const { return size(); } @@ -1636,7 +1634,6 @@ template class basic_writer { if (sign) *it++ = static_cast(data::signs[sign]); it = internal::copy_str( str, str + static_cast(inf_size), it); - if (as_percentage) *it++ = static_cast('%'); } }; @@ -1754,9 +1751,9 @@ template class basic_writer { float_spec fspec = parse_float_type_spec(specs.type); if (!std::isfinite(value)) { - const char* str = std::isinf(value) ? (fspec.upper ? "INF" : "inf") + auto str = std::isinf(value) ? (fspec.upper ? "INF" : "inf") : (fspec.upper ? "NAN" : "nan"); - return write_padded(specs, inf_or_nan_writer{sign, fspec.percent, str}); + return write_padded(specs, inf_or_nan_writer{sign, str}); } if (fspec.percent) value *= 100;