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

committed by
GitHub

parent
29dcf92f87
commit
de8253fcb0
@@ -461,12 +461,66 @@ TEST(NodeTest, FloatingPrecisionFloat) {
|
||||
EXPECT_EQ(x, node.as<float>());
|
||||
}
|
||||
|
||||
TEST(NodeTest, FloatingPrecisionPositiveInfinityFloat) {
|
||||
if (!std::numeric_limits<float>::has_infinity) {
|
||||
return;
|
||||
}
|
||||
const float x = std::numeric_limits<float>::infinity();
|
||||
Node node = Node(x);
|
||||
EXPECT_EQ(x, node.as<float>());
|
||||
}
|
||||
|
||||
TEST(NodeTest, FloatingPrecisionNegativeInfinityFloat) {
|
||||
if (!std::numeric_limits<float>::has_infinity) {
|
||||
return;
|
||||
}
|
||||
const float x = -std::numeric_limits<float>::infinity();
|
||||
Node node = Node(x);
|
||||
EXPECT_EQ(x, node.as<float>());
|
||||
}
|
||||
|
||||
TEST(NodeTest, FloatingPrecisionNanFloat) {
|
||||
if (!std::numeric_limits<float>::has_quiet_NaN) {
|
||||
return;
|
||||
}
|
||||
const float x = std::numeric_limits<float>::quiet_NaN();
|
||||
Node node = Node(x);
|
||||
EXPECT_TRUE(std::isnan(node.as<float>()));
|
||||
}
|
||||
|
||||
TEST(NodeTest, FloatingPrecisionDouble) {
|
||||
const double x = 0.123456789;
|
||||
Node node = Node(x);
|
||||
EXPECT_EQ(x, node.as<double>());
|
||||
}
|
||||
|
||||
TEST(NodeTest, FloatingPrecisionPositiveInfinityDouble) {
|
||||
if (!std::numeric_limits<double>::has_infinity) {
|
||||
return;
|
||||
}
|
||||
const double x = std::numeric_limits<double>::infinity();
|
||||
Node node = Node(x);
|
||||
EXPECT_EQ(x, node.as<float>());
|
||||
}
|
||||
|
||||
TEST(NodeTest, FloatingPrecisionNegativeInfinityDouble) {
|
||||
if (!std::numeric_limits<double>::has_infinity) {
|
||||
return;
|
||||
}
|
||||
const double x = -std::numeric_limits<double>::infinity();
|
||||
Node node = Node(x);
|
||||
EXPECT_EQ(x, node.as<double>());
|
||||
}
|
||||
|
||||
TEST(NodeTest, FloatingPrecisionNanDouble) {
|
||||
if (!std::numeric_limits<double>::has_quiet_NaN) {
|
||||
return;
|
||||
}
|
||||
const double x = std::numeric_limits<double>::quiet_NaN();
|
||||
Node node = Node(x);
|
||||
EXPECT_TRUE(std::isnan(node.as<double>()));
|
||||
}
|
||||
|
||||
TEST(NodeTest, SpaceChar) {
|
||||
Node node = Node(' ');
|
||||
EXPECT_EQ(' ', node.as<char>());
|
||||
|
Reference in New Issue
Block a user