diff --git a/include/yaml-cpp/node/convert.h b/include/yaml-cpp/node/convert.h index 902b9cd..26dbb72 100644 --- a/include/yaml-cpp/node/convert.h +++ b/include/yaml-cpp/node/convert.h @@ -90,6 +90,33 @@ struct convert<_Null> { } }; +template +bool careful_isnan(T arg) +{ + if constexpr (std::is_floating_point_v) + return std::isnan(arg); + else + return false; +} + +template +bool careful_isinf(T arg) +{ + if constexpr (std::is_floating_point_v) + return std::isinf(arg); + else + return false; +} + +template +bool careful_sign(T arg) +{ + if constexpr (std::is_floating_point_v) + return std::signbit(arg); + else + return false; +} + #define YAML_DEFINE_CONVERT_STREAMABLE(type, negative_op) \ template <> \ struct convert { \ @@ -97,10 +124,10 @@ struct convert<_Null> { std::stringstream stream; \ stream.precision(std::numeric_limits::max_digits10); \ if (std::is_floating_point::value) { \ - if (std::isnan(rhs)) { \ + if (careful_isnan(rhs)) { \ stream << ".nan"; \ - } else if (std::isinf(rhs)) { \ - if (std::signbit(rhs)) { \ + } else if (careful_isinf(rhs)) { \ + if (careful_sign(rhs)) { \ stream << "-.inf"; \ } else { \ stream << ".inf"; \