Skip to content

Commit 6e5e9be

Browse files
committed
corss compiler isnan
1 parent 4050143 commit 6e5e9be

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/lib_json/json_writer.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,25 @@
6868
#define snprintf _snprintf
6969
#endif
7070

71+
#if defined(_MSC_VER) && !defined(__clang__)
72+
#if _MSC_VER >= 1900 && defined(_WIN64)
73+
#include <math.h>
74+
#define isnan _isnanf
75+
#else
76+
#include <float.h>
77+
#define isnan _isnan
78+
#endif
79+
#elif __cplusplus >= 201103L
80+
#include <cmath>
81+
#define isnan std::isnan
82+
#else
83+
#include <math.h>
84+
#if !define(isnan)
85+
// IEEE standard states that NaN values will not compare to themselves
86+
#define isnan(x) (x!=x)
87+
#endif
88+
#endif
89+
7190
#if defined(_MSC_VER) && _MSC_VER >= 1400 // VC++ 8.0
7291
// Disable warning about strdup being deprecated.
7392
#pragma warning(disable : 4996)
@@ -148,7 +167,7 @@ JSONCPP_STRING valueToString(double value, bool useSpecialFloats, unsigned int p
148167
}
149168

150169
} else {
151-
// IEEE standard states that NaN values will not compare to themselves
170+
152171
if (isnan(value)) {
153172
len = snprintf(buffer, sizeof(buffer), useSpecialFloats ? "NaN" : "null");
154173
} else if (value < 0) {

src/test_lib_json/main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <sstream>
1919
#include <string>
2020
#include <iomanip>
21+
#include <cmath>
2122

2223
// Make numeric limits more convenient to talk about.
2324
// Assumes int type in 32 bits.
@@ -2405,7 +2406,7 @@ JSONTEST_FIXTURE(CharReaderAllowSpecialFloatsTest, issue209) {
24052406
JSONTEST_ASSERT_STRING_EQUAL("", errs);
24062407
JSONTEST_ASSERT_EQUAL(3u, root.size());
24072408
double n = root["a"].asDouble();
2408-
JSONTEST_ASSERT(isnan(n));
2409+
JSONTEST_ASSERT(std::isnan(n));
24092410
JSONTEST_ASSERT_EQUAL(std::numeric_limits<double>::infinity(), root.get("b", 0.0));
24102411
JSONTEST_ASSERT_EQUAL(-std::numeric_limits<double>::infinity(), root.get("c", 0.0));
24112412
}

0 commit comments

Comments
 (0)