The JSON-generating code was previously carefult to avoid emitting NaN
into its output, but it would still write "inf" for an infinite value,
(which is invalid JSON).
Fix by calling writeNull for any value for which std::isfinite returns
false, (rather than the previous test for merely (n != n)).
#include <stddef.h>
#include <wchar.h>
+#ifdef _MSC_VER
+# include <float.h>
+# define isfinite _finite
+#else
+# include <math.h> // isfinite
+#endif
+
#include <iomanip>
#include <limits>
#include <ostream>
template<class T>
inline void writeNumber(T n) {
- if (n != n) {
- // NaN
+ if (!isfinite(n)) {
+ // NaN/Inf
writeNull();
} else {
separator();