]> granicus.if.org Git - vim/commitdiff
patch 8.1.1111: it is not easy to check for infinity v8.1.1111
authorBram Moolenaar <Bram@vim.org>
Thu, 4 Apr 2019 11:44:37 +0000 (13:44 +0200)
committerBram Moolenaar <Bram@vim.org>
Thu, 4 Apr 2019 11:44:37 +0000 (13:44 +0200)
Problem:    It is not easy to check for infinity.
Solution:   Add isinf(). (Ozaki Kiichi, closes #3787)

runtime/doc/eval.txt
src/evalfunc.c
src/testdir/test_float_func.vim
src/version.c

index a367946164a3ef12f85d415f981c922ba5eb352d..c764f9aa0c05459579d6c633078bccf90575e594 100644 (file)
@@ -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}]
 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
 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}
                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*
                The result is a Number, which is |TRUE| when {expr} is the
                name of a locked variable.
index 2eafe140ce310e423393cf21dc5b1e2e1a7ae537..4a54d6dc9de74f1ff52abc27bc31543d55c42e4f 100644 (file)
@@ -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_islocked(typval_T *argvars, typval_T *rettv);
 #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);
 #endif
 static void f_items(typval_T *argvars, typval_T *rettv);
@@ -721,6 +722,9 @@ static struct fst
     {"insert",         2, 3, f_insert},
     {"invert",         1, 1, f_invert},
     {"isdirectory",    1, 1, f_isdirectory},
+#if defined(FEAT_FLOAT) && defined(HAVE_MATH_H)
+    {"isinf",          1, 1, f_isinf},
+#endif
     {"islocked",       1, 1, f_islocked},
 #if defined(FEAT_FLOAT) && defined(HAVE_MATH_H)
     {"isnan",          1, 1, f_isnan},
@@ -6582,9 +6586,6 @@ f_has(typval_T *argvars, typval_T *rettv)
 #ifdef FEAT_TAG_BINS
        "tag_binary",
 #endif
-#ifdef FEAT_TAG_OLDSTATIC
-       "tag_old_static",
-#endif
 #ifdef FEAT_TCL
 # ifndef DYNAMIC_TCL
        "tcl",
@@ -7442,6 +7443,16 @@ f_islocked(typval_T *argvars, typval_T *rettv)
 }
 
 #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
  */
index 32b985e1b873ca9b3c7ec9eb8cd918c9d6bf363f..48fae74012f6bd97cecd77b00efa8abc3eaab186 100644 (file)
@@ -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
index 38a7683f9bb978bfdeaf2e8ce30e2ba6118abdea..9c237e5a9f27371ff6b438656f93e21dfda79f78 100644 (file)
@@ -771,6 +771,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1111,
 /**/
     1110,
 /**/