Emitter: produce string with trailing '.0' for floating point value with only integral part#1377
Conversation
…ith only integral part For example the number 1.0 will be converted to "1.0" instead of "1". This allows to keep the correct type information when parsing back the YAML. Fix jbeder#226 jbeder#412 jbeder#1016
…ith only integral part For example the number 1.0 will be converted to "1.0" instead of "1". This allows to keep the correct type information when parsing back the YAML. This patch is equivalent of jbeder#1377 but for the 0.8.0 version of yaml-cpp.
|
I don't know if it worth adding it, but this test fail on void testRoundTripDouble(double value) {
Emitter out;
out << value;
Node node = Load(out.c_str());
int64_t intValue;
EXPECT_FALSE(YAML::convert<int64_t>::decode(node, intValue));
double doubleValue;
EXPECT_TRUE(YAML::convert<double>::decode(node, doubleValue));
EXPECT_EQ(doubleValue, value);
}
TEST(RoundTripTest, Double) {
testRoundTripDouble(0.0);
testRoundTripDouble(3.14159);
} |
|
Hey, Reading the yaml spec I understand that it has 3 types: The correct fix, would probably be add a explicit '!!float' tag to indicate the type, but yaml-cpp does not support this. I have done some similar fix for some other library which uses yaml-cpp: fujitatomoya/ros2_persist_parameter_server#13 (comment) |
|
So, what we maybe actually need, is someway of configuring the Emitter to add a ".0" or not. (There might also be other things we want to configure?) |
|
Thanks @SGSSGene for pointing out fujitatomoya/ros2_persist_parameter_server#13 (comment). Having a mean to configure the Emitter would be nice. |
|
FYI there are lots of emitter flags. |
|
I am working on this now. Just notice, other parsers also have trouble with other representations, like |
|
@romainreignier please take a look at PR #1407 and give me feedback if that is a valid solution for you. |
For example the number 1.0 will be converted to "1.0" instead of "1".
This allows to keep the correct type information when parsing back the YAML.
This is an attempt to Fix #226 #412 #1016