aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2019-08-24 15:45:33 -0400
committerJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2019-08-24 15:56:17 -0400
commit01b5499eea24961f0163b0ca3728c649aad53bbf (patch)
treecc5cc5a9004414b9145825beee791f34a06cb66e
parent34e416667378a610943f614b97da9b865d622806 (diff)
downloadrneovim-01b5499eea24961f0163b0ca3728c649aad53bbf.tar.gz
rneovim-01b5499eea24961f0163b0ca3728c649aad53bbf.tar.bz2
rneovim-01b5499eea24961f0163b0ca3728c649aad53bbf.zip
vim-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(). https://github.com/vim/vim/commit/f1b6ac72293e658bb6e68c5cfd926c405b1b6f34
-rw-r--r--runtime/doc/eval.txt5
-rw-r--r--src/nvim/eval.c7
-rw-r--r--src/nvim/eval.lua1
-rw-r--r--src/nvim/testdir/test_float_func.vim1
4 files changed, 13 insertions, 1 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index de2650baa4..811dbad559 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -2190,6 +2190,7 @@ insert({list}, {item} [, {idx}])
invert({expr}) Number bitwise invert
isdirectory({directory}) Number |TRUE| if {directory} is a directory
islocked({expr}) Number |TRUE| if {expr} is locked
+isnan({expr}) Number |TRUE| if {expr} is NaN
id({expr}) String identifier of the container
items({dict}) List key-value pairs in {dict}
jobpid({id}) Number Returns pid of a job.
@@ -5319,6 +5320,10 @@ items({dict}) *items()*
entry and the value of this entry. The |List| is in arbitrary
order.
+isnan({expr}) *isnan()*
+ Return |TRUE| if {expr} is a float with value NaN. >
+ echo isnan(0.0 / 0.0)
+< 1
jobpid({job}) *jobpid()*
Return the PID (process id) of |job-id| {job}.
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 1570af07d7..94dcbe0dcf 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -47,6 +47,7 @@
#include "nvim/indent_c.h"
#include "nvim/indent.h"
#include "nvim/mark.h"
+#include "nvim/math.h"
#include "nvim/mbyte.h"
#include "nvim/memline.h"
#include "nvim/memory.h"
@@ -12028,6 +12029,12 @@ static void f_islocked(typval_T *argvars, typval_T *rettv, FunPtr fptr)
clear_lval(&lv);
}
+// "isnan()" function
+static void f_isnan(typval_T *argvars, typval_T *rettv, FunPtr fptr)
+{
+ rettv->vval.v_number = argvars[0].v_type == VAR_FLOAT
+ && xisnan(argvars[0].vval.v_float);
+}
/// Turn a dictionary into a list
///
diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua
index 6b63003e69..bc3e612b0a 100644
--- a/src/nvim/eval.lua
+++ b/src/nvim/eval.lua
@@ -190,6 +190,7 @@ return {
invert={args=1},
isdirectory={args=1},
islocked={args=1},
+ isnan={args=1},
id={args=1},
items={args=1},
jobclose={args={1, 2}, func="f_chanclose"},
diff --git a/src/nvim/testdir/test_float_func.vim b/src/nvim/testdir/test_float_func.vim
index 5ea5192994..a44c5a9e98 100644
--- a/src/nvim/testdir/test_float_func.vim
+++ b/src/nvim/testdir/test_float_func.vim
@@ -289,7 +289,6 @@ func Test_trunc()
endfunc
func Test_isnan()
- throw 'skipped: Nvim does not support isnan()'
call assert_equal(0, isnan(1.0))
call assert_equal(1, isnan(0.0/0.0))
call assert_equal(0, isnan(1.0/0.0))