From dcbe85fe9cc84d35e0a40c44b414c8901071bd6c Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Fri, 14 Nov 2014 17:56:19 -0800 Subject: [PATCH] json.writer: handle special floats. --- basis/json/writer/writer.factor | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/basis/json/writer/writer.factor b/basis/json/writer/writer.factor index df02e43608..7f030fc214 100644 --- a/basis/json/writer/writer.factor +++ b/basis/json/writer/writer.factor @@ -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* ;