diff options
-rw-r--r-- | runtime/doc/eval.txt | 10 | ||||
-rw-r--r-- | src/nvim/eval.c | 10 | ||||
-rw-r--r-- | src/nvim/eval.lua | 1 | ||||
-rw-r--r-- | src/nvim/testdir/test_float_func.vim | 23 |
4 files changed, 37 insertions, 7 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 811dbad559..eac1493a7a 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -2189,6 +2189,8 @@ insert({list}, {item} [, {idx}]) List insert {item} in {list} [before {idx}] invert({expr}) Number bitwise invert isdirectory({directory}) Number |TRUE| if {directory} is a directory +isinf({expr}) Number determine if {expr} is infinity value + (positive or negative) islocked({expr}) Number |TRUE| if {expr} is locked isnan({expr}) Number |TRUE| if {expr} is NaN id({expr}) String identifier of the container @@ -5285,6 +5287,14 @@ isdirectory({directory}) *isdirectory()* exist, or isn't a directory, the result is |FALSE|. {directory} is any expression, which is used as a String. +isinf({expr}) *isinf()* + Return 1 if {expr} is a positive infinity, or -1 a negative + infinity, otherwise 0. > + :echo isinf(1.0 / 0.0) +< 1 > + :echo isinf(-1.0 / 0.0) +< -1 + islocked({expr}) *islocked()* *E786* The result is a Number, which is |TRUE| when {expr} is the name of a locked variable. diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 94dcbe0dcf..7b620a03e6 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -11276,7 +11276,6 @@ static void f_has(typval_T *argvars, typval_T *rettv, FunPtr fptr) #endif "tablineat", "tag_binary", - "tag_old_static", "termguicolors", "termresponse", "textobjects", @@ -12029,6 +12028,15 @@ static void f_islocked(typval_T *argvars, typval_T *rettv, FunPtr fptr) clear_lval(&lv); } +// "isinf()" function +static void f_isinf(typval_T *argvars, typval_T *rettv, FunPtr fptr) +{ + if (argvars[0].v_type == VAR_FLOAT + && xisinf(argvars[0].vval.v_float)) { + rettv->vval.v_number = argvars[0].vval.v_float > 0.0 ? 1 : -1; + } +} + // "isnan()" function static void f_isnan(typval_T *argvars, typval_T *rettv, FunPtr fptr) { diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua index bc3e612b0a..a21e5a6f5d 100644 --- a/src/nvim/eval.lua +++ b/src/nvim/eval.lua @@ -189,6 +189,7 @@ return { insert={args={2, 3}}, invert={args=1}, isdirectory={args=1}, + isinf={args=1}, islocked={args=1}, isnan={args=1}, id={args=1}, diff --git a/src/nvim/testdir/test_float_func.vim b/src/nvim/testdir/test_float_func.vim index a44c5a9e98..154ef570e0 100644 --- a/src/nvim/testdir/test_float_func.vim +++ b/src/nvim/testdir/test_float_func.vim @@ -288,13 +288,24 @@ func Test_trunc() call assert_fails("call trunc('')", 'E808:') endfunc +func Test_isinf() + call assert_equal(1, isinf(1.0/0.0)) + call assert_equal(-1, isinf(-1.0/0.0)) + call assert_false(isinf(1.0)) + call assert_false(isinf(0.0/0.0)) + call assert_false(isinf('a')) + call assert_false(isinf([])) + call assert_false(isinf({})) +endfunc + func Test_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)) - call assert_equal(0, isnan('a')) - call assert_equal(0, isnan([])) - call assert_equal(0, isnan({})) + call assert_true(isnan(0.0/0.0)) + call assert_false(isnan(1.0)) + call assert_false(isnan(1.0/0.0)) + call assert_false(isnan(-1.0/0.0)) + call assert_false(isnan('a')) + call assert_false(isnan([])) + call assert_false(isnan({})) endfunc " This was converted from test65 |