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
add0d9c8
Commit
add0d9c8
authored
Sep 05, 2014
by
miloyip
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Compute error statistics of normal precision
parent
c4a657d4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
0 deletions
+45
-0
readertest.cpp
test/unittest/readertest.cpp
+45
-0
No files found.
test/unittest/readertest.cpp
View file @
add0d9c8
...
...
@@ -266,6 +266,51 @@ TEST(Reader, ParseNumber_FullPrecisionDouble) {
TestParseDouble
<
true
>
();
}
TEST
(
Reader
,
ParseNumber_NormalPrecisionError
)
{
static
unsigned
count
=
1000000
;
static
const
uint64_t
kSignMask
=
RAPIDJSON_UINT64_C2
(
0x80000000
,
0
);
union
{
double
d
;
uint64_t
u
;
uint64_t
ToBias
()
const
{
if
(
u
&
kSignMask
)
return
~
u
+
1
;
else
return
u
|
kSignMask
;
}
}
u
,
a
;
Random
r
;
double
ulpSum
=
0.0
;
double
ulpMax
=
0.0
;
for
(
unsigned
i
=
0
;
i
<
count
;
i
++
)
{
do
{
// Need to call r() in two statements for cross-platform coherent sequence.
u
.
u
=
uint64_t
(
r
())
<<
32
;
u
.
u
|=
uint64_t
(
r
());
}
while
(
std
::
isnan
(
u
.
d
)
||
std
::
isinf
(
u
.
d
)
||
!
std
::
isnormal
(
u
.
d
));
char
buffer
[
32
];
*
internal
::
dtoa
(
u
.
d
,
buffer
)
=
'\0'
;
StringStream
s
(
buffer
);
ParseDoubleHandler
h
;
Reader
reader
;
ASSERT_EQ
(
kParseErrorNone
,
reader
.
Parse
(
s
,
h
).
Code
());
EXPECT_EQ
(
1u
,
h
.
step_
);
a
.
d
=
h
.
actual_
;
uint64_t
bias1
=
u
.
ToBias
();
uint64_t
bias2
=
a
.
ToBias
();
double
ulp
=
bias1
>=
bias2
?
bias1
-
bias2
:
bias2
-
bias1
;
ulpMax
=
std
::
max
(
ulpMax
,
ulp
);
ulpSum
+=
ulp
;
}
printf
(
"ULP Average = %g, Max = %g
\n
"
,
ulpSum
/
count
,
ulpMax
);
}
TEST
(
Reader
,
ParseNumber_Error
)
{
#define TEST_NUMBER_ERROR(errorCode, str) \
{
\
...
...
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