mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-patch:8.1.1111: it is not easy to check for infinity
Problem: It is not easy to check for infinity.
Solution: Add isinf(). (Ozaki Kiichi, closes vim/vim#3787)
fda1bff39f
This commit is contained in:
parent
01b5499eea
commit
1dc088ea7d
@ -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.
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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},
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user