From f9722af3df6dafa27c7dc956b2c6ba96a8cf8324 Mon Sep 17 00:00:00 2001 From: Megvii Engine Team Date: Wed, 1 Sep 2021 22:10:50 +0800 Subject: [PATCH] fix(src/json): fix parsing error when inf is dumped as a Number GitOrigin-RevId: 62cfba48c00449a8709525e0131564bd6e85b1f8 --- src/core/impl/utils/json.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/core/impl/utils/json.cpp b/src/core/impl/utils/json.cpp index c2a40281..7172ee75 100644 --- a/src/core/impl/utils/json.cpp +++ b/src/core/impl/utils/json.cpp @@ -52,6 +52,14 @@ void Value::writeto_fpath(const char* fout_path, int indent) const { } void Number::writeto(std::string& fout, int) const { + if (std::isinf(m_val)){ + fout += "\"inf\""; + return ; + } + if (std::isnan(m_val)){ + fout += "\"nan\""; + return ; + } static char fmt[16]; static Spinlock fmt_mtx; if (!fmt[sizeof(fmt) - 1]) { -- GitLab