mirror of
https://github.com/vim/vim.git
synced 2025-09-29 04:34:16 -04:00
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 #3787)
This commit is contained in:
@@ -2411,6 +2411,8 @@ inputsecret({prompt} [, {text}]) String like input() but hiding the text
|
|||||||
insert({object}, {item} [, {idx}]) List insert {item} in {object} [before {idx}]
|
insert({object}, {item} [, {idx}]) List insert {item} in {object} [before {idx}]
|
||||||
invert({expr}) Number bitwise invert
|
invert({expr}) Number bitwise invert
|
||||||
isdirectory({directory}) Number |TRUE| if {directory} is a directory
|
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
|
islocked({expr}) Number |TRUE| if {expr} is locked
|
||||||
isnan({expr}) Number |TRUE| if {expr} is NaN
|
isnan({expr}) Number |TRUE| if {expr} is NaN
|
||||||
items({dict}) List key-value pairs in {dict}
|
items({dict}) List key-value pairs in {dict}
|
||||||
@@ -5772,6 +5774,16 @@ isdirectory({directory}) *isdirectory()*
|
|||||||
exist, or isn't a directory, the result is |FALSE|. {directory}
|
exist, or isn't a directory, the result is |FALSE|. {directory}
|
||||||
is any expression, which is used as a String.
|
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
|
||||||
|
|
||||||
|
{only available when compiled with the |+float| feature}
|
||||||
|
|
||||||
islocked({expr}) *islocked()* *E786*
|
islocked({expr}) *islocked()* *E786*
|
||||||
The result is a Number, which is |TRUE| when {expr} is the
|
The result is a Number, which is |TRUE| when {expr} is the
|
||||||
name of a locked variable.
|
name of a locked variable.
|
||||||
|
@@ -237,6 +237,7 @@ static void f_invert(typval_T *argvars, typval_T *rettv);
|
|||||||
static void f_isdirectory(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);
|
static void f_islocked(typval_T *argvars, typval_T *rettv);
|
||||||
#if defined(FEAT_FLOAT) && defined(HAVE_MATH_H)
|
#if defined(FEAT_FLOAT) && defined(HAVE_MATH_H)
|
||||||
|
static void f_isinf(typval_T *argvars, typval_T *rettv);
|
||||||
static void f_isnan(typval_T *argvars, typval_T *rettv);
|
static void f_isnan(typval_T *argvars, typval_T *rettv);
|
||||||
#endif
|
#endif
|
||||||
static void f_items(typval_T *argvars, typval_T *rettv);
|
static void f_items(typval_T *argvars, typval_T *rettv);
|
||||||
@@ -721,6 +722,9 @@ static struct fst
|
|||||||
{"insert", 2, 3, f_insert},
|
{"insert", 2, 3, f_insert},
|
||||||
{"invert", 1, 1, f_invert},
|
{"invert", 1, 1, f_invert},
|
||||||
{"isdirectory", 1, 1, f_isdirectory},
|
{"isdirectory", 1, 1, f_isdirectory},
|
||||||
|
#if defined(FEAT_FLOAT) && defined(HAVE_MATH_H)
|
||||||
|
{"isinf", 1, 1, f_isinf},
|
||||||
|
#endif
|
||||||
{"islocked", 1, 1, f_islocked},
|
{"islocked", 1, 1, f_islocked},
|
||||||
#if defined(FEAT_FLOAT) && defined(HAVE_MATH_H)
|
#if defined(FEAT_FLOAT) && defined(HAVE_MATH_H)
|
||||||
{"isnan", 1, 1, f_isnan},
|
{"isnan", 1, 1, f_isnan},
|
||||||
@@ -6582,9 +6586,6 @@ f_has(typval_T *argvars, typval_T *rettv)
|
|||||||
#ifdef FEAT_TAG_BINS
|
#ifdef FEAT_TAG_BINS
|
||||||
"tag_binary",
|
"tag_binary",
|
||||||
#endif
|
#endif
|
||||||
#ifdef FEAT_TAG_OLDSTATIC
|
|
||||||
"tag_old_static",
|
|
||||||
#endif
|
|
||||||
#ifdef FEAT_TCL
|
#ifdef FEAT_TCL
|
||||||
# ifndef DYNAMIC_TCL
|
# ifndef DYNAMIC_TCL
|
||||||
"tcl",
|
"tcl",
|
||||||
@@ -7442,6 +7443,16 @@ f_islocked(typval_T *argvars, typval_T *rettv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if defined(FEAT_FLOAT) && defined(HAVE_MATH_H)
|
#if defined(FEAT_FLOAT) && defined(HAVE_MATH_H)
|
||||||
|
/*
|
||||||
|
* "isinf()" function
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
f_isinf(typval_T *argvars, typval_T *rettv)
|
||||||
|
{
|
||||||
|
if (argvars[0].v_type == VAR_FLOAT && isinf(argvars[0].vval.v_float))
|
||||||
|
rettv->vval.v_number = argvars[0].vval.v_float > 0.0 ? 1 : -1;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* "isnan()" function
|
* "isnan()" function
|
||||||
*/
|
*/
|
||||||
|
@@ -288,13 +288,24 @@ func Test_trunc()
|
|||||||
call assert_fails("call trunc('')", 'E808:')
|
call assert_fails("call trunc('')", 'E808:')
|
||||||
endfunc
|
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()
|
func Test_isnan()
|
||||||
call assert_equal(0, isnan(1.0))
|
call assert_true(isnan(0.0/0.0))
|
||||||
call assert_equal(1, isnan(0.0/0.0))
|
call assert_false(isnan(1.0))
|
||||||
call assert_equal(0, isnan(1.0/0.0))
|
call assert_false(isnan(1.0/0.0))
|
||||||
call assert_equal(0, isnan('a'))
|
call assert_false(isnan(-1.0/0.0))
|
||||||
call assert_equal(0, isnan([]))
|
call assert_false(isnan('a'))
|
||||||
call assert_equal(0, isnan({}))
|
call assert_false(isnan([]))
|
||||||
|
call assert_false(isnan({}))
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
" This was converted from test65
|
" This was converted from test65
|
||||||
|
@@ -771,6 +771,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1111,
|
||||||
/**/
|
/**/
|
||||||
1110,
|
1110,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user