]> git.cworth.org Git - apitrace/commitdiff
Handle NaNs in JSON.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Fri, 6 May 2011 19:49:45 +0000 (20:49 +0100)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Fri, 6 May 2011 19:49:45 +0000 (20:49 +0100)
json.hpp

index 24d9c873930d358980c7750572882c3365d7f631..d13793ebd64925f253c6a88e509b1213fbfc9e87 100644 (file)
--- a/json.hpp
+++ b/json.hpp
@@ -294,10 +294,15 @@ public:
 
     template<class T>
     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) {