Commit 02aa12a2 authored by Milo Yip's avatar Milo Yip

Merge pull request #291 from miloyip/issue289_NegativeZeroRoundtrip

Fix #289 negative zero roundtrip (double only)
parents 928d3421 e5cf3b85
......@@ -21,6 +21,7 @@
#include "itoa.h" // GetDigitsLut()
#include "diyfp.h"
#include "ieee754.h"
RAPIDJSON_NAMESPACE_BEGIN
namespace internal {
......@@ -193,6 +194,9 @@ inline char* Prettify(char* buffer, int length, int k) {
inline char* dtoa(double value, char* buffer) {
if (value == 0) {
Double d(value);
if (d.Sign())
*buffer++ = '-'; // -0.0, Issue #289
buffer[0] = '0';
buffer[1] = '.';
buffer[2] = '0';
......
......@@ -187,6 +187,8 @@ static void TestParseDouble() {
Reader reader; \
ASSERT_EQ(kParseErrorNone, reader.Parse<fullPrecision ? kParseFullPrecisionFlag : 0>(s, h).Code()); \
EXPECT_EQ(1u, h.step_); \
internal::Double e(x), a(h.actual_); \
EXPECT_EQ(e.Sign(), a.Sign()); \
if (fullPrecision) { \
EXPECT_EQ(x, h.actual_); \
if (x != h.actual_) \
......@@ -197,6 +199,7 @@ static void TestParseDouble() {
}
TEST_DOUBLE(fullPrecision, "0.0", 0.0);
TEST_DOUBLE(fullPrecision, "-0.0", -0.0); // For checking issue #289
TEST_DOUBLE(fullPrecision, "1.0", 1.0);
TEST_DOUBLE(fullPrecision, "-1.0", -1.0);
TEST_DOUBLE(fullPrecision, "1.5", 1.5);
......
......@@ -93,7 +93,7 @@ TEST(Writer, String) {
TEST(Writer, Double) {
TEST_ROUNDTRIP("[1.2345,1.2345678,0.123456789012,1234567.8]");
TEST_ROUNDTRIP("[-0.0]"); // Issue #289
}
TEST(Writer, Transcode) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment