Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
R
rapidjson
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
rapidjson
Commits
82ff580f
Commit
82ff580f
authored
May 14, 2015
by
Milo Yip
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #342 from miloyip/issue340_doubleparsebug
Fix some numbers parsed incorrectly
parents
f8b3c65d
add5a505
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
4 deletions
+38
-4
strtod.h
include/rapidjson/internal/strtod.h
+6
-1
readertest.cpp
test/unittest/readertest.cpp
+32
-3
No files found.
include/rapidjson/internal/strtod.h
View file @
82ff580f
...
...
@@ -191,8 +191,13 @@ inline bool StrtodDiyFp(const char* decimals, size_t length, size_t decimalPosit
DiyFp
rounded
(
v
.
f
>>
precisionSize
,
v
.
e
+
precisionSize
);
const
uint64_t
precisionBits
=
(
v
.
f
&
((
uint64_t
(
1
)
<<
precisionSize
)
-
1
))
*
kUlp
;
const
uint64_t
halfWay
=
(
uint64_t
(
1
)
<<
(
precisionSize
-
1
))
*
kUlp
;
if
(
precisionBits
>=
halfWay
+
error
)
if
(
precisionBits
>=
halfWay
+
error
)
{
rounded
.
f
++
;
if
(
rounded
.
f
&
(
DiyFp
::
kDpHiddenBit
<<
1
))
{
// rounding overflows mantissa (issue #340)
rounded
.
f
>>=
1
;
rounded
.
e
++
;
}
}
*
result
=
rounded
.
ToDouble
();
...
...
test/unittest/readertest.cpp
View file @
82ff580f
...
...
@@ -193,7 +193,7 @@ static void TestParseDouble() {
EXPECT_DOUBLE_EQ
(
x
,
h
.
actual_
);
\
}
\
}
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
);
...
...
@@ -327,15 +327,44 @@ static void TestParseDouble() {
if
(
fullPrecision
)
{
EXPECT_EQ
(
d
.
Uint64Value
(),
a
.
Uint64Value
());
if
(
d
.
Uint64Value
()
!=
a
.
Uint64Value
())
printf
(
" String: %s
n Actual: %.17gnExpected: %.17g
n"
,
buffer
,
h
.
actual_
,
d
.
Value
());
printf
(
" String: %s
\n
Actual: %.17g
\n
Expected: %.17g
\
n
"
,
buffer
,
h
.
actual_
,
d
.
Value
());
}
else
{
EXPECT_EQ
(
d
.
Sign
(),
a
.
Sign
());
/
* for 0.0 != -0.0 */
EXPECT_EQ
(
d
.
Sign
(),
a
.
Sign
());
/
/ for 0.0 != -0.0
EXPECT_DOUBLE_EQ
(
d
.
Value
(),
h
.
actual_
);
}
}
}
}
// Issue #340
TEST_DOUBLE
(
fullPrecision
,
"7.450580596923828e-9"
,
7.450580596923828e-9
);
{
internal
::
Double
d
(
1.0
);
for
(
int
i
=
0
;
i
<
324
;
i
++
)
{
char
buffer
[
32
];
*
internal
::
dtoa
(
d
.
Value
(),
buffer
)
=
'\0'
;
StringStream
s
(
buffer
);
ParseDoubleHandler
h
;
Reader
reader
;
ASSERT_EQ
(
kParseErrorNone
,
reader
.
Parse
<
fullPrecision
?
kParseFullPrecisionFlag
:
0
>
(
s
,
h
).
Code
());
EXPECT_EQ
(
1u
,
h
.
step_
);
internal
::
Double
a
(
h
.
actual_
);
if
(
fullPrecision
)
{
EXPECT_EQ
(
d
.
Uint64Value
(),
a
.
Uint64Value
());
if
(
d
.
Uint64Value
()
!=
a
.
Uint64Value
())
printf
(
" String: %s
\n
Actual: %.17g
\n
Expected: %.17g
\n
"
,
buffer
,
h
.
actual_
,
d
.
Value
());
}
else
{
EXPECT_EQ
(
d
.
Sign
(),
a
.
Sign
());
// for 0.0 != -0.0
EXPECT_DOUBLE_EQ
(
d
.
Value
(),
h
.
actual_
);
}
d
=
d
.
Value
()
*
0.5
;
}
}
#undef TEST_DOUBLE
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment