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
7e24024f
Commit
7e24024f
authored
Apr 10, 2015
by
Milo Yip
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #293 from miloyip/issue287_WarningFloatEqual
Add -Wfloat-equal and fix all derived warnings
parents
a0a361d2
5ae85e67
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
21 additions
and
17 deletions
+21
-17
document.h
include/rapidjson/document.h
+4
-2
diyfp.h
include/rapidjson/internal/diyfp.h
+1
-1
dtoa.h
include/rapidjson/internal/dtoa.h
+2
-2
ieee754.h
include/rapidjson/internal/ieee754.h
+2
-1
reader.h
include/rapidjson/reader.h
+1
-1
CMakeLists.txt
test/unittest/CMakeLists.txt
+2
-2
documenttest.cpp
test/unittest/documenttest.cpp
+1
-1
readertest.cpp
test/unittest/readertest.cpp
+3
-2
valuetest.cpp
test/unittest/valuetest.cpp
+5
-5
No files found.
include/rapidjson/document.h
View file @
7e24024f
...
...
@@ -700,8 +700,10 @@ public:
return
StringEqual
(
rhs
);
case
kNumberType
:
if
(
IsDouble
()
||
rhs
.
IsDouble
())
return
GetDouble
()
==
rhs
.
GetDouble
();
// May convert one operand from integer to double.
if
(
IsDouble
()
||
rhs
.
IsDouble
())
{
float
delta
=
GetDouble
()
-
rhs
.
GetDouble
();
// May convert one operand from integer to double.
return
delta
>=
0
.
0
&&
delta
<=
0
.
0
;
// Prevent -Wfloat-equal
}
else
return
data_
.
n
.
u64
==
rhs
.
data_
.
n
.
u64
;
...
...
include/rapidjson/internal/diyfp.h
View file @
7e24024f
...
...
@@ -238,7 +238,7 @@ inline DiyFp GetCachedPower(int e, int* K) {
//int k = static_cast<int>(ceil((-61 - e) * 0.30102999566398114)) + 374;
double
dk
=
(
-
61
-
e
)
*
0
.
30102999566398114
+
347
;
// dk must be positive, so can do ceiling in positive
int
k
=
static_cast
<
int
>
(
dk
);
if
(
k
!=
dk
)
if
(
dk
-
k
>
0
.
0
)
k
++
;
unsigned
index
=
static_cast
<
unsigned
>
((
k
>>
3
)
+
1
);
...
...
include/rapidjson/internal/dtoa.h
View file @
7e24024f
...
...
@@ -193,8 +193,8 @@ inline char* Prettify(char* buffer, int length, int k) {
}
inline
char
*
dtoa
(
double
value
,
char
*
buffer
)
{
if
(
value
==
0
)
{
Double
d
(
value
);
Double
d
(
value
);
if
(
d
.
IsZero
())
{
if
(
d
.
Sign
())
*
buffer
++
=
'-'
;
// -0.0, Issue #289
buffer
[
0
]
=
'0'
;
...
...
include/rapidjson/internal/ieee754.h
View file @
7e24024f
...
...
@@ -36,7 +36,7 @@ public:
double
PreviousPositiveDouble
()
const
{
RAPIDJSON_ASSERT
(
!
Sign
());
if
(
d
==
0
.
0
)
if
(
IsZero
()
)
return
0
.
0
;
else
return
Double
(
u
-
1
).
Value
();
...
...
@@ -49,6 +49,7 @@ public:
bool
IsNan
()
const
{
return
(
u
&
kExponentMask
)
==
kExponentMask
&&
Significand
()
!=
0
;
}
bool
IsInf
()
const
{
return
(
u
&
kExponentMask
)
==
kExponentMask
&&
Significand
()
==
0
;
}
bool
IsNormal
()
const
{
return
(
u
&
kExponentMask
)
!=
0
||
Significand
()
==
0
;
}
bool
IsZero
()
const
{
return
(
u
&
(
kExponentMask
|
kSignificandMask
))
==
0
;
}
uint64_t
IntegerSignificand
()
const
{
return
IsNormal
()
?
Significand
()
|
kHiddenBit
:
Significand
();
}
int
IntegerExponent
()
const
{
return
(
IsNormal
()
?
Exponent
()
:
kDenormalExponent
)
-
kSignificandSize
;
}
...
...
include/rapidjson/reader.h
View file @
7e24024f
...
...
@@ -896,7 +896,7 @@ private:
if
(
significandDigit
<
17
)
{
d
=
d
*
10
.
0
+
(
s
.
TakePush
()
-
'0'
);
--
expFrac
;
if
(
d
!=
0
.
0
)
if
(
d
>
0
.
0
)
significandDigit
++
;
}
else
...
...
test/unittest/CMakeLists.txt
View file @
7e24024f
...
...
@@ -14,9 +14,9 @@ set(UNITTEST_SOURCES
writertest.cpp
)
if
(
"
${
CMAKE_CXX_COMPILER_ID
}
"
STREQUAL
"GNU"
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-Werror -W
effc++ -Wswitch-default
"
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-Werror -W
all -Wextra -Weffc++ -Wswitch-default -Wfloat-equal
"
)
elseif
(
CMAKE_CXX_COMPILER_ID MATCHES
"Clang"
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-Werror -W
effc++ -Wswitch-default
"
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-Werror -W
all -Wextra -Weffc++ -Wswitch-default -Wfloat-equal
"
)
elseif
(
"
${
CMAKE_CXX_COMPILER_ID
}
"
STREQUAL
"MSVC"
)
add_definitions
(
-D_CRT_SECURE_NO_WARNINGS=1
)
endif
()
...
...
test/unittest/documenttest.cpp
View file @
7e24024f
...
...
@@ -63,7 +63,7 @@ void ParseTest() {
EXPECT_TRUE
(
doc
.
HasMember
(
"pi"
));
const
ValueType
&
pi
=
doc
[
"pi"
];
EXPECT_TRUE
(
pi
.
IsNumber
());
EXPECT_EQ
(
3.1416
,
pi
.
GetDouble
());
EXPECT_
DOUBLE_
EQ
(
3.1416
,
pi
.
GetDouble
());
EXPECT_TRUE
(
doc
.
HasMember
(
"a"
));
const
ValueType
&
a
=
doc
[
"a"
];
...
...
test/unittest/readertest.cpp
View file @
7e24024f
...
...
@@ -30,6 +30,7 @@ using namespace rapidjson;
#ifdef __GNUC__
RAPIDJSON_DIAG_PUSH
RAPIDJSON_DIAG_OFF
(
effc
++
)
RAPIDJSON_DIAG_OFF
(
float
-
equal
)
#endif
template
<
bool
expect
>
...
...
@@ -190,7 +191,7 @@ static void TestParseDouble() {
internal
::
Double
e
(
x
),
a
(
h
.
actual_
);
\
EXPECT_EQ
(
e
.
Sign
(),
a
.
Sign
());
\
if
(
fullPrecision
)
{
\
EXPECT_
EQ
(
x
,
h
.
actual_
);
\
EXPECT_
NEAR
(
x
,
h
.
actual_
,
0.0
);
\
if
(
x
!=
h
.
actual_
)
\
printf
(
" String: %s
\n
Actual: %.17g
\n
Expected: %.17g
\n
"
,
str
,
h
.
actual_
,
x
);
\
}
\
...
...
@@ -662,7 +663,7 @@ struct ParseObjectHandler : BaseReaderHandler<UTF8<>, ParseObjectHandler> {
}
}
bool
Uint
(
unsigned
i
)
{
return
Int
(
i
);
}
bool
Double
(
double
d
)
{
EXPECT_EQ
(
12u
,
step_
);
EXPECT_EQ
(
3.1416
,
d
);
step_
++
;
return
true
;
}
bool
Double
(
double
d
)
{
EXPECT_EQ
(
12u
,
step_
);
EXPECT_
DOUBLE_
EQ
(
3.1416
,
d
);
step_
++
;
return
true
;
}
bool
String
(
const
char
*
str
,
size_t
,
bool
)
{
switch
(
step_
)
{
case
1
:
EXPECT_STREQ
(
"hello"
,
str
);
step_
++
;
return
true
;
...
...
test/unittest/valuetest.cpp
View file @
7e24024f
...
...
@@ -339,7 +339,7 @@ TEST(Value, Int) {
EXPECT_EQ
(
1234u
,
x
.
GetUint
());
EXPECT_EQ
(
1234
,
x
.
GetInt64
());
EXPECT_EQ
(
1234u
,
x
.
GetUint64
());
EXPECT_
EQ
(
1234
,
x
.
GetDouble
()
);
EXPECT_
NEAR
(
1234.0
,
x
.
GetDouble
(),
0.0
);
//EXPECT_EQ(1234, (int)x);
//EXPECT_EQ(1234, (unsigned)x);
//EXPECT_EQ(1234, (int64_t)x);
...
...
@@ -397,7 +397,7 @@ TEST(Value, Uint) {
EXPECT_TRUE
(
x
.
IsUint
());
EXPECT_TRUE
(
x
.
IsInt64
());
EXPECT_TRUE
(
x
.
IsUint64
());
EXPECT_
EQ
(
1234.0
,
x
.
GetDouble
()
);
// Number can always be cast as double but !IsDouble().
EXPECT_
NEAR
(
1234.0
,
x
.
GetDouble
(),
0.0
);
// Number can always be cast as double but !IsDouble().
EXPECT_FALSE
(
x
.
IsDouble
());
EXPECT_FALSE
(
x
.
IsNull
());
...
...
@@ -517,7 +517,7 @@ TEST(Value, Double) {
// Constructor with double
Value
x
(
12.34
);
EXPECT_EQ
(
kNumberType
,
x
.
GetType
());
EXPECT_
EQ
(
12.34
,
x
.
GetDouble
()
);
EXPECT_
NEAR
(
12.34
,
x
.
GetDouble
(),
0.0
);
EXPECT_TRUE
(
x
.
IsNumber
());
EXPECT_TRUE
(
x
.
IsDouble
());
...
...
@@ -533,10 +533,10 @@ TEST(Value, Double) {
// SetDouble()
Value
z
;
z
.
SetDouble
(
12.34
);
EXPECT_
EQ
(
12.34
,
z
.
GetDouble
()
);
EXPECT_
NEAR
(
12.34
,
z
.
GetDouble
(),
0.0
);
z
=
56.78
;
EXPECT_
EQ
(
56.78
,
z
.
GetDouble
()
);
EXPECT_
NEAR
(
56.78
,
z
.
GetDouble
(),
0.0
);
}
TEST
(
Value
,
String
)
{
...
...
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