mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 12:41:17 +00:00
Fix floating point precision on input.
This commit is contained in:
@@ -78,6 +78,7 @@ namespace YAML
|
|||||||
struct convert<type> {\
|
struct convert<type> {\
|
||||||
static Node encode(const type& rhs) {\
|
static Node encode(const type& rhs) {\
|
||||||
std::stringstream stream;\
|
std::stringstream stream;\
|
||||||
|
stream.precision(std::numeric_limits<type>::digits10 + 1);\
|
||||||
stream << rhs;\
|
stream << rhs;\
|
||||||
return Node(stream.str());\
|
return Node(stream.str());\
|
||||||
}\
|
}\
|
||||||
|
@@ -498,6 +498,14 @@ namespace Test
|
|||||||
YAML_ASSERT_THROWS(node.begin()->begin()->IsDefined(), YAML::InvalidNode);
|
YAML_ASSERT_THROWS(node.begin()->begin()->IsDefined(), YAML::InvalidNode);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST FloatingPrecision()
|
||||||
|
{
|
||||||
|
const double x = 0.123456789;
|
||||||
|
YAML::Node node = YAML::Node(x);
|
||||||
|
YAML_ASSERT(node.as<double>() == x);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RunNodeTest(TEST (*test)(), const std::string& name, int& passed, int& total) {
|
void RunNodeTest(TEST (*test)(), const std::string& name, int& passed, int& total) {
|
||||||
@@ -560,6 +568,7 @@ namespace Test
|
|||||||
RunNodeTest(&Node::ForceInsertIntoMap, "force insert into map", passed, total);
|
RunNodeTest(&Node::ForceInsertIntoMap, "force insert into map", passed, total);
|
||||||
RunNodeTest(&Node::ResetNode, "reset node", passed, total);
|
RunNodeTest(&Node::ResetNode, "reset node", passed, total);
|
||||||
RunNodeTest(&Node::DereferenceIteratorError, "dereference iterator error", passed, total);
|
RunNodeTest(&Node::DereferenceIteratorError, "dereference iterator error", passed, total);
|
||||||
|
RunNodeTest(&Node::FloatingPrecision, "floating precision", passed, total);
|
||||||
|
|
||||||
std::cout << "Node tests: " << passed << "/" << total << " passed\n";
|
std::cout << "Node tests: " << passed << "/" << total << " passed\n";
|
||||||
return passed == total;
|
return passed == total;
|
||||||
|
Reference in New Issue
Block a user