Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/miloyip/rapidjson.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjack_perisich <jackperisich@gmail.com>2021-07-28 02:50:51 +0300
committerjack_perisich <jackperisich@gmail.com>2021-07-28 02:50:51 +0300
commitbb0621108802d7839059cede4dee5daca7205e28 (patch)
treedda67ad543fd0b51810bc9bf72a4cd923907cbc3
parent48fbd8cd202ca54031fe799db2ad44ffa8e77c13 (diff)
Fix small errors in dtoa output for certain doubles
-rw-r--r--include/rapidjson/internal/dtoa.h10
-rw-r--r--test/unittest/dtoatest.cpp1
2 files changed, 8 insertions, 3 deletions
diff --git a/include/rapidjson/internal/dtoa.h b/include/rapidjson/internal/dtoa.h
index 621402fd..9f6ae3b3 100644
--- a/include/rapidjson/internal/dtoa.h
+++ b/include/rapidjson/internal/dtoa.h
@@ -58,7 +58,11 @@ inline int CountDecimalDigit32(uint32_t n) {
}
inline void DigitGen(const DiyFp& W, const DiyFp& Mp, uint64_t delta, char* buffer, int* len, int* K) {
- static const uint32_t kPow10[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 };
+ static const uint64_t kPow10[] = { 1U, 10U, 100U, 1000U, 10000U, 100000U, 1000000U, 10000000U, 100000000U,
+ 1000000000U, 10000000000U, 100000000000U, 1000000000000U,
+ 10000000000000U, 100000000000000U, 1000000000000000U,
+ 10000000000000000U, 100000000000000000U, 1000000000000000000U,
+ 10000000000000000000U };
const DiyFp one(uint64_t(1) << -Mp.e, Mp.e);
const DiyFp wp_w = Mp - W;
uint32_t p1 = static_cast<uint32_t>(Mp.f >> -one.e);
@@ -86,7 +90,7 @@ inline void DigitGen(const DiyFp& W, const DiyFp& Mp, uint64_t delta, char* buff
uint64_t tmp = (static_cast<uint64_t>(p1) << -one.e) + p2;
if (tmp <= delta) {
*K += kappa;
- GrisuRound(buffer, *len, delta, tmp, static_cast<uint64_t>(kPow10[kappa]) << -one.e, wp_w.f);
+ GrisuRound(buffer, *len, delta, tmp, kPow10[kappa] << -one.e, wp_w.f);
return;
}
}
@@ -103,7 +107,7 @@ inline void DigitGen(const DiyFp& W, const DiyFp& Mp, uint64_t delta, char* buff
if (p2 < delta) {
*K += kappa;
int index = -kappa;
- GrisuRound(buffer, *len, delta, p2, one.f, wp_w.f * (index < 9 ? kPow10[index] : 0));
+ GrisuRound(buffer, *len, delta, p2, one.f, wp_w.f * (index < 20 ? kPow10[index] : 0));
return;
}
}
diff --git a/test/unittest/dtoatest.cpp b/test/unittest/dtoatest.cpp
index 66576bdf..3ec89828 100644
--- a/test/unittest/dtoatest.cpp
+++ b/test/unittest/dtoatest.cpp
@@ -38,6 +38,7 @@ TEST(dtoa, normal) {
TEST_DTOA(0.123456789012, "0.123456789012");
TEST_DTOA(1234567.8, "1234567.8");
TEST_DTOA(-79.39773355813419, "-79.39773355813419");
+ TEST_DTOA(-36.973846435546875, "-36.973846435546875");
TEST_DTOA(0.000001, "0.000001");
TEST_DTOA(0.0000001, "1e-7");
TEST_DTOA(1e30, "1e30");