]> granicus.if.org Git - vim/commitdiff
patch 7.4.2266 v7.4.2266
authorBram Moolenaar <Bram@vim.org>
Sat, 27 Aug 2016 13:26:35 +0000 (15:26 +0200)
committerBram Moolenaar <Bram@vim.org>
Sat, 27 Aug 2016 13:26:35 +0000 (15:26 +0200)
Problem:    printf() test fails on Windows. "-inf" is not used.
Solution:   Check for Windows-specific values for "nan".  Add sign to "inf"
            when appropriate.

src/message.c
src/testdir/test_expr.vim
src/version.c

index 0d1043137211793e832943b95733fe5274715818..2824b5bbb8b61d19a1aabd675dc346d750f906e7 100644 (file)
@@ -4701,6 +4701,7 @@ vim_vsnprintf(
                    char        format[40];
                    int         l;
                    int         remove_trailing_zeroes = FALSE;
+                   char        *s;
 
                    f =
 #  if defined(FEAT_EVAL)
@@ -4730,8 +4731,16 @@ vim_vsnprintf(
                            )
                    {
                        /* Avoid a buffer overflow */
-                       strcpy(tmp, "inf");
-                       str_arg_l = 3;
+                       if (f < 0)
+                       {
+                           strcpy(tmp, "-inf");
+                           str_arg_l = 4;
+                       }
+                       else
+                       {
+                           strcpy(tmp, "inf");
+                           str_arg_l = 3;
+                       }
                    }
                    else
                    {
@@ -4753,6 +4762,22 @@ vim_vsnprintf(
                        format[l + 1] = NUL;
                        str_arg_l = sprintf(tmp, format, f);
 
+                       /* Be consistent: Change "1.#IND" to "nan" and
+                        * "1.#INF" to "inf". */
+                       s = *tmp == '-' ? tmp + 1 : tmp;
+                       if (STRNCMP(s, "1.#INF", 6) == 0)
+                           STRCPY(s, "inf");
+                       else if (STRNCMP(s, "1.#IND", 6) == 0)
+                           STRCPY(s, "nan");
+
+                       /* Remove sign before "nan". */
+                       if (STRNCMP(tmp, "-nan", 4) == 0)
+                           STRCPY(tmp, "nan");
+
+                       /* Add sign before "inf" if needed. */
+                       if (isinf(f) == -1 && STRNCMP(tmp, "inf", 3) == 0)
+                           STRCPY(tmp, "-inf");
+
                        if (remove_trailing_zeroes)
                        {
                            int i;
index 49d6c3a370268a473113c6fb11f72ca52ef04a01..6f1de59c94bf2668aa5cbf4ca3574e431aabe55f 100644 (file)
@@ -204,12 +204,10 @@ function Test_printf_float()
 
     call assert_equal('inf', printf('%f', 1.0/0.0))
 
-    " This prints inf but shouldn't it print -inf instead?
-    call assert_match('^-\?inf$', printf('%f', -1.0/0.0))
+    call assert_match('^-inf$', printf('%f', -1.0/0.0))
 
-    " This prints -nan but shouldn't it print nan instead?
-    call assert_match('^-\?nan$', printf('%f', sqrt(-1.0)))
-    call assert_match('^-\?nan$', printf('%f', 0.0/0.0))
+    call assert_match('^nan$', printf('%f', sqrt(-1.0)))
+    call assert_match('^nan$', printf('%f', 0.0/0.0))
 
     call assert_fails('echo printf("%f", "a")', 'E807:')
   endif
index 0f5e7ed749d29db8a64b32e6bcb983510d750727..93976c37d31a43b937ae95af002e430774e2f42f 100644 (file)
@@ -763,6 +763,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2266,
 /**/
     2265,
 /**/