diff --git a/include/yaml-cpp/node/convert.h b/include/yaml-cpp/node/convert.h index 1329dbc..741c42f 100644 --- a/include/yaml-cpp/node/convert.h +++ b/include/yaml-cpp/node/convert.h @@ -42,19 +42,6 @@ static const std::regex re_float( "[-+]?(\\.[0-9]+|[0-9]+(\\.[0-9]*)?)([eE][-+]?[0-9]+)?"); static const std::regex re_inf("[-+]?(\\.inf|\\.Inf|\\.INF)"); static const std::regex re_nan("\\.nan|\\.NaN|\\.NAN"); - -inline bool IsInfinity(const std::string& input) { - return input == ".inf" || input == ".Inf" || input == ".INF" || - input == "+.inf" || input == "+.Inf" || input == "+.INF"; -} - -inline bool IsNegativeInfinity(const std::string& input) { - return input == "-.inf" || input == "-.Inf" || input == "-.INF"; -} - -inline bool IsNaN(const std::string& input) { - return input == ".nan" || input == ".NaN" || input == ".NAN"; -} } // Node @@ -199,11 +186,14 @@ struct convert< } return Node(".inf"); } - auto str = std::to_string(rhs); + std::stringstream stream; + stream.precision(std::numeric_limits::max_digits10); + stream << rhs; + auto str = stream.str(); if (std::regex_match(str, conversion::re_decimal)) { return Node(str + "."); // Disambiguate float from int } - return Node(std::to_string(rhs)); + return Node(str); } static bool decode(const Node& node, type& rhs) { diff --git a/src/emitterstate.cpp b/src/emitterstate.cpp index 3542aaf..d5f39e7 100644 --- a/src/emitterstate.cpp +++ b/src/emitterstate.cpp @@ -24,8 +24,8 @@ EmitterState::EmitterState() m_seqFmt.set(Block); m_mapFmt.set(Block); m_mapKeyFmt.set(Auto); - m_floatPrecision.set(std::numeric_limits::digits10 + 1); - m_doublePrecision.set(std::numeric_limits::digits10 + 1); + m_floatPrecision.set(std::numeric_limits::max_digits10); + m_doublePrecision.set(std::numeric_limits::max_digits10); } EmitterState::~EmitterState() {} @@ -349,7 +349,7 @@ bool EmitterState::SetMapKeyFormat(EMITTER_MANIP value, FmtScope::value scope) { } bool EmitterState::SetFloatPrecision(std::size_t value, FmtScope::value scope) { - if (value > std::numeric_limits::digits10 + 1) + if (value > std::numeric_limits::max_digits10) return false; _Set(m_floatPrecision, value, scope); return true; @@ -357,7 +357,7 @@ bool EmitterState::SetFloatPrecision(std::size_t value, FmtScope::value scope) { bool EmitterState::SetDoublePrecision(std::size_t value, FmtScope::value scope) { - if (value > std::numeric_limits::digits10 + 1) + if (value > std::numeric_limits::max_digits10) return false; _Set(m_doublePrecision, value, scope); return true;