File tree Expand file tree Collapse file tree 3 files changed +32
-7
lines changed
Expand file tree Collapse file tree 3 files changed +32
-7
lines changed Original file line number Diff line number Diff line change @@ -4701,6 +4701,7 @@ vim_vsnprintf(
47014701 char format [40 ];
47024702 int l ;
47034703 int remove_trailing_zeroes = FALSE;
4704+ char * s ;
47044705
47054706 f =
47064707# if defined(FEAT_EVAL )
@@ -4730,8 +4731,16 @@ vim_vsnprintf(
47304731 )
47314732 {
47324733 /* Avoid a buffer overflow */
4733- strcpy (tmp , "inf" );
4734- str_arg_l = 3 ;
4734+ if (f < 0 )
4735+ {
4736+ strcpy (tmp , "-inf" );
4737+ str_arg_l = 4 ;
4738+ }
4739+ else
4740+ {
4741+ strcpy (tmp , "inf" );
4742+ str_arg_l = 3 ;
4743+ }
47354744 }
47364745 else
47374746 {
@@ -4753,6 +4762,22 @@ vim_vsnprintf(
47534762 format [l + 1 ] = NUL ;
47544763 str_arg_l = sprintf (tmp , format , f );
47554764
4765+ /* Be consistent: Change "1.#IND" to "nan" and
4766+ * "1.#INF" to "inf". */
4767+ s = * tmp == '-' ? tmp + 1 : tmp ;
4768+ if (STRNCMP (s , "1.#INF" , 6 ) == 0 )
4769+ STRCPY (s , "inf" );
4770+ else if (STRNCMP (s , "1.#IND" , 6 ) == 0 )
4771+ STRCPY (s , "nan" );
4772+
4773+ /* Remove sign before "nan". */
4774+ if (STRNCMP (tmp , "-nan" , 4 ) == 0 )
4775+ STRCPY (tmp , "nan" );
4776+
4777+ /* Add sign before "inf" if needed. */
4778+ if (isinf (f ) == -1 && STRNCMP (tmp , "inf" , 3 ) == 0 )
4779+ STRCPY (tmp , "-inf" );
4780+
47564781 if (remove_trailing_zeroes )
47574782 {
47584783 int i ;
Original file line number Diff line number Diff line change @@ -204,12 +204,10 @@ function Test_printf_float()
204204
205205 call assert_equal (' inf' , printf (' %f' , 1.0 /0.0 ))
206206
207- " This prints inf but shouldn't it print -inf instead?
208- call assert_match (' ^-\?inf$' , printf (' %f' , -1.0 /0.0 ))
207+ call assert_match (' ^-inf$' , printf (' %f' , -1.0 /0.0 ))
209208
210- " This prints -nan but shouldn't it print nan instead?
211- call assert_match (' ^-\?nan$' , printf (' %f' , sqrt (-1.0 )))
212- call assert_match (' ^-\?nan$' , printf (' %f' , 0.0 /0.0 ))
209+ call assert_match (' ^nan$' , printf (' %f' , sqrt (-1.0 )))
210+ call assert_match (' ^nan$' , printf (' %f' , 0.0 /0.0 ))
213211
214212 call assert_fails (' echo printf("%f", "a")' , ' E807:' )
215213 endif
Original file line number Diff line number Diff line change @@ -763,6 +763,8 @@ static char *(features[]) =
763763
764764static int included_patches [] =
765765{ /* Add new patch number below this line */
766+ /**/
767+ 2266 ,
766768/**/
767769 2265 ,
768770/**/
You can’t perform that action at this time.
0 commit comments