patch 8.2.2928: the evalfunc.c file is too big

Problem:    The evalfunc.c file is too big.
Solution:   Move float related functionality to a separate file. (Yegappan
            Lakshmanan, closes #8287)
This commit is contained in:
Yegappan Lakshmanan
2021-06-02 17:07:18 +02:00
committed by Bram Moolenaar
parent a83d06026d
commit 01c798c31a
14 changed files with 544 additions and 547 deletions

View File

@ -68,6 +68,7 @@ SRC_ALL = \
src/fileio.c \
src/filepath.c \
src/findfile.c \
src/float.c \
src/fold.c \
src/getchar.c \
src/globals.h \
@ -246,6 +247,7 @@ SRC_ALL = \
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 \

View File

@ -117,6 +117,7 @@ SRC += \
fileio.c \
filepath.c \
findfile.c \
float.c \
fold.c \
getchar.c \
hardcopy.c \

View File

@ -749,6 +749,7 @@ OBJ = \
$(OUTDIR)/fileio.o \
$(OUTDIR)/filepath.o \
$(OUTDIR)/findfile.o \
$(OUTDIR)/float.o \
$(OUTDIR)/fold.o \
$(OUTDIR)/getchar.o \
$(OUTDIR)/gui_xim.o \

View File

@ -743,6 +743,7 @@ OBJ = \
$(OUTDIR)\fileio.obj \
$(OUTDIR)\filepath.obj \
$(OUTDIR)\findfile.obj \
$(OUTDIR)\float.obj \
$(OUTDIR)\fold.obj \
$(OUTDIR)\getchar.obj \
$(OUTDIR)\gui_xim.obj \
@ -1599,6 +1600,8 @@ $(OUTDIR)/filepath.obj: $(OUTDIR) filepath.c $(INCL)
$(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,6 +1938,7 @@ proto.h: \
proto/fileio.pro \
proto/filepath.pro \
proto/findfile.pro \
proto/float.pro \
proto/getchar.pro \
proto/gui_xim.pro \
proto/hardcopy.pro \

View File

@ -343,6 +343,7 @@ SRC = \
fileio.c \
filepath.c, \
findfile.c \
float.c \
fold.c \
getchar.c \
gui_xim.c \
@ -460,6 +461,7 @@ OBJ = \
fileio.obj \
filepath.obj \
findfile.obj \
float.obj \
fold.obj \
getchar.obj \
gui_xim.obj \
@ -860,6 +862,9 @@ findfile.obj : findfile.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
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

View File

@ -386,7 +386,8 @@ CClink = $(CC)
# 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
# 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,6 +437,8 @@ CClink = $(CC)
# 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,7 +466,7 @@ CClink = $(CC)
# 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
#CONF_OPT_TCL = --enable-tclinterp=dynamic
#CONF_OPT_TCL = --enable-tclinterp --with-tclsh=tclsh8.4
@ -690,16 +693,18 @@ LINT_OPTIONS = -beprxzF
# 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.
# 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=address -fno-omit-frame-pointer
#SANITIZER_CFLAGS = -g -O0 -fsanitize=undefined -fno-omit-frame-pointer
#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,7 +984,7 @@ SANITIZER_LIBS = $(SANITIZER_CFLAGS)
# 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/\\";$$/";/'
# QUOTESED = sed -e 's/[\\"]/\\&/g' -e 's/\\"/"/' -e 's/\\";$$/";/' -e 's/ */ /g'
##################### end of system specific lines ################### }}}
@ -1621,6 +1626,7 @@ BASIC_SRC = \
fileio.c \
filepath.c \
findfile.c \
float.c \
fold.c \
getchar.c \
gui_xim.c \
@ -1775,6 +1781,7 @@ OBJ_COMMON = \
objects/fileio.o \
objects/filepath.o \
objects/findfile.o \
objects/float.o \
objects/fold.o \
objects/getchar.o \
objects/gui_xim.o \
@ -1945,6 +1952,7 @@ PRO_AUTO = \
fileio.pro \
filepath.pro \
findfile.pro \
float.pro \
fold.pro \
getchar.pro \
gui_xim.pro \
@ -3247,6 +3255,9 @@ objects/filepath.o: filepath.c
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,6 +3849,10 @@ objects/findfile.o: findfile.c vim.h protodef.h auto/config.h feature.h os_unix.
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 \

View File

@ -56,6 +56,7 @@ locale.c | locale/language handling
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

View File

@ -5155,43 +5155,6 @@ string_quote(char_u *str, int function)
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.

View File

@ -20,16 +20,7 @@
# include <float.h>
#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);
@ -42,9 +33,6 @@ static void byteidx(typval_T *argvars, typval_T *rettv, int comp);
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);
@ -52,10 +40,6 @@ static void f_charidx(typval_T *argvars, typval_T *rettv);
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);
@ -70,17 +54,9 @@ static void f_eval(typval_T *argvars, typval_T *rettv);
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);
@ -118,20 +94,12 @@ static void f_inputsecret(typval_T *argvars, typval_T *rettv);
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
@ -153,9 +121,6 @@ static void f_or(typval_T *argvars, typval_T *rettv);
#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);
@ -176,9 +141,6 @@ static void f_reg_executing(typval_T *argvars, typval_T *rettv);
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
@ -206,21 +168,11 @@ static void f_sha256(typval_T *argvars, typval_T *rettv);
#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);
@ -246,17 +198,10 @@ static void f_synconcealed(typval_T *argvars, typval_T *rettv);
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);
@ -2194,70 +2139,6 @@ non_zero_arg(typval_T *argvars)
&& *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
*/
@ -2268,54 +2149,6 @@ f_and(typval_T *argvars, typval_T *rettv)
& 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
*/
@ -2518,23 +2351,6 @@ f_call(typval_T *argvars, typval_T *rettv)
(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
*/
@ -2772,38 +2588,6 @@ f_copy(typval_T *argvars, typval_T *rettv)
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.
@ -3351,23 +3135,6 @@ f_exists(typval_T *argvars, typval_T *rettv)
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
*/
@ -3578,58 +3345,6 @@ f_feedkeys(typval_T *argvars, typval_T *rettv UNUSED)
}
}
#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
*/
@ -6262,28 +5977,6 @@ f_islocked(typval_T *argvars, typval_T *rettv)
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.
*/
@ -6456,38 +6149,6 @@ f_line2byte(typval_T *argvars UNUSED, typval_T *rettv)
#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
@ -7008,24 +6669,6 @@ f_perleval(typval_T *argvars, typval_T *rettv)
}
#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
*/
@ -7780,33 +7423,6 @@ theend:
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
@ -8790,38 +8406,6 @@ f_shiftwidth(typval_T *argvars UNUSED, typval_T *rettv)
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
*/
@ -9072,42 +8656,6 @@ theend:
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
*/
@ -9949,38 +9497,6 @@ f_taglist(typval_T *argvars, typval_T *rettv)
(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
*/
@ -10205,24 +9721,6 @@ f_trim(typval_T *argvars, typval_T *rettv)
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
*/

477
src/float.c Normal file
View File

@ -0,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 <float.h>
#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

View File

@ -90,6 +90,7 @@ extern int _stricoll(char *a, char *b);
# include "fileio.pro"
# include "filepath.pro"
# include "findfile.pro"
# include "float.pro"
# include "fold.pro"
# include "getchar.pro"
# include "gui_xim.pro"

View File

@ -56,7 +56,6 @@ int set_ref_in_item(typval_T *tv, int copyID, ht_stack_T **ht_stack, list_stack_
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);

28
src/proto/float.pro Normal file
View File

@ -0,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 : */

View File

@ -750,6 +750,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
2928,
/**/
2927,
/**/