]> gitweb.factorcode.org Git - factor.git/commitdiff
json.writer: handle special floats.
authorJohn Benediktsson <mrjbq7@gmail.com>
Sat, 15 Nov 2014 01:56:19 +0000 (17:56 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Sat, 15 Nov 2014 01:56:19 +0000 (17:56 -0800)
basis/json/writer/writer.factor

index df02e43608497c5064c2ce7a404502c51c3c0e4a..7f030fc21467b4d2d6da7682455c2649e69277ec 100644 (file)
@@ -37,6 +37,16 @@ M: string stream-json-print
 M: integer stream-json-print
     [ number>string ] [ stream-write ] bi* ;
 
+M: float stream-json-print
+    [
+        {
+            { [ dup fp-nan? ] [ drop "NaN" ] }
+            { [ dup 1/0. = ] [ drop "Infinity" ] }
+            { [ dup -1/0. = ] [ drop "-Infinity" ] }
+            [ number>string ]
+        } cond
+    ] dip stream-write ;
+
 M: real stream-json-print
     [ >float number>string ] [ stream-write ] bi* ;