Mercurial > vim
diff src/eval.c @ 8228:a0e552c51c34 v7.4.1407
commit https://github.com/vim/vim/commit/f1b6ac72293e658bb6e68c5cfd926c405b1b6f34
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Feb 23 21:26:43 2016 +0100
patch 7.4.1407
Problem: json_encode() does not handle NaN and inf properly. (David
Barnett)
Solution: For JSON turn them into "null". For JS use "NaN" and "Infinity".
Add isnan().
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 23 Feb 2016 21:30:08 +0100 |
parents | 3456e2ebebd4 |
children | 51ca0cee512e |
line wrap: on
line diff
--- a/src/eval.c +++ b/src/eval.c @@ -628,6 +628,9 @@ static void f_insert(typval_T *argvars, static void f_invert(typval_T *argvars, typval_T *rettv); static void f_isdirectory(typval_T *argvars, typval_T *rettv); static void f_islocked(typval_T *argvars, typval_T *rettv); +#if defined(FEAT_FLOAT) && defined(HAVE_MATH_H) +static void f_isnan(typval_T *argvars, typval_T *rettv); +#endif static void f_items(typval_T *argvars, typval_T *rettv); #ifdef FEAT_JOB # ifdef FEAT_CHANNEL @@ -8320,6 +8323,9 @@ static struct fst {"invert", 1, 1, f_invert}, {"isdirectory", 1, 1, f_isdirectory}, {"islocked", 1, 1, f_islocked}, +#if defined(FEAT_FLOAT) && defined(HAVE_MATH_H) + {"isnan", 1, 1, f_isnan}, +#endif {"items", 1, 1, f_items}, #ifdef FEAT_JOB # ifdef FEAT_CHANNEL @@ -14740,6 +14746,18 @@ f_islocked(typval_T *argvars, typval_T * clear_lval(&lv); } +#if defined(FEAT_FLOAT) && defined(HAVE_MATH_H) +/* + * "isnan()" function + */ + static void +f_isnan(typval_T *argvars, typval_T *rettv) +{ + rettv->vval.v_number = argvars[0].v_type == VAR_FLOAT + && isnan(argvars[0].vval.v_float); +} +#endif + static void dict_list(typval_T *argvars, typval_T *rettv, int what); /*