To: vim_dev@googlegroups.com Subject: Patch 8.2.2928 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.2928 Problem: The evalfunc.c file is too big. Solution: Move float related functionality to a separate file. (Yegappan Lakshmanan, closes #8287) Files: Filelist, src/Make_ami.mak, src/Make_cyg_ming.mak, src/Make_mvc.mak, src/Make_vms.mms, src/Makefile, src/README.md, src/eval.c, src/evalfunc.c, src/float.c, src/proto.h, src/proto/eval.pro, src/proto/float.pro *** ../vim-8.2.2927/Filelist 2021-05-24 18:48:00.756582853 +0200 --- Filelist 2021-06-02 16:53:34.790373298 +0200 *************** *** 68,73 **** --- 68,74 ---- src/fileio.c \ src/filepath.c \ src/findfile.c \ + src/float.c \ src/fold.c \ src/getchar.c \ src/globals.h \ *************** *** 246,251 **** --- 247,253 ---- src/proto/fileio.pro \ src/proto/filepath.pro \ src/proto/findfile.pro \ + src/proto/float.pro \ src/proto/fold.pro \ src/proto/getchar.pro \ src/proto/gui.pro \ *** ../vim-8.2.2927/src/Make_ami.mak 2020-09-09 20:41:21.588337124 +0200 --- src/Make_ami.mak 2021-06-02 16:53:34.790373298 +0200 *************** *** 117,122 **** --- 117,123 ---- fileio.c \ filepath.c \ findfile.c \ + float.c \ fold.c \ getchar.c \ hardcopy.c \ *** ../vim-8.2.2927/src/Make_cyg_ming.mak 2021-05-24 18:48:00.756582853 +0200 --- src/Make_cyg_ming.mak 2021-06-02 16:53:34.790373298 +0200 *************** *** 749,754 **** --- 749,755 ---- $(OUTDIR)/fileio.o \ $(OUTDIR)/filepath.o \ $(OUTDIR)/findfile.o \ + $(OUTDIR)/float.o \ $(OUTDIR)/fold.o \ $(OUTDIR)/getchar.o \ $(OUTDIR)/gui_xim.o \ *** ../vim-8.2.2927/src/Make_mvc.mak 2021-05-24 18:48:00.756582853 +0200 --- src/Make_mvc.mak 2021-06-02 16:53:34.790373298 +0200 *************** *** 743,748 **** --- 743,749 ---- $(OUTDIR)\fileio.obj \ $(OUTDIR)\filepath.obj \ $(OUTDIR)\findfile.obj \ + $(OUTDIR)\float.obj \ $(OUTDIR)\fold.obj \ $(OUTDIR)\getchar.obj \ $(OUTDIR)\gui_xim.obj \ *************** *** 1599,1604 **** --- 1600,1607 ---- $(OUTDIR)/findfile.obj: $(OUTDIR) findfile.c $(INCL) + $(OUTDIR)/float.obj: $(OUTDIR) float.c $(INCL) + $(OUTDIR)/fold.obj: $(OUTDIR) fold.c $(INCL) $(OUTDIR)/getchar.obj: $(OUTDIR) getchar.c $(INCL) *************** *** 1935,1940 **** --- 1938,1944 ---- proto/fileio.pro \ proto/filepath.pro \ proto/findfile.pro \ + proto/float.pro \ proto/getchar.pro \ proto/gui_xim.pro \ proto/hardcopy.pro \ *** ../vim-8.2.2927/src/Make_vms.mms 2021-01-04 10:47:21.698153964 +0100 --- src/Make_vms.mms 2021-06-02 16:53:34.790373298 +0200 *************** *** 343,348 **** --- 343,349 ---- fileio.c \ filepath.c, \ findfile.c \ + float.c \ fold.c \ getchar.c \ gui_xim.c \ *************** *** 460,465 **** --- 461,467 ---- fileio.obj \ filepath.obj \ findfile.obj \ + float.obj \ fold.obj \ getchar.obj \ gui_xim.obj \ *************** *** 860,865 **** --- 862,870 ---- ascii.h keymap.h term.h macros.h structs.h regexp.h \ gui.h beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \ errors.h globals.h + float.obj : float.c vim.h [.auto]config.h feature.h os_unix.h \ + ascii.h keymap.h term.h macros.h structs.h regexp.h gui.h beval.h \ + [.proto]gui_beval.pro option.h ex_cmds.h proto.h errors.h globals.h fold.obj : fold.c vim.h [.auto]config.h feature.h os_unix.h \ ascii.h keymap.h term.h macros.h structs.h regexp.h gui.h beval.h \ [.proto]gui_beval.pro option.h ex_cmds.h proto.h errors.h globals.h *** ../vim-8.2.2927/src/Makefile 2021-01-30 20:31:57.683115306 +0100 --- src/Makefile 2021-06-02 17:06:31.812471779 +0200 *************** *** 386,392 **** # Select the architecture supported. Default is to build for the current # platform. Use "both" for a universal binary. That probably doesn't work # when including Perl, Python, etc. ! #CONF_OPT_DARWIN = --with-mac-arch=i386 #CONF_OPT_DARWIN = --with-mac-arch=ppc #CONF_OPT_DARWIN = --with-mac-arch=both --- 386,393 ---- # Select the architecture supported. Default is to build for the current # platform. Use "both" for a universal binary. That probably doesn't work # when including Perl, Python, etc. ! # NOTE: ppc probably doesn't work anymore, ! #CONF_OPT_DARWIN = --with-mac-arch=intel #CONF_OPT_DARWIN = --with-mac-arch=ppc #CONF_OPT_DARWIN = --with-mac-arch=both *************** *** 436,441 **** --- 437,444 ---- # PYTHON # Uncomment lines here when you want to include the Python interface. # This requires at least "normal" features, "tiny" and "small" don't work. + # Python 3 is preferred, Python 2 (often referred to as "Python") has been + # deprecated for a long time. # NOTE: This may cause threading to be enabled, which has side effects (such # as using different libraries and debugging becomes more difficult). # For Python3 support make a symbolic link in /usr/local/bin: *************** *** 463,469 **** # TCL # Uncomment this when you want to include the Tcl interface. # First one is for static linking, second one for dynamic loading. ! #CONF_OPT_TCL = --enable-tclinterp #CONF_OPT_TCL = --enable-tclinterp=dynamic #CONF_OPT_TCL = --enable-tclinterp --with-tclsh=tclsh8.4 --- 466,472 ---- # TCL # Uncomment this when you want to include the Tcl interface. # First one is for static linking, second one for dynamic loading. ! CONF_OPT_TCL = --enable-tclinterp #CONF_OPT_TCL = --enable-tclinterp=dynamic #CONF_OPT_TCL = --enable-tclinterp --with-tclsh=tclsh8.4 *************** *** 690,705 **** # PROFILE_CFLAGS=-g -O0 --coverage -DWE_ARE_PROFILING -DUSE_GCOV_FLUSH ! # Uncomment one of the next two lines to compile Vim with the ! # address sanitizer (asan) or with the undefined sanitizer. Works with gcc. # May make Vim twice as slow. Errors are reported on stderr. # More at: https://code.google.com/p/address-sanitizer/ # Useful environment variables: # $ export ASAN_OPTIONS="print_stacktrace=1 log_path=asan" # $ export LSAN_OPTIONS="suppressions=`pwd`/testdir/lsan-suppress.txt" # When running tests output can be found in testdir/asan.* ! #SANITIZER_CFLAGS = -g -O0 -fsanitize=address -fno-omit-frame-pointer ! #SANITIZER_CFLAGS = -g -O0 -fsanitize=undefined -fno-omit-frame-pointer # Similarly when compiling with clang and using ubsan. # $ export UBSAN_OPTIONS="print_stacktrace=1 log_path=ubsan" --- 693,710 ---- # PROFILE_CFLAGS=-g -O0 --coverage -DWE_ARE_PROFILING -DUSE_GCOV_FLUSH ! # Uncomment the next lines to compile Vim with the address sanitizer (asan) and ! # with the undefined sanitizer. Works with gcc. ! # You should also use -DEXITFREE to avoid false reports. # May make Vim twice as slow. Errors are reported on stderr. # More at: https://code.google.com/p/address-sanitizer/ # Useful environment variables: # $ export ASAN_OPTIONS="print_stacktrace=1 log_path=asan" # $ export LSAN_OPTIONS="suppressions=`pwd`/testdir/lsan-suppress.txt" # When running tests output can be found in testdir/asan.* ! #SANITIZER_CFLAGS = -g -O0 -fsanitize-recover=all \ ! # -fsanitize=address -fsanitize=undefined \ ! # -fno-omit-frame-pointer # Similarly when compiling with clang and using ubsan. # $ export UBSAN_OPTIONS="print_stacktrace=1 log_path=ubsan" *************** *** 979,985 **** # The value of QUOTESED comes from auto/config.mk. # Uncomment the next line to use the default value. ! # QUOTESED = sed -e 's/[\\"]/\\&/g' -e 's/\\"/"/' -e 's/\\";$$/";/' ##################### end of system specific lines ################### }}} --- 984,990 ---- # The value of QUOTESED comes from auto/config.mk. # Uncomment the next line to use the default value. ! # QUOTESED = sed -e 's/[\\"]/\\&/g' -e 's/\\"/"/' -e 's/\\";$$/";/' -e 's/ */ /g' ##################### end of system specific lines ################### }}} *************** *** 1621,1626 **** --- 1626,1632 ---- fileio.c \ filepath.c \ findfile.c \ + float.c \ fold.c \ getchar.c \ gui_xim.c \ *************** *** 1775,1780 **** --- 1781,1787 ---- objects/fileio.o \ objects/filepath.o \ objects/findfile.o \ + objects/float.o \ objects/fold.o \ objects/getchar.o \ objects/gui_xim.o \ *************** *** 1945,1950 **** --- 1952,1958 ---- fileio.pro \ filepath.pro \ findfile.pro \ + float.pro \ fold.pro \ getchar.pro \ gui_xim.pro \ *************** *** 3247,3252 **** --- 3255,3263 ---- objects/findfile.o: findfile.c $(CCC) -o $@ findfile.c + objects/float.o: float.c + $(CCC) -o $@ float.c + objects/fold.o: fold.c $(CCC) -o $@ fold.c *************** *** 3838,3843 **** --- 3849,3858 ---- auto/osdef.h ascii.h keymap.h term.h macros.h option.h beval.h \ proto/gui_beval.pro structs.h regexp.h gui.h alloc.h ex_cmds.h spell.h \ proto.h errors.h globals.h + objects/float.o: float.c vim.h protodef.h auto/config.h feature.h \ + os_unix.h auto/osdef.h ascii.h keymap.h term.h macros.h option.h beval.h \ + proto/gui_beval.pro structs.h regexp.h gui.h alloc.h ex_cmds.h spell.h \ + proto.h errors.h globals.h objects/fold.o: fold.c vim.h protodef.h auto/config.h feature.h os_unix.h \ auto/osdef.h ascii.h keymap.h term.h macros.h option.h beval.h \ proto/gui_beval.pro structs.h regexp.h gui.h alloc.h ex_cmds.h spell.h \ *** ../vim-8.2.2927/src/README.md 2020-07-22 19:10:59.877072059 +0200 --- src/README.md 2021-06-02 16:53:34.790373298 +0200 *************** *** 56,61 **** --- 56,62 ---- map.c | mapping and abbreviations mark.c | marks match.c | highlight matching + float.c | floating point functions mbyte.c | multi-byte character handling memfile.c | storing lines for buffers in a swapfile memline.c | storing lines for buffers in memory *** ../vim-8.2.2927/src/eval.c 2021-06-02 14:56:35.819997074 +0200 --- src/eval.c 2021-06-02 16:53:34.794373287 +0200 *************** *** 5155,5197 **** return s; } - #if defined(FEAT_FLOAT) || defined(PROTO) - /* - * Convert the string "text" to a floating point number. - * This uses strtod(). setlocale(LC_NUMERIC, "C") has been used to make sure - * this always uses a decimal point. - * Returns the length of the text that was consumed. - */ - int - string2float( - char_u *text, - float_T *value) // result stored here - { - char *s = (char *)text; - float_T f; - - // MS-Windows does not deal with "inf" and "nan" properly. - if (STRNICMP(text, "inf", 3) == 0) - { - *value = INFINITY; - return 3; - } - if (STRNICMP(text, "-inf", 3) == 0) - { - *value = -INFINITY; - return 4; - } - if (STRNICMP(text, "nan", 3) == 0) - { - *value = NAN; - return 3; - } - f = strtod(s, &s); - *value = f; - return (int)((char_u *)s - text); - } - #endif - /* * Convert the specified byte index of line 'lnum' in buffer 'buf' to a * character index. Works only for loaded buffers. Returns -1 on failure. --- 5155,5160 ---- *** ../vim-8.2.2927/src/evalfunc.c 2021-06-02 14:56:35.823997065 +0200 --- src/evalfunc.c 2021-06-02 16:53:34.794373287 +0200 *************** *** 20,35 **** # include #endif - #ifdef FEAT_FLOAT - static void f_abs(typval_T *argvars, typval_T *rettv); - static void f_acos(typval_T *argvars, typval_T *rettv); - #endif static void f_and(typval_T *argvars, typval_T *rettv); - #ifdef FEAT_FLOAT - static void f_asin(typval_T *argvars, typval_T *rettv); - static void f_atan(typval_T *argvars, typval_T *rettv); - static void f_atan2(typval_T *argvars, typval_T *rettv); - #endif #ifdef FEAT_BEVAL static void f_balloon_gettext(typval_T *argvars, typval_T *rettv); static void f_balloon_show(typval_T *argvars, typval_T *rettv); --- 20,26 ---- *************** *** 42,50 **** static void f_byteidx(typval_T *argvars, typval_T *rettv); static void f_byteidxcomp(typval_T *argvars, typval_T *rettv); static void f_call(typval_T *argvars, typval_T *rettv); - #ifdef FEAT_FLOAT - static void f_ceil(typval_T *argvars, typval_T *rettv); - #endif static void f_changenr(typval_T *argvars, typval_T *rettv); static void f_char2nr(typval_T *argvars, typval_T *rettv); static void f_charcol(typval_T *argvars, typval_T *rettv); --- 33,38 ---- *************** *** 52,61 **** static void f_col(typval_T *argvars, typval_T *rettv); static void f_confirm(typval_T *argvars, typval_T *rettv); static void f_copy(typval_T *argvars, typval_T *rettv); - #ifdef FEAT_FLOAT - static void f_cos(typval_T *argvars, typval_T *rettv); - static void f_cosh(typval_T *argvars, typval_T *rettv); - #endif static void f_cursor(typval_T *argsvars, typval_T *rettv); #ifdef MSWIN static void f_debugbreak(typval_T *argvars, typval_T *rettv); --- 40,45 ---- *************** *** 70,86 **** static void f_eventhandler(typval_T *argvars, typval_T *rettv); static void f_execute(typval_T *argvars, typval_T *rettv); static void f_exists(typval_T *argvars, typval_T *rettv); - #ifdef FEAT_FLOAT - static void f_exp(typval_T *argvars, typval_T *rettv); - #endif static void f_expand(typval_T *argvars, typval_T *rettv); static void f_expandcmd(typval_T *argvars, typval_T *rettv); static void f_feedkeys(typval_T *argvars, typval_T *rettv); - #ifdef FEAT_FLOAT - static void f_float2nr(typval_T *argvars, typval_T *rettv); - static void f_floor(typval_T *argvars, typval_T *rettv); - static void f_fmod(typval_T *argvars, typval_T *rettv); - #endif static void f_fnameescape(typval_T *argvars, typval_T *rettv); static void f_foreground(typval_T *argvars, typval_T *rettv); static void f_funcref(typval_T *argvars, typval_T *rettv); --- 54,62 ---- *************** *** 118,137 **** static void f_interrupt(typval_T *argvars, typval_T *rettv); static void f_invert(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_last_buffer_nr(typval_T *argvars, typval_T *rettv); static void f_len(typval_T *argvars, typval_T *rettv); static void f_libcall(typval_T *argvars, typval_T *rettv); static void f_libcallnr(typval_T *argvars, typval_T *rettv); static void f_line(typval_T *argvars, typval_T *rettv); static void f_line2byte(typval_T *argvars, typval_T *rettv); - #ifdef FEAT_FLOAT - static void f_log(typval_T *argvars, typval_T *rettv); - static void f_log10(typval_T *argvars, typval_T *rettv); - #endif #ifdef FEAT_LUA static void f_luaeval(typval_T *argvars, typval_T *rettv); #endif --- 94,105 ---- *************** *** 153,161 **** #ifdef FEAT_PERL static void f_perleval(typval_T *argvars, typval_T *rettv); #endif - #ifdef FEAT_FLOAT - static void f_pow(typval_T *argvars, typval_T *rettv); - #endif static void f_prevnonblank(typval_T *argvars, typval_T *rettv); static void f_printf(typval_T *argvars, typval_T *rettv); static void f_pum_getpos(typval_T *argvars, typval_T *rettv); --- 121,126 ---- *************** *** 176,184 **** static void f_reg_recording(typval_T *argvars, typval_T *rettv); static void f_rename(typval_T *argvars, typval_T *rettv); static void f_repeat(typval_T *argvars, typval_T *rettv); - #ifdef FEAT_FLOAT - static void f_round(typval_T *argvars, typval_T *rettv); - #endif #ifdef FEAT_RUBY static void f_rubyeval(typval_T *argvars, typval_T *rettv); #endif --- 141,146 ---- *************** *** 206,226 **** #endif static void f_shellescape(typval_T *argvars, typval_T *rettv); static void f_shiftwidth(typval_T *argvars, typval_T *rettv); - #ifdef FEAT_FLOAT - static void f_sin(typval_T *argvars, typval_T *rettv); - static void f_sinh(typval_T *argvars, typval_T *rettv); - #endif static void f_soundfold(typval_T *argvars, typval_T *rettv); static void f_spellbadword(typval_T *argvars, typval_T *rettv); static void f_spellsuggest(typval_T *argvars, typval_T *rettv); static void f_split(typval_T *argvars, typval_T *rettv); - #ifdef FEAT_FLOAT - static void f_sqrt(typval_T *argvars, typval_T *rettv); - #endif static void f_srand(typval_T *argvars, typval_T *rettv); - #ifdef FEAT_FLOAT - static void f_str2float(typval_T *argvars, typval_T *rettv); - #endif static void f_str2list(typval_T *argvars, typval_T *rettv); static void f_str2nr(typval_T *argvars, typval_T *rettv); static void f_strcharlen(typval_T *argvars, typval_T *rettv); --- 168,178 ---- *************** *** 246,262 **** static void f_tabpagebuflist(typval_T *argvars, typval_T *rettv); static void f_taglist(typval_T *argvars, typval_T *rettv); static void f_tagfiles(typval_T *argvars, typval_T *rettv); - #ifdef FEAT_FLOAT - static void f_tan(typval_T *argvars, typval_T *rettv); - static void f_tanh(typval_T *argvars, typval_T *rettv); - #endif static void f_tolower(typval_T *argvars, typval_T *rettv); static void f_toupper(typval_T *argvars, typval_T *rettv); static void f_tr(typval_T *argvars, typval_T *rettv); static void f_trim(typval_T *argvars, typval_T *rettv); - #ifdef FEAT_FLOAT - static void f_trunc(typval_T *argvars, typval_T *rettv); - #endif static void f_type(typval_T *argvars, typval_T *rettv); static void f_virtcol(typval_T *argvars, typval_T *rettv); static void f_visualmode(typval_T *argvars, typval_T *rettv); --- 198,207 ---- *************** *** 2194,2263 **** && *argvars[0].vval.v_string != NUL)); } - #ifdef FEAT_FLOAT - /* - * Get the float value of "argvars[0]" into "f". - * Returns FAIL when the argument is not a Number or Float. - */ - static int - get_float_arg(typval_T *argvars, float_T *f) - { - if (argvars[0].v_type == VAR_FLOAT) - { - *f = argvars[0].vval.v_float; - return OK; - } - if (argvars[0].v_type == VAR_NUMBER) - { - *f = (float_T)argvars[0].vval.v_number; - return OK; - } - emsg(_("E808: Number or Float required")); - return FAIL; - } - - /* - * "abs(expr)" function - */ - static void - f_abs(typval_T *argvars, typval_T *rettv) - { - if (argvars[0].v_type == VAR_FLOAT) - { - rettv->v_type = VAR_FLOAT; - rettv->vval.v_float = fabs(argvars[0].vval.v_float); - } - else - { - varnumber_T n; - int error = FALSE; - - n = tv_get_number_chk(&argvars[0], &error); - if (error) - rettv->vval.v_number = -1; - else if (n > 0) - rettv->vval.v_number = n; - else - rettv->vval.v_number = -n; - } - } - - /* - * "acos()" function - */ - static void - f_acos(typval_T *argvars, typval_T *rettv) - { - float_T f = 0.0; - - rettv->v_type = VAR_FLOAT; - if (get_float_arg(argvars, &f) == OK) - rettv->vval.v_float = acos(f); - else - rettv->vval.v_float = 0.0; - } - #endif - /* * "and(expr, expr)" function */ --- 2139,2144 ---- *************** *** 2268,2321 **** & tv_get_number_chk(&argvars[1], NULL); } - #ifdef FEAT_FLOAT - /* - * "asin()" function - */ - static void - f_asin(typval_T *argvars, typval_T *rettv) - { - float_T f = 0.0; - - rettv->v_type = VAR_FLOAT; - if (get_float_arg(argvars, &f) == OK) - rettv->vval.v_float = asin(f); - else - rettv->vval.v_float = 0.0; - } - - /* - * "atan()" function - */ - static void - f_atan(typval_T *argvars, typval_T *rettv) - { - float_T f = 0.0; - - rettv->v_type = VAR_FLOAT; - if (get_float_arg(argvars, &f) == OK) - rettv->vval.v_float = atan(f); - else - rettv->vval.v_float = 0.0; - } - - /* - * "atan2()" function - */ - static void - f_atan2(typval_T *argvars, typval_T *rettv) - { - float_T fx = 0.0, fy = 0.0; - - rettv->v_type = VAR_FLOAT; - if (get_float_arg(argvars, &fx) == OK - && get_float_arg(&argvars[1], &fy) == OK) - rettv->vval.v_float = atan2(fx, fy); - else - rettv->vval.v_float = 0.0; - } - #endif - /* * "balloon_show()" function */ --- 2149,2154 ---- *************** *** 2518,2540 **** (void)func_call(func, &argvars[1], partial, selfdict, rettv); } - #ifdef FEAT_FLOAT - /* - * "ceil({float})" function - */ - static void - f_ceil(typval_T *argvars, typval_T *rettv) - { - float_T f = 0.0; - - rettv->v_type = VAR_FLOAT; - if (get_float_arg(argvars, &f) == OK) - rettv->vval.v_float = ceil(f); - else - rettv->vval.v_float = 0.0; - } - #endif - /* * "changenr()" function */ --- 2351,2356 ---- *************** *** 2772,2809 **** item_copy(&argvars[0], rettv, FALSE, 0); } - #ifdef FEAT_FLOAT - /* - * "cos()" function - */ - static void - f_cos(typval_T *argvars, typval_T *rettv) - { - float_T f = 0.0; - - rettv->v_type = VAR_FLOAT; - if (get_float_arg(argvars, &f) == OK) - rettv->vval.v_float = cos(f); - else - rettv->vval.v_float = 0.0; - } - - /* - * "cosh()" function - */ - static void - f_cosh(typval_T *argvars, typval_T *rettv) - { - float_T f = 0.0; - - rettv->v_type = VAR_FLOAT; - if (get_float_arg(argvars, &f) == OK) - rettv->vval.v_float = cosh(f); - else - rettv->vval.v_float = 0.0; - } - #endif - /* * Set the cursor position. * If 'charcol' is TRUE, then use the column number as a character offset. --- 2588,2593 ---- *************** *** 3351,3373 **** rettv->vval.v_number = n; } - #ifdef FEAT_FLOAT - /* - * "exp()" function - */ - static void - f_exp(typval_T *argvars, typval_T *rettv) - { - float_T f = 0.0; - - rettv->v_type = VAR_FLOAT; - if (get_float_arg(argvars, &f) == OK) - rettv->vval.v_float = exp(f); - else - rettv->vval.v_float = 0.0; - } - #endif - /* * "expand()" function */ --- 3135,3140 ---- *************** *** 3578,3635 **** } } - #ifdef FEAT_FLOAT - /* - * "float2nr({float})" function - */ - static void - f_float2nr(typval_T *argvars, typval_T *rettv) - { - float_T f = 0.0; - - if (get_float_arg(argvars, &f) == OK) - { - if (f <= (float_T)-VARNUM_MAX + DBL_EPSILON) - rettv->vval.v_number = -VARNUM_MAX; - else if (f >= (float_T)VARNUM_MAX - DBL_EPSILON) - rettv->vval.v_number = VARNUM_MAX; - else - rettv->vval.v_number = (varnumber_T)f; - } - } - - /* - * "floor({float})" function - */ - static void - f_floor(typval_T *argvars, typval_T *rettv) - { - float_T f = 0.0; - - rettv->v_type = VAR_FLOAT; - if (get_float_arg(argvars, &f) == OK) - rettv->vval.v_float = floor(f); - else - rettv->vval.v_float = 0.0; - } - - /* - * "fmod()" function - */ - static void - f_fmod(typval_T *argvars, typval_T *rettv) - { - float_T fx = 0.0, fy = 0.0; - - rettv->v_type = VAR_FLOAT; - if (get_float_arg(argvars, &fx) == OK - && get_float_arg(&argvars[1], &fy) == OK) - rettv->vval.v_float = fmod(fx, fy); - else - rettv->vval.v_float = 0.0; - } - #endif - /* * "fnameescape({string})" function */ --- 3345,3350 ---- *************** *** 6262,6289 **** clear_lval(&lv); } - #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 - */ - static void - f_isnan(typval_T *argvars, typval_T *rettv) - { - rettv->vval.v_number = argvars[0].v_type == VAR_FLOAT - && isnan(argvars[0].vval.v_float); - } - #endif - /* * "last_buffer_nr()" function. */ --- 5977,5982 ---- *************** *** 6456,6493 **** #endif } - #ifdef FEAT_FLOAT - /* - * "log()" function - */ - static void - f_log(typval_T *argvars, typval_T *rettv) - { - float_T f = 0.0; - - rettv->v_type = VAR_FLOAT; - if (get_float_arg(argvars, &f) == OK) - rettv->vval.v_float = log(f); - else - rettv->vval.v_float = 0.0; - } - - /* - * "log10()" function - */ - static void - f_log10(typval_T *argvars, typval_T *rettv) - { - float_T f = 0.0; - - rettv->v_type = VAR_FLOAT; - if (get_float_arg(argvars, &f) == OK) - rettv->vval.v_float = log10(f); - else - rettv->vval.v_float = 0.0; - } - #endif - #ifdef FEAT_LUA /* * "luaeval()" function --- 6149,6154 ---- *************** *** 7008,7031 **** } #endif - #ifdef FEAT_FLOAT - /* - * "pow()" function - */ - static void - f_pow(typval_T *argvars, typval_T *rettv) - { - float_T fx = 0.0, fy = 0.0; - - rettv->v_type = VAR_FLOAT; - if (get_float_arg(argvars, &fx) == OK - && get_float_arg(&argvars[1], &fy) == OK) - rettv->vval.v_float = pow(fx, fy); - else - rettv->vval.v_float = 0.0; - } - #endif - /* * "prevnonblank()" function */ --- 6669,6674 ---- *************** *** 7780,7812 **** return retval; } - #ifdef FEAT_FLOAT - - /* - * round() is not in C90, use ceil() or floor() instead. - */ - float_T - vim_round(float_T f) - { - return f > 0 ? floor(f + 0.5) : ceil(f - 0.5); - } - - /* - * "round({float})" function - */ - static void - f_round(typval_T *argvars, typval_T *rettv) - { - float_T f = 0.0; - - rettv->v_type = VAR_FLOAT; - if (get_float_arg(argvars, &f) == OK) - rettv->vval.v_float = vim_round(f); - else - rettv->vval.v_float = 0.0; - } - #endif - #ifdef FEAT_RUBY /* * "rubyeval()" function --- 7423,7428 ---- *************** *** 8790,8827 **** rettv->vval.v_number = get_sw_value(curbuf); } - #ifdef FEAT_FLOAT - /* - * "sin()" function - */ - static void - f_sin(typval_T *argvars, typval_T *rettv) - { - float_T f = 0.0; - - rettv->v_type = VAR_FLOAT; - if (get_float_arg(argvars, &f) == OK) - rettv->vval.v_float = sin(f); - else - rettv->vval.v_float = 0.0; - } - - /* - * "sinh()" function - */ - static void - f_sinh(typval_T *argvars, typval_T *rettv) - { - float_T f = 0.0; - - rettv->v_type = VAR_FLOAT; - if (get_float_arg(argvars, &f) == OK) - rettv->vval.v_float = sinh(f); - else - rettv->vval.v_float = 0.0; - } - #endif - /* * "soundfold({word})" function */ --- 8406,8411 ---- *************** *** 9072,9113 **** p_cpo = save_cpo; } - #ifdef FEAT_FLOAT - /* - * "sqrt()" function - */ - static void - f_sqrt(typval_T *argvars, typval_T *rettv) - { - float_T f = 0.0; - - rettv->v_type = VAR_FLOAT; - if (get_float_arg(argvars, &f) == OK) - rettv->vval.v_float = sqrt(f); - else - rettv->vval.v_float = 0.0; - } - #endif - - #ifdef FEAT_FLOAT - /* - * "str2float()" function - */ - static void - f_str2float(typval_T *argvars, typval_T *rettv) - { - char_u *p = skipwhite(tv_get_string(&argvars[0])); - int isneg = (*p == '-'); - - if (*p == '+' || *p == '-') - p = skipwhite(p + 1); - (void)string2float(p, &rettv->vval.v_float); - if (isneg) - rettv->vval.v_float *= -1; - rettv->v_type = VAR_FLOAT; - } - #endif - /* * "str2list()" function */ --- 8656,8661 ---- *************** *** 9949,9986 **** (void)get_tags(rettv->vval.v_list, tag_pattern, fname); } - #ifdef FEAT_FLOAT - /* - * "tan()" function - */ - static void - f_tan(typval_T *argvars, typval_T *rettv) - { - float_T f = 0.0; - - rettv->v_type = VAR_FLOAT; - if (get_float_arg(argvars, &f) == OK) - rettv->vval.v_float = tan(f); - else - rettv->vval.v_float = 0.0; - } - - /* - * "tanh()" function - */ - static void - f_tanh(typval_T *argvars, typval_T *rettv) - { - float_T f = 0.0; - - rettv->v_type = VAR_FLOAT; - if (get_float_arg(argvars, &f) == OK) - rettv->vval.v_float = tanh(f); - else - rettv->vval.v_float = 0.0; - } - #endif - /* * "tolower(string)" function */ --- 9497,9502 ---- *************** *** 10205,10228 **** rettv->vval.v_string = vim_strnsave(head, tail - head); } - #ifdef FEAT_FLOAT - /* - * "trunc({float})" function - */ - static void - f_trunc(typval_T *argvars, typval_T *rettv) - { - float_T f = 0.0; - - rettv->v_type = VAR_FLOAT; - if (get_float_arg(argvars, &f) == OK) - // trunc() is not in C90, use floor() or ceil() instead. - rettv->vval.v_float = f > 0 ? floor(f) : ceil(f); - else - rettv->vval.v_float = 0.0; - } - #endif - /* * "type(expr)" function */ --- 9721,9726 ---- *** ../vim-8.2.2927/src/float.c 2021-06-02 17:06:48.632431131 +0200 --- src/float.c 2021-06-02 17:01:02.225271317 +0200 *************** *** 0 **** --- 1,477 ---- + /* vi:set ts=8 sts=4 sw=4 noet: + * + * VIM - Vi IMproved by Bram Moolenaar + * + * Do ":help uganda" in Vim to read copying and usage conditions. + * Do ":help credits" in Vim to see a list of people who contributed. + * See README.txt for an overview of the Vim source code. + */ + + /* + * float.c: Floating point functions + */ + #define USING_FLOAT_STUFF + + #include "vim.h" + + #if (defined(FEAT_EVAL) && defined(FEAT_FLOAT)) || defined(PROTO) + + #ifdef VMS + # include + #endif + + /* + * Convert the string "text" to a floating point number. + * This uses strtod(). setlocale(LC_NUMERIC, "C") has been used to make sure + * this always uses a decimal point. + * Returns the length of the text that was consumed. + */ + int + string2float( + char_u *text, + float_T *value) // result stored here + { + char *s = (char *)text; + float_T f; + + // MS-Windows does not deal with "inf" and "nan" properly. + if (STRNICMP(text, "inf", 3) == 0) + { + *value = INFINITY; + return 3; + } + if (STRNICMP(text, "-inf", 3) == 0) + { + *value = -INFINITY; + return 4; + } + if (STRNICMP(text, "nan", 3) == 0) + { + *value = NAN; + return 3; + } + f = strtod(s, &s); + *value = f; + return (int)((char_u *)s - text); + } + + /* + * Get the float value of "argvars[0]" into "f". + * Returns FAIL when the argument is not a Number or Float. + */ + static int + get_float_arg(typval_T *argvars, float_T *f) + { + if (argvars[0].v_type == VAR_FLOAT) + { + *f = argvars[0].vval.v_float; + return OK; + } + if (argvars[0].v_type == VAR_NUMBER) + { + *f = (float_T)argvars[0].vval.v_number; + return OK; + } + emsg(_("E808: Number or Float required")); + return FAIL; + } + + /* + * "abs(expr)" function + */ + void + f_abs(typval_T *argvars, typval_T *rettv) + { + if (argvars[0].v_type == VAR_FLOAT) + { + rettv->v_type = VAR_FLOAT; + rettv->vval.v_float = fabs(argvars[0].vval.v_float); + } + else + { + varnumber_T n; + int error = FALSE; + + n = tv_get_number_chk(&argvars[0], &error); + if (error) + rettv->vval.v_number = -1; + else if (n > 0) + rettv->vval.v_number = n; + else + rettv->vval.v_number = -n; + } + } + + /* + * "acos()" function + */ + void + f_acos(typval_T *argvars, typval_T *rettv) + { + float_T f = 0.0; + + rettv->v_type = VAR_FLOAT; + if (get_float_arg(argvars, &f) == OK) + rettv->vval.v_float = acos(f); + else + rettv->vval.v_float = 0.0; + } + + /* + * "asin()" function + */ + void + f_asin(typval_T *argvars, typval_T *rettv) + { + float_T f = 0.0; + + rettv->v_type = VAR_FLOAT; + if (get_float_arg(argvars, &f) == OK) + rettv->vval.v_float = asin(f); + else + rettv->vval.v_float = 0.0; + } + + /* + * "atan()" function + */ + void + f_atan(typval_T *argvars, typval_T *rettv) + { + float_T f = 0.0; + + rettv->v_type = VAR_FLOAT; + if (get_float_arg(argvars, &f) == OK) + rettv->vval.v_float = atan(f); + else + rettv->vval.v_float = 0.0; + } + + /* + * "atan2()" function + */ + void + f_atan2(typval_T *argvars, typval_T *rettv) + { + float_T fx = 0.0, fy = 0.0; + + rettv->v_type = VAR_FLOAT; + if (get_float_arg(argvars, &fx) == OK + && get_float_arg(&argvars[1], &fy) == OK) + rettv->vval.v_float = atan2(fx, fy); + else + rettv->vval.v_float = 0.0; + } + + /* + * "ceil({float})" function + */ + void + f_ceil(typval_T *argvars, typval_T *rettv) + { + float_T f = 0.0; + + rettv->v_type = VAR_FLOAT; + if (get_float_arg(argvars, &f) == OK) + rettv->vval.v_float = ceil(f); + else + rettv->vval.v_float = 0.0; + } + + /* + * "cos()" function + */ + void + f_cos(typval_T *argvars, typval_T *rettv) + { + float_T f = 0.0; + + rettv->v_type = VAR_FLOAT; + if (get_float_arg(argvars, &f) == OK) + rettv->vval.v_float = cos(f); + else + rettv->vval.v_float = 0.0; + } + + /* + * "cosh()" function + */ + void + f_cosh(typval_T *argvars, typval_T *rettv) + { + float_T f = 0.0; + + rettv->v_type = VAR_FLOAT; + if (get_float_arg(argvars, &f) == OK) + rettv->vval.v_float = cosh(f); + else + rettv->vval.v_float = 0.0; + } + + /* + * "exp()" function + */ + void + f_exp(typval_T *argvars, typval_T *rettv) + { + float_T f = 0.0; + + rettv->v_type = VAR_FLOAT; + if (get_float_arg(argvars, &f) == OK) + rettv->vval.v_float = exp(f); + else + rettv->vval.v_float = 0.0; + } + + /* + * "float2nr({float})" function + */ + void + f_float2nr(typval_T *argvars, typval_T *rettv) + { + float_T f = 0.0; + + if (get_float_arg(argvars, &f) == OK) + { + if (f <= (float_T)-VARNUM_MAX + DBL_EPSILON) + rettv->vval.v_number = -VARNUM_MAX; + else if (f >= (float_T)VARNUM_MAX - DBL_EPSILON) + rettv->vval.v_number = VARNUM_MAX; + else + rettv->vval.v_number = (varnumber_T)f; + } + } + + /* + * "floor({float})" function + */ + void + f_floor(typval_T *argvars, typval_T *rettv) + { + float_T f = 0.0; + + rettv->v_type = VAR_FLOAT; + if (get_float_arg(argvars, &f) == OK) + rettv->vval.v_float = floor(f); + else + rettv->vval.v_float = 0.0; + } + + /* + * "fmod()" function + */ + void + f_fmod(typval_T *argvars, typval_T *rettv) + { + float_T fx = 0.0, fy = 0.0; + + rettv->v_type = VAR_FLOAT; + if (get_float_arg(argvars, &fx) == OK + && get_float_arg(&argvars[1], &fy) == OK) + rettv->vval.v_float = fmod(fx, fy); + else + rettv->vval.v_float = 0.0; + } + + # if defined(HAVE_MATH_H) || defined(PROTO) + /* + * "isinf()" function + */ + 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 + */ + void + f_isnan(typval_T *argvars, typval_T *rettv) + { + rettv->vval.v_number = argvars[0].v_type == VAR_FLOAT + && isnan(argvars[0].vval.v_float); + } + # endif + + /* + * "log()" function + */ + void + f_log(typval_T *argvars, typval_T *rettv) + { + float_T f = 0.0; + + rettv->v_type = VAR_FLOAT; + if (get_float_arg(argvars, &f) == OK) + rettv->vval.v_float = log(f); + else + rettv->vval.v_float = 0.0; + } + + /* + * "log10()" function + */ + void + f_log10(typval_T *argvars, typval_T *rettv) + { + float_T f = 0.0; + + rettv->v_type = VAR_FLOAT; + if (get_float_arg(argvars, &f) == OK) + rettv->vval.v_float = log10(f); + else + rettv->vval.v_float = 0.0; + } + + /* + * "pow()" function + */ + void + f_pow(typval_T *argvars, typval_T *rettv) + { + float_T fx = 0.0, fy = 0.0; + + rettv->v_type = VAR_FLOAT; + if (get_float_arg(argvars, &fx) == OK + && get_float_arg(&argvars[1], &fy) == OK) + rettv->vval.v_float = pow(fx, fy); + else + rettv->vval.v_float = 0.0; + } + + + /* + * round() is not in C90, use ceil() or floor() instead. + */ + float_T + vim_round(float_T f) + { + return f > 0 ? floor(f + 0.5) : ceil(f - 0.5); + } + + /* + * "round({float})" function + */ + void + f_round(typval_T *argvars, typval_T *rettv) + { + float_T f = 0.0; + + rettv->v_type = VAR_FLOAT; + if (get_float_arg(argvars, &f) == OK) + rettv->vval.v_float = vim_round(f); + else + rettv->vval.v_float = 0.0; + } + + /* + * "sin()" function + */ + void + f_sin(typval_T *argvars, typval_T *rettv) + { + float_T f = 0.0; + + rettv->v_type = VAR_FLOAT; + if (get_float_arg(argvars, &f) == OK) + rettv->vval.v_float = sin(f); + else + rettv->vval.v_float = 0.0; + } + + /* + * "sinh()" function + */ + void + f_sinh(typval_T *argvars, typval_T *rettv) + { + float_T f = 0.0; + + rettv->v_type = VAR_FLOAT; + if (get_float_arg(argvars, &f) == OK) + rettv->vval.v_float = sinh(f); + else + rettv->vval.v_float = 0.0; + } + + /* + * "sqrt()" function + */ + void + f_sqrt(typval_T *argvars, typval_T *rettv) + { + float_T f = 0.0; + + rettv->v_type = VAR_FLOAT; + if (get_float_arg(argvars, &f) == OK) + rettv->vval.v_float = sqrt(f); + else + rettv->vval.v_float = 0.0; + } + + /* + * "str2float()" function + */ + void + f_str2float(typval_T *argvars, typval_T *rettv) + { + char_u *p = skipwhite(tv_get_string(&argvars[0])); + int isneg = (*p == '-'); + + if (*p == '+' || *p == '-') + p = skipwhite(p + 1); + (void)string2float(p, &rettv->vval.v_float); + if (isneg) + rettv->vval.v_float *= -1; + rettv->v_type = VAR_FLOAT; + } + + /* + * "tan()" function + */ + void + f_tan(typval_T *argvars, typval_T *rettv) + { + float_T f = 0.0; + + rettv->v_type = VAR_FLOAT; + if (get_float_arg(argvars, &f) == OK) + rettv->vval.v_float = tan(f); + else + rettv->vval.v_float = 0.0; + } + + /* + * "tanh()" function + */ + void + f_tanh(typval_T *argvars, typval_T *rettv) + { + float_T f = 0.0; + + rettv->v_type = VAR_FLOAT; + if (get_float_arg(argvars, &f) == OK) + rettv->vval.v_float = tanh(f); + else + rettv->vval.v_float = 0.0; + } + + /* + * "trunc({float})" function + */ + void + f_trunc(typval_T *argvars, typval_T *rettv) + { + float_T f = 0.0; + + rettv->v_type = VAR_FLOAT; + if (get_float_arg(argvars, &f) == OK) + // trunc() is not in C90, use floor() or ceil() instead. + rettv->vval.v_float = f > 0 ? floor(f) : ceil(f); + else + rettv->vval.v_float = 0.0; + } + + #endif *** ../vim-8.2.2927/src/proto.h 2020-12-28 18:25:56.800886000 +0100 --- src/proto.h 2021-06-02 16:53:34.794373287 +0200 *************** *** 90,95 **** --- 90,96 ---- # include "fileio.pro" # include "filepath.pro" # include "findfile.pro" + # include "float.pro" # include "fold.pro" # include "getchar.pro" # include "gui_xim.pro" *** ../vim-8.2.2927/src/proto/eval.pro 2021-02-11 21:19:30.522147936 +0100 --- src/proto/eval.pro 2021-06-02 16:53:34.794373287 +0200 *************** *** 56,62 **** char_u *echo_string_core(typval_T *tv, char_u **tofree, char_u *numbuf, int copyID, int echo_style, int restore_copyID, int composite_val); char_u *echo_string(typval_T *tv, char_u **tofree, char_u *numbuf, int copyID); char_u *string_quote(char_u *str, int function); - int string2float(char_u *text, float_T *value); int buf_byteidx_to_charidx(buf_T *buf, int lnum, int byteidx); int buf_charidx_to_byteidx(buf_T *buf, int lnum, int charidx); pos_T *var2fpos(typval_T *varp, int dollar_lnum, int *fnum, int charcol); --- 56,61 ---- *** ../vim-8.2.2927/src/proto/float.pro 2021-06-02 17:06:48.644431104 +0200 --- src/proto/float.pro 2021-06-02 16:53:34.794373287 +0200 *************** *** 0 **** --- 1,28 ---- + /* math.c */ + int string2float(char_u *text, float_T *value); + void f_abs(typval_T *argvars, typval_T *rettv); + void f_acos(typval_T *argvars, typval_T *rettv); + void f_asin(typval_T *argvars, typval_T *rettv); + void f_atan(typval_T *argvars, typval_T *rettv); + void f_atan2(typval_T *argvars, typval_T *rettv); + void f_ceil(typval_T *argvars, typval_T *rettv); + void f_cos(typval_T *argvars, typval_T *rettv); + void f_cosh(typval_T *argvars, typval_T *rettv); + void f_exp(typval_T *argvars, typval_T *rettv); + void f_float2nr(typval_T *argvars, typval_T *rettv); + void f_floor(typval_T *argvars, typval_T *rettv); + void f_fmod(typval_T *argvars, typval_T *rettv); + void f_isinf(typval_T *argvars, typval_T *rettv); + void f_isnan(typval_T *argvars, typval_T *rettv); + void f_log(typval_T *argvars, typval_T *rettv); + void f_log10(typval_T *argvars, typval_T *rettv); + void f_pow(typval_T *argvars, typval_T *rettv); + void f_round(typval_T *argvars, typval_T *rettv); + void f_sin(typval_T *argvars, typval_T *rettv); + void f_sinh(typval_T *argvars, typval_T *rettv); + void f_sqrt(typval_T *argvars, typval_T *rettv); + void f_str2float(typval_T *argvars, typval_T *rettv); + void f_tan(typval_T *argvars, typval_T *rettv); + void f_tanh(typval_T *argvars, typval_T *rettv); + void f_trunc(typval_T *argvars, typval_T *rettv); + /* vim: set ft=c : */ *** ../vim-8.2.2927/src/version.c 2021-06-02 16:49:27.758997408 +0200 --- src/version.c 2021-06-02 16:53:21.738405905 +0200 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 2928, /**/ -- Any sufficiently advanced technology is indistinguishable from magic. Arthur C. Clarke Any sufficiently advanced bug is indistinguishable from a feature. Rich Kulawiec /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///