mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 20:51:16 +00:00
Fix storing inf and NaN (#817)
This commit is contained in:

committed by
GitHub

parent
29dcf92f87
commit
de8253fcb0
@@ -8,10 +8,12 @@
|
||||
#endif
|
||||
|
||||
#include <array>
|
||||
#include <cmath>
|
||||
#include <limits>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
#include "yaml-cpp/binary.h"
|
||||
@@ -94,7 +96,21 @@ struct convert<_Null> {
|
||||
static Node encode(const type& rhs) { \
|
||||
std::stringstream stream; \
|
||||
stream.precision(std::numeric_limits<type>::max_digits10); \
|
||||
stream << rhs; \
|
||||
if (std::is_floating_point<type>::value) { \
|
||||
if (std::isnan(rhs)) { \
|
||||
stream << ".nan"; \
|
||||
} else if (std::isinf(rhs)) { \
|
||||
if (std::signbit(rhs)) { \
|
||||
stream << "-.inf"; \
|
||||
} else { \
|
||||
stream << ".inf"; \
|
||||
} \
|
||||
} else { \
|
||||
stream << rhs; \
|
||||
} \
|
||||
} else { \
|
||||
stream << rhs; \
|
||||
} \
|
||||
return Node(stream.str()); \
|
||||
} \
|
||||
\
|
||||
|
Reference in New Issue
Block a user