Ensure that the fact that a float was provided on input is preserved when writing output; update tests to reflect this fact

This commit is contained in:
Brendan Drew
2016-10-27 04:43:04 -07:00
parent a1db52b030
commit 89ab7eca7f
2 changed files with 12 additions and 6 deletions

View File

@@ -139,7 +139,7 @@ namespace {
JSONCPP_STRING valueToString(double value, bool useSpecialFloats, unsigned int precision) {
// Allocate a buffer that is more than large enough to store the 16 digits of
// precision requested below.
char buffer[32];
char buffer[36];
int len = -1;
char formatString[6];
@@ -150,6 +150,12 @@ JSONCPP_STRING valueToString(double value, bool useSpecialFloats, unsigned int p
// concepts of reals and integers.
if (isfinite(value)) {
len = snprintf(buffer, sizeof(buffer), formatString, value);
// try to ensure we preserve the fact that this was given to us as a double on input
if (!strstr(buffer, ".") && !strstr(buffer, "e")) {
strcat(buffer, ".0");
}
} else {
// IEEE standard states that NaN values will not compare to themselves
if (value != value) {