|
10 | 10 | #include <algorithm>
|
11 | 11 | #include <cassert>
|
12 | 12 | #include <cctype>
|
| 13 | +#include <cmath> |
| 14 | +#include <cstdio> |
13 | 15 | #include <cstring>
|
14 | 16 | #include <iomanip>
|
15 | 17 | #include <memory>
|
16 | 18 | #include <set>
|
17 | 19 | #include <sstream>
|
18 | 20 | #include <utility>
|
19 | 21 |
|
20 |
| -#if __cplusplus >= 201103L |
21 |
| -#include <cmath> |
22 |
| -#include <cstdio> |
23 |
| - |
24 |
| -#if !defined(isnan) |
25 |
| -#define isnan std::isnan |
26 |
| -#endif |
27 |
| - |
28 |
| -#if !defined(isfinite) |
29 |
| -#define isfinite std::isfinite |
30 |
| -#endif |
31 |
| - |
32 |
| -#else |
33 |
| -#include <cmath> |
34 |
| -#include <cstdio> |
35 |
| - |
36 |
| -#if defined(_MSC_VER) |
37 |
| -#if !defined(isnan) |
38 |
| -#include <float.h> |
39 |
| -#define isnan _isnan |
40 |
| -#endif |
41 |
| - |
42 |
| -#if !defined(isfinite) |
43 |
| -#include <float.h> |
44 |
| -#define isfinite _finite |
45 |
| -#endif |
46 |
| - |
47 |
| -#if !defined(_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES) |
48 |
| -#define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES 1 |
49 |
| -#endif //_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES |
50 |
| - |
51 |
| -#endif //_MSC_VER |
52 |
| - |
53 |
| -#if defined(__sun) && defined(__SVR4) // Solaris |
54 |
| -#if !defined(isfinite) |
55 |
| -#include <ieeefp.h> |
56 |
| -#define isfinite finite |
57 |
| -#endif |
58 |
| -#endif |
59 |
| - |
60 |
| -#if defined(__hpux) |
61 |
| -#if !defined(isfinite) |
62 |
| -#if defined(__ia64) && !defined(finite) |
63 |
| -#define isfinite(x) \ |
64 |
| - ((sizeof(x) == sizeof(float) ? _Isfinitef(x) : _IsFinite(x))) |
65 |
| -#endif |
66 |
| -#endif |
67 |
| -#endif |
68 |
| - |
69 |
| -#if !defined(isnan) |
70 |
| -// IEEE standard states that NaN values will not compare to themselves |
71 |
| -#define isnan(x) ((x) != (x)) |
72 |
| -#endif |
73 |
| - |
74 |
| -#if !defined(__APPLE__) |
75 |
| -#if !defined(isfinite) |
76 |
| -#define isfinite finite |
77 |
| -#endif |
78 |
| -#endif |
79 |
| -#endif |
80 |
| - |
81 | 22 | #if defined(_MSC_VER)
|
82 | 23 | // Disable warning about strdup being deprecated.
|
83 | 24 | #pragma warning(disable : 4996)
|
84 | 25 | #endif
|
85 | 26 |
|
86 | 27 | namespace Json {
|
87 | 28 |
|
88 |
| -#if __cplusplus >= 201103L || (defined(_CPPLIB_VER) && _CPPLIB_VER >= 520) |
89 | 29 | using StreamWriterPtr = std::unique_ptr<StreamWriter>;
|
90 |
| -#else |
91 |
| -using StreamWriterPtr = std::auto_ptr<StreamWriter>; |
92 |
| -#endif |
93 | 30 |
|
94 | 31 | String valueToString(LargestInt value) {
|
95 | 32 | UIntToStringBuffer buffer;
|
@@ -129,12 +66,12 @@ String valueToString(double value, bool useSpecialFloats,
|
129 | 66 | // Print into the buffer. We need not request the alternative representation
|
130 | 67 | // that always has a decimal point because JSON doesn't distinguish the
|
131 | 68 | // concepts of reals and integers.
|
132 |
| - if (!isfinite(value)) { |
133 |
| - static const char* const reps[2][3] = {{"NaN", "-Infinity", "Infinity"}, |
134 |
| - {"null", "-1e+9999", "1e+9999"}}; |
135 |
| - return reps[useSpecialFloats ? 0 : 1][isnan(value) ? 0 |
136 |
| - : (value < 0) ? 1 |
137 |
| - : 2]; |
| 69 | + if (!std::isfinite(value)) { |
| 70 | + if (std::isnan(value)) |
| 71 | + return useSpecialFloats ? "NaN" : "null"; |
| 72 | + if (value < 0) |
| 73 | + return useSpecialFloats ? "-Infinity" : "-1e+9999"; |
| 74 | + return useSpecialFloats ? "Infinity" : "1e+9999"; |
138 | 75 | }
|
139 | 76 |
|
140 | 77 | String buffer(size_t(36), '\0');
|
|
0 commit comments