summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYegappan Lakshmanan <yegappan@yahoo.com>2021-06-02 17:07:18 +0200
committerBram Moolenaar <Bram@vim.org>2021-06-02 17:07:18 +0200
commit01c798c31a94a50ad0c4a022fc21c1a31553be21 (patch)
treecc720adf347b3afa81846b110dd8f595eed5177c
parenta83d06026d0e0dad873de296bff97707ad2faff3 (diff)
patch 8.2.2928: the evalfunc.c file is too bigv8.2.2928
Problem: The evalfunc.c file is too big. Solution: Move float related functionality to a separate file. (Yegappan Lakshmanan, closes #8287)
-rw-r--r--Filelist2
-rw-r--r--src/Make_ami.mak1
-rw-r--r--src/Make_cyg_ming.mak1
-rw-r--r--src/Make_mvc.mak4
-rw-r--r--src/Make_vms.mms5
-rw-r--r--src/Makefile29
-rw-r--r--src/README.md1
-rw-r--r--src/eval.c37
-rw-r--r--src/evalfunc.c502
-rw-r--r--src/float.c477
-rw-r--r--src/proto.h1
-rw-r--r--src/proto/eval.pro1
-rw-r--r--src/proto/float.pro28
-rw-r--r--src/version.c2
14 files changed, 544 insertions, 547 deletions
diff --git a/Filelist b/Filelist
index 66fe467a9c..579344bddc 100644
--- a/Filelist
+++ b/Filelist
@@ -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 \
diff --git a/src/Make_ami.mak b/src/Make_ami.mak
index 88b3986508..91246d9bce 100644
--- a/src/Make_ami.mak
+++ b/src/Make_ami.mak
@@ -117,6 +117,7 @@ SRC += \
fileio.c \
filepath.c \
findfile.c \
+ float.c \
fold.c \
getchar.c \
hardcopy.c \
diff --git a/src/Make_cyg_ming.mak b/src/Make_cyg_ming.mak
index 0be3abbaa1..c33200b33e 100644
--- a/src/Make_cyg_ming.mak
+++ b/src/Make_cyg_ming.mak
@@ -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 \
diff --git a/src/Make_mvc.mak b/src/Make_mvc.mak
index 30f8175e25..42b6f8ddf6 100644
--- a/src/Make_mvc.mak
+++ b/src/Make_mvc.mak
@@ -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 \
diff --git a/src/Make_vms.mms b/src/Make_vms.mms
index 3631236360..4928b0be86 100644
--- a/src/Make_vms.mms
+++ b/src/Make_vms.mms
@@ -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
diff --git a/src/Makefile b/src/Makefile
index 4e32814ffd..202daec91a 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -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 \
diff --git a/src/README.md b/src/README.md
index b4d9bdd89a..81ca37d0d6 100644
--- a/src/README.md
+++ b/src/README.md
@@ -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
diff --git a/src/eval.c b/src/eval.c
index e39c604ad2..77578f3650 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -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.
diff --git a/src/evalfunc.c b/src/evalfunc.c
index 8ea48f9bd5..1962ccd15a 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -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
*/
diff --git a/src/float.c b/src/float.c
new file mode 100644
index 0000000000..1361a36d50
--- /dev/null
+++ b/src/float.c
@@ -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);