From 82e35467152309bcebd6f3190ef32ae90d905bd1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Fri, 6 May 2011 20:49:45 +0100 Subject: [PATCH] Handle NaNs in JSON. --- json.hpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/json.hpp b/json.hpp index 24d9c87..d13793e 100644 --- a/json.hpp +++ b/json.hpp @@ -294,10 +294,15 @@ public: template inline void writeNumber(T n) { - separator(); - os << std::dec << std::setprecision(9) << n; - value = true; - space = ' '; + if (n != n) { + // NaN + writeNull(); + } else { + separator(); + os << std::dec << std::setprecision(9) << n; + value = true; + space = ' '; + } } inline void writeStringMember(const char *name, const char *s) { -- 2.7.4