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
475b2420
Commit
475b2420
authored
Sep 16, 2014
by
Milo Yip
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor refactoring before optimization trial
parent
5171775d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
22 deletions
+32
-22
strtod.h
include/rapidjson/internal/strtod.h
+30
-20
reader.h
include/rapidjson/reader.h
+2
-2
No files found.
include/rapidjson/internal/strtod.h
View file @
475b2420
...
...
@@ -29,7 +29,7 @@
namespace
rapidjson
{
namespace
internal
{
inline
double
Strtod
FastPath
(
double
significand
,
int
exp
)
{
inline
double
FastPath
(
double
significand
,
int
exp
)
{
if
(
exp
<
-
308
)
return
0
.
0
;
else
if
(
exp
>=
0
)
...
...
@@ -38,14 +38,14 @@ inline double StrtodFastPath(double significand, int exp) {
return
significand
/
internal
::
Pow10
(
-
exp
);
}
inline
double
NormalPrecision
(
double
d
,
int
p
)
{
inline
double
Strtod
NormalPrecision
(
double
d
,
int
p
)
{
if
(
p
<
-
308
)
{
// Prevent expSum < -308, making Pow10(p) = 0
d
=
Strtod
FastPath
(
d
,
-
308
);
d
=
Strtod
FastPath
(
d
,
p
+
308
);
d
=
FastPath
(
d
,
-
308
);
d
=
FastPath
(
d
,
p
+
308
);
}
else
d
=
Strtod
FastPath
(
d
,
p
);
d
=
FastPath
(
d
,
p
);
return
d
;
}
...
...
@@ -124,25 +124,24 @@ inline int CheckWithinHalfULP(double b, const BigInteger& d, int dExp, bool* adj
return
cmp
;
}
inline
double
FullPrecision
(
double
d
,
int
p
,
const
char
*
decimals
,
size_t
length
,
size_t
decimalPosition
,
int
exp
)
{
RAPIDJSON_ASSERT
(
d
>=
0
.
0
);
RAPIDJSON_ASSERT
(
length
>=
1
);
inline
bool
StrtodFast
(
double
d
,
int
p
,
double
*
result
)
{
// Use fast path for string-to-double conversion if possible
// see http://www.exploringbinary.com/fast-path-decimal-to-floating-point-conversion/
if
(
p
>
22
)
{
if
(
p
<
22
+
16
)
{
// Fast Path Cases In Disguise
d
*=
internal
::
Pow10
(
p
-
22
);
p
=
22
;
}
if
(
p
>
22
&&
p
<
22
+
16
)
{
// Fast Path Cases In Disguise
d
*=
internal
::
Pow10
(
p
-
22
);
p
=
22
;
}
if
(
p
>=
-
22
&&
p
<=
22
&&
d
<=
9007199254740991
.
0
)
// 2^53 - 1
return
StrtodFastPath
(
d
,
p
);
// Use slow-path with BigInteger comparison
if
(
p
>=
-
22
&&
p
<=
22
&&
d
<=
9007199254740991
.
0
)
{
// 2^53 - 1
*
result
=
FastPath
(
d
,
p
);
return
true
;
}
else
return
false
;
}
inline
double
StrtodBigInteger
(
double
d
,
int
p
,
const
char
*
decimals
,
size_t
length
,
size_t
decimalPosition
,
int
exp
)
{
// Trim leading zeros
while
(
*
decimals
==
'0'
&&
length
>
1
)
{
length
--
;
...
...
@@ -170,7 +169,7 @@ inline double FullPrecision(double d, int p, const char* decimals, size_t length
const
BigInteger
dInt
(
decimals
,
length
);
const
int
dExp
=
(
int
)
decimalPosition
-
(
int
)
length
+
exp
;
Double
approx
=
NormalPrecision
(
d
,
p
);
Double
approx
=
Strtod
NormalPrecision
(
d
,
p
);
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
bool
adjustToNegative
;
int
cmp
=
CheckWithinHalfULP
(
approx
.
Value
(),
dInt
,
dExp
,
&
adjustToNegative
);
...
...
@@ -191,6 +190,17 @@ inline double FullPrecision(double d, int p, const char* decimals, size_t length
return
approx
.
Value
();
}
inline
double
StrtodFullPrecision
(
double
d
,
int
p
,
const
char
*
decimals
,
size_t
length
,
size_t
decimalPosition
,
int
exp
)
{
RAPIDJSON_ASSERT
(
d
>=
0
.
0
);
RAPIDJSON_ASSERT
(
length
>=
1
);
double
result
;
if
(
StrtodFast
(
d
,
p
,
&
result
))
return
result
;
return
StrtodBigInteger
(
d
,
p
,
decimals
,
length
,
decimalPosition
,
exp
);
}
}
// namespace internal
}
// namespace rapidjson
...
...
include/rapidjson/reader.h
View file @
475b2420
...
...
@@ -941,9 +941,9 @@ private:
if
(
useDouble
)
{
int
p
=
exp
+
expFrac
;
if
(
parseFlags
&
kParseFullPrecisionFlag
)
d
=
internal
::
FullPrecision
(
d
,
p
,
decimal
,
length
,
decimalPosition
,
exp
);
d
=
internal
::
Strtod
FullPrecision
(
d
,
p
,
decimal
,
length
,
decimalPosition
,
exp
);
else
d
=
internal
::
NormalPrecision
(
d
,
p
);
d
=
internal
::
Strtod
NormalPrecision
(
d
,
p
);
cont
=
handler
.
Double
(
minus
?
-
d
:
d
);
}
...
...
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