diff src/json.c @ 8275:ff900e499f79 v7.4.1430

commit https://github.com/vim/vim/commit/7ce686c990ea8c490d16be7f1c6bd95eb48816f9 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Feb 27 16:33:22 2016 +0100 patch 7.4.1430 Problem: When encoding JSON, turning NaN and Infinity into null without giving an error is not useful. Solution: Pass NaN and Infinity on. If the receiver can't handle them it will generate the error.
author Christian Brabandt <cb@256bit.org>
date Sat, 27 Feb 2016 16:45:04 +0100
parents 51ca0cee512e
children b8a56d4d83e0
line wrap: on
line diff
--- a/src/json.c
+++ b/src/json.c
@@ -27,8 +27,10 @@
 #  define isnan(x) _isnan(x)
 #  define isinf(x) (!_finite(x) && !_isnan(x))
 # endif
-# if defined(_MSC_VER) && !defined(INFINITY)
+# if !defined(INFINITY) && defined(DBL_MAX)
 #  define INFINITY (DBL_MAX+DBL_MAX)
+# endif
+# if !defined(NAN) && defined(INFINITY)
 #  define NAN (INFINITY-INFINITY)
 # endif
 #endif
@@ -285,12 +287,10 @@ json_encode_item(garray_T *gap, typval_T
 	case VAR_FLOAT:
 #ifdef FEAT_FLOAT
 # if defined(HAVE_MATH_H)
-	    if ((options & JSON_JS) && isnan(val->vval.v_float))
+	    if (isnan(val->vval.v_float))
 		ga_concat(gap, (char_u *)"NaN");
-	    else if ((options & JSON_JS) && isinf(val->vval.v_float))
+	    else if (isinf(val->vval.v_float))
 		ga_concat(gap, (char_u *)"Infinity");
-	    else if (isnan(val->vval.v_float) || isinf(val->vval.v_float))
-		ga_concat(gap, (char_u *)"null");
 	    else
 # endif
 	    {